Skip to content

Commit cf8c6bd

Browse files
committed
adding scaffolding
1 parent 4e8b342 commit cf8c6bd

File tree

5 files changed

+254
-3
lines changed

5 files changed

+254
-3
lines changed

.github/workflows/internal-validate-workflow-files.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,15 @@ jobs:
4747
exit 1
4848
fi
4949
50+
- name: Generate Workflow Files (Bundle Feature)
51+
shell: bash
52+
run: |
53+
if ! qlt bundle init --use-runner ubuntu-latest --language cpp --automation-type actions --development --overwrite-existing ; then
54+
echo "Failed to generate bundle workflow files."
55+
exit 1
56+
fi
57+
58+
5059
- name: Check Git Clean Status
5160
shell: bash
5261
run: |

src/CodeQLToolkit.Features/Bundle/Lifecycle/BundleLifecycleFeature.cs

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using System.CommandLine;
77
using System.Reflection;
88
using CodeQLToolkit.Features.Bundle.Lifecycle.Targets;
9+
using CodeQLToolkit.Features.Test.Lifecycle;
910

1011
namespace CodeQLToolkit.Features.Bundle.Lifecycle
1112
{
@@ -32,7 +33,18 @@ public override LanguageType[] SupportedLangauges
3233

3334
public void Register(Command parentCommand)
3435
{
35-
//Log<BundleLifecycleFeature>.G().LogInformation("Registering lifecycle submodule.");
36+
Log<BundleLifecycleFeature>.G().LogInformation("Registering lifecycle submodule.");
37+
38+
var initCommand = new Command("init", "Initialize bundle creation and integration testing features.");
39+
var overwriteExistingOption = new Option<bool>("--overwrite-existing", () => false, "Overwrite exiting files (if they exist).");
40+
var useRunnerOption = new Option<string>("--use-runner", () => "ubuntu-latest", "The runner(s) to use. Should be a comma-seperated list of actions runners.");
41+
var languageOption = new Option<string>("--language", $"The language to generate automation for.") { IsRequired = true }.FromAmong(SupportedLangauges.Select(x => x.ToOptionString()).ToArray());
42+
43+
initCommand.AddOption(overwriteExistingOption);
44+
initCommand.AddOption(useRunnerOption);
45+
initCommand.AddOption(languageOption);
46+
47+
parentCommand.Add(initCommand);
3648

3749
var setCommand = new Command("set", "Functions pertaining to setting variables related to custom CodeQL bundles.");
3850
//parentCommand.Add(setCommand);
@@ -90,6 +102,27 @@ public void Register(Command parentCommand)
90102
}
91103

92104

105+
initCommand.SetHandler((devMode, basePath, automationType, overwriteExisting, useRunner, language) =>
106+
{
107+
Log<BundleLifecycleFeature>.G().LogInformation("Executing init command...");
108+
109+
//
110+
// dispatch at runtime to the correct automation type
111+
//
112+
var featureTarget = AutomationFeatureFinder.FindTargetForAutomationType<BaseLifecycleTarget>(AutomationTypeHelper.AutomationTypeFromString(automationType));
113+
114+
// setup common params
115+
featureTarget.FeatureName = FeatureName;
116+
featureTarget.Base = basePath;
117+
featureTarget.OverwriteExisting = overwriteExisting;
118+
featureTarget.UseRunner = useRunner;
119+
featureTarget.Language = language;
120+
featureTarget.DevMode = devMode;
121+
featureTarget.Run();
122+
123+
}, Globals.Development, Globals.BasePathOption, Globals.AutomationTypeOption, overwriteExistingOption, useRunnerOption, languageOption);
124+
125+
93126
}
94127

95128
public int Run()
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
7+
namespace CodeQLToolkit.Features.Bundle.Lifecycle.Targets.Actions
8+
{
9+
public class InitLifecycleTarget : BaseLifecycleTarget
10+
{
11+
12+
public InitLifecycleTarget()
13+
{
14+
AutomationType = AutomationType.ACTIONS;
15+
}
16+
17+
public override void Run()
18+
{
19+
Log<InitLifecycleTarget>.G().LogInformation("Running init command...");
20+
21+
// temporarily disable the language resolution
22+
var tmpLanguage = Language;
23+
Language = null;
24+
25+
WriteTemplateIfOverwriteOrNotExists("install-qlt", Path.Combine(Base, ".github", "actions", "install-qlt", "action.yml"), "install-qlt action");
26+
WriteTemplateIfOverwriteOrNotExists("run-bundle-integration-tests", Path.Combine(Base, ".github", "workflows", $"run-bundle-integration-tests-{tmpLanguage}.yml"), $"Run CodeQL Unit Tests ({Language})", new
27+
{
28+
useRunner = UseRunner,
29+
language = tmpLanguage,
30+
devMode = DevMode,
31+
});
32+
33+
Language = tmpLanguage;
34+
35+
var message = @"------------------------------------------
36+
Your repository now has the Bundle Creation and Integration Test Runner installed in `.github/workflows/`. Additionally,
37+
QLT has installed necessary actions for keeping your version of QLT and CodeQL current in `.github/actions/install-qlt`.
38+
39+
Note that for integration testing to work, you MUST create a directory `integration-test` in the root of your repository. Please
40+
consult the QLT documentation for details on how to structure this directory.
41+
42+
In addition to using QLT to generate your files you can also directly edit this file to fine tune its settings.
43+
44+
(Hint: If you'd like to regenerate your files, you can use the `--overwrite-existing` option to overwrite the files that are in place now.)";
45+
46+
Log<InitLifecycleTarget>.G().LogInformation(message);
47+
}
48+
}
49+
}
Lines changed: 161 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,161 @@
1+
name: ⚙️ Integration Test Bundle ({{language}})
2+
3+
on:
4+
push:
5+
branches:
6+
- '**'
7+
pull_request:
8+
branches:
9+
- '**'
10+
workflow_dispatch:
11+
12+
jobs:
13+
integration-test:
14+
name: Run Bundle Integration Test
15+
runs-on: ubuntu-latest
16+
permissions:
17+
actions: read
18+
contents: read
19+
security-events: write
20+
strategy:
21+
fail-fast: false
22+
matrix:
23+
language: [ 'cpp' ]
24+
25+
steps:
26+
- name: Checkout repository
27+
uses: actions/checkout@v4
28+
29+
{% if dev_mode %}
30+
- name: Install QLT
31+
id: install-qlt
32+
uses: ./.github/actions/install-qlt-local
33+
with:
34+
qlt-version: 'latest'
35+
add-to-path: true
36+
{% else %}
37+
- name: Install QLT
38+
id: install-qlt
39+
uses: ./.github/actions/install-qlt
40+
with:
41+
qlt-version: 'latest'
42+
add-to-path: true
43+
{% endif %}
44+
{% raw %}
45+
- name: Validate QLT Installation
46+
shell: bash
47+
run: |
48+
echo -e "Checking QLT Version:"
49+
echo "QLT Home: ${{ steps.install-qlt.outputs.qlt-home }}"
50+
qlt version
51+
{% endraw %}
52+
{% if dev_mode %}
53+
- name: Create Bundle (compiled)
54+
shell: bash
55+
run: |
56+
if ! qlt codeql run install --custom-bundle --base example/ ; then
57+
echo "Failed to generate bundle."
58+
exit 1
59+
fi
60+
61+
# ensure bundle runs
62+
63+
if ! qlt query run install-packs --use-bundle --base example/ ; then
64+
echo "Failed to install query packs with tool."
65+
exit 1
66+
fi
67+
{% else %}
68+
- name: Create Bundle (compiled)
69+
shell: bash
70+
run: |
71+
if ! qlt codeql run install --custom-bundle ; then
72+
echo "Failed to generate bundle."
73+
exit 1
74+
fi
75+
76+
# ensure bundle runs
77+
78+
if ! qlt query run install-packs --use-bundle ; then
79+
echo "Failed to install query packs with tool."
80+
exit 1
81+
fi
82+
{% endif %}
83+
{% raw %}
84+
- name: Validate Bundle Existence
85+
shell: bash
86+
run: |
87+
echo "Checking Bundle Existence"
88+
ls -l ${{ env.QLT_CODEQL_HOME }}/../out/
89+
90+
- name: Upload Bundle Used
91+
uses: actions/upload-artifact@v2
92+
with:
93+
name: codeql-bundle.tar.gz
94+
path: |
95+
${{ env.QLT_CODEQL_BUNDLE_PATH }}
96+
if-no-files-found: error
97+
98+
- name: Initialize CodeQL
99+
uses: github/codeql-action/init@v2
100+
with:
101+
languages: ${{ matrix.language }}
102+
tools: ${{ env.QLT_CODEQL_BUNDLE_PATH }}
103+
{% endraw %}
104+
{% if dev_mode %}
105+
{% raw %}
106+
- name: Autobuild
107+
uses: github/codeql-action/autobuild@v2
108+
with:
109+
working-directory: example/integration-tests/${{ matrix.language }}/src/ # Path containing the example application
110+
{% endraw %}
111+
{% else %}
112+
{% raw %}
113+
- name: Autobuild
114+
uses: github/codeql-action/autobuild@v2
115+
with:
116+
working-directory: integration-tests/${{ matrix.language }}/src/ # Path containing the example application
117+
{% endraw %}
118+
{% endif %}
119+
{% raw %}
120+
- name: Perform CodeQL Analysis
121+
id: analysis
122+
uses: github/codeql-action/analyze@v2
123+
124+
- name: Validate SARIF Location
125+
shell: bash
126+
run: |
127+
# validate we have the actual sarif results
128+
echo "Checking SARIF file location at: ${{ steps.analysis.outputs.sarif-output }}"
129+
ls -l ${{ steps.analysis.outputs.sarif-output }}
130+
131+
- name: Upload SARIF Results
132+
uses: actions/upload-artifact@v2
133+
with:
134+
name: actual.sarif
135+
path: |
136+
${{ steps.analysis.outputs.sarif-output }}/*.sarif
137+
if-no-files-found: error
138+
139+
- name: Validate SARIF Existence
140+
shell: bash
141+
run: |
142+
ls -l ${{ steps.analysis.outputs.sarif-output }}/*.sarif
143+
{% endraw %}
144+
145+
{% if dev_mode %}
146+
{% raw %}
147+
- name: Validate SARIF Results
148+
shell: bash
149+
run: |
150+
# Compare the expected vs the actual
151+
qlt bundle run validate-integration-tests --expected example/integration-tests/${{ matrix.language }}/expected.sarif --actual ${{ steps.analysis.outputs.sarif-output }}/${{ matrix.language }}.sarif
152+
{% endraw %}
153+
{% else %}
154+
{% raw %}
155+
- name: Validate SARIF Results
156+
shell: bash
157+
run: |
158+
# Compare the expected vs the actual
159+
qlt bundle run validate-integration-tests --expected integration-tests/${{ matrix.language }}/expected.sarif --actual ${{ steps.analysis.outputs.sarif-output }}/${{ matrix.language }}.sarif
160+
{% endraw %}
161+
{% else %}

src/CodeQLToolkit.Features/Test/Lifecycle/Targets/Actions/InitLifecycleTarget.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,7 @@ public override void Run()
4545

4646
var message = @"------------------------------------------
4747
Your repository now has the CodeQL Unit Test Runner installed in `.github/workflows/`. Additionally,
48-
QLT has installed necessary actions for keeping your version of QLT and CodeQL current in `.github/actions/install-qlt` and
49-
`.github/actions/install-codeql`.
48+
QLT has installed necessary actions for keeping your version of QLT and CodeQL current in `.github/actions/install-qlt`.
5049
5150
Note that, by default, your runner will use 4 threads and defaults to the `ubuntu-latest` runner.
5251

0 commit comments

Comments
 (0)