Skip to content

Commit 26cb693

Browse files
authored
Merge pull request #22 from advanced-security/jsinglet/repo-library-issue
adding new option for default codescanning config
2 parents 35baef8 + 4367b9a commit 26cb693

File tree

20 files changed

+511
-38
lines changed

20 files changed

+511
-38
lines changed

.github/workflows/internal-pr-bundle-integration-test-cpp.yml

+2-3
Original file line numberDiff line numberDiff line change
@@ -66,13 +66,12 @@ jobs:
6666
with:
6767
languages: ${{ matrix.language }}
6868
queries: security-extended
69-
source-root: integration-tests/cpp/src/ # Path containing the example application
7069
tools: ${{ env.QLT_CODEQL_BUNDLE_PATH }}
7170

7271
- name: Autobuild
7372
uses: github/codeql-action/autobuild@v2
7473
with:
75-
working-directory: integration-tests/cpp/src/ # Path containing the example application
74+
working-directory: example/integration-tests/cpp/src/ # Path containing the example application
7675

7776
- name: Perform CodeQL Analysis
7877
id: analysis
@@ -105,4 +104,4 @@ jobs:
105104
shell: bash
106105
run: |
107106
# Compare the expected vs the actual
108-
qlt bundle run validate-integration-tests --expected integration-tests/cpp/expected.sarif --actual ${{ steps.analysis.outputs.sarif-output }}/cpp.sarif
107+
qlt bundle run validate-integration-tests --expected example/integration-tests/cpp/expected.sarif --actual ${{ steps.analysis.outputs.sarif-output }}/cpp.sarif

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

+9
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: |
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
name: ⚙️ Integration Test Bundle (cpp)
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+
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+
37+
38+
- name: Validate QLT Installation
39+
shell: bash
40+
run: |
41+
echo -e "Checking QLT Version:"
42+
echo "QLT Home: ${{ steps.install-qlt.outputs.qlt-home }}"
43+
qlt version
44+
45+
46+
- name: Create Bundle (compiled)
47+
shell: bash
48+
run: |
49+
if ! qlt codeql run install --custom-bundle --base example/ ; then
50+
echo "Failed to generate bundle."
51+
exit 1
52+
fi
53+
54+
# ensure bundle runs
55+
56+
if ! qlt query run install-packs --use-bundle --base example/ ; then
57+
echo "Failed to install query packs with tool."
58+
exit 1
59+
fi
60+
61+
62+
- name: Validate Bundle Existence
63+
shell: bash
64+
run: |
65+
echo "Checking Bundle Existence"
66+
ls -l ${{ env.QLT_CODEQL_HOME }}/../out/
67+
68+
- name: Upload Bundle Used
69+
uses: actions/upload-artifact@v2
70+
with:
71+
name: codeql-bundle.tar.gz
72+
path: |
73+
${{ env.QLT_CODEQL_BUNDLE_PATH }}
74+
if-no-files-found: error
75+
76+
- name: Initialize CodeQL
77+
uses: github/codeql-action/init@v2
78+
with:
79+
languages: ${{ matrix.language }}
80+
tools: ${{ env.QLT_CODEQL_BUNDLE_PATH }}
81+
82+
83+
84+
- name: Autobuild
85+
uses: github/codeql-action/autobuild@v2
86+
with:
87+
working-directory: example/integration-tests/${{ matrix.language }}/src/ # Path containing the example application
88+
89+
90+
91+
- name: Perform CodeQL Analysis
92+
id: analysis
93+
uses: github/codeql-action/analyze@v2
94+
95+
- name: Validate SARIF Location
96+
shell: bash
97+
run: |
98+
# validate we have the actual sarif results
99+
echo "Checking SARIF file location at: ${{ steps.analysis.outputs.sarif-output }}"
100+
ls -l ${{ steps.analysis.outputs.sarif-output }}
101+
102+
- name: Upload SARIF Results
103+
uses: actions/upload-artifact@v2
104+
with:
105+
name: actual.sarif
106+
path: |
107+
${{ steps.analysis.outputs.sarif-output }}/*.sarif
108+
if-no-files-found: error
109+
110+
- name: Validate SARIF Existence
111+
shell: bash
112+
run: |
113+
ls -l ${{ steps.analysis.outputs.sarif-output }}/*.sarif
114+
115+
116+
117+
118+
- name: Validate SARIF Results
119+
shell: bash
120+
run: |
121+
# Compare the expected vs the actual
122+
qlt bundle run validate-integration-tests --expected example/integration-tests/${{ matrix.language }}/expected.sarif --actual ${{ steps.analysis.outputs.sarif-output }}/${{ matrix.language }}.sarif
123+

example/qlt.conf.json

+4-3
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,15 @@
44
"CodeQLCLIBundle": "codeql-bundle-v2.15.5",
55
"EnableCustomCodeQLBundles": true,
66
"CodeQLStandardLibraryIdent": "codeql-cli_v2.15.5",
7-
"CustomizationPacks" : [
7+
"CodeQLPackConfiguration" : [
88
{
99
"Name": "qlt/cpp-customizations",
10-
"Export" : true
10+
"Bundle" : true
1111
},
1212
{
1313
"Name": "qlt2/stuff2-tests",
14-
"Export" : false
14+
"Bundle" : false,
15+
"ReferencesBundle" : true
1516
}
1617
]
1718
}

src/CodeQLToolkit.Core/Properties/launchSettings.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"profiles": {
33
"CodeQLToolkit.Core": {
44
"commandName": "Project",
5-
"commandLineArgs": "--base C:\\Projects\\codeql-development-lifecycle-toolkit\\example bundle set enable-custom-bundles"
5+
"commandLineArgs": "bundle init --use-runner ubuntu-latest --language cpp --automation-type actions --development --overwrite-existing"
66
}
77
}
88
}

src/CodeQLToolkit.Core/ver.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.0.17
1+
0.0.23

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

-5
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,7 @@ namespace CodeQLToolkit.Features.Bundle.Lifecycle
88
{
99
abstract public class BaseLifecycleTarget : ILifecycleTarget
1010
{
11-
public int NumThreads { get; set; }
1211
public string UseRunner { get; set; }
1312

14-
public string ExtraArgs { get; set; }
15-
16-
17-
1813
}
1914
}

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

+34-6
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
1-
using CodeQLToolkit.Features.CodeQL.Lifecycle.Targets;
2-
using CodeQLToolkit.Features.CodeQL.Lifecycle;
3-
using CodeQLToolkit.Features.Test.Lifecycle.Targets;
4-
using CodeQLToolkit.Features.Test.Lifecycle.Targets.Actions;
1+
using CodeQLToolkit.Features.CodeQL.Lifecycle;
52
using CodeQLToolkit.Shared.Utils;
63
using System.CommandLine;
7-
using System.Reflection;
84
using CodeQLToolkit.Features.Bundle.Lifecycle.Targets;
95

106
namespace CodeQLToolkit.Features.Bundle.Lifecycle
@@ -32,7 +28,18 @@ public override LanguageType[] SupportedLangauges
3228

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

3744
var setCommand = new Command("set", "Functions pertaining to setting variables related to custom CodeQL bundles.");
3845
//parentCommand.Add(setCommand);
@@ -90,6 +97,27 @@ public void Register(Command parentCommand)
9097
}
9198

9299

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

95123
public int Run()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
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+
[AutomationType(AutomationType.ACTIONS)]
10+
public class InitLifecycleTarget : BaseLifecycleTarget
11+
{
12+
13+
public InitLifecycleTarget()
14+
{
15+
AutomationType = AutomationType.ACTIONS;
16+
}
17+
18+
public override void Run()
19+
{
20+
Log<InitLifecycleTarget>.G().LogInformation("Running init command...");
21+
22+
// temporarily disable the language resolution
23+
var tmpLanguage = Language;
24+
Language = null;
25+
26+
WriteTemplateIfOverwriteOrNotExists("install-qlt", Path.Combine(Base, ".github", "actions", "install-qlt", "action.yml"), "install-qlt action");
27+
WriteTemplateIfOverwriteOrNotExists("run-bundle-integration-tests", Path.Combine(Base, ".github", "workflows", $"run-bundle-integration-tests-{tmpLanguage}.yml"), $"Run CodeQL Unit Tests ({Language})", new
28+
{
29+
useRunner = UseRunner,
30+
language = tmpLanguage,
31+
devMode = DevMode,
32+
});
33+
34+
Language = tmpLanguage;
35+
36+
var message = @"------------------------------------------
37+
Your repository now has the Bundle Creation and Integration Test Runner installed in `.github/workflows/`. Additionally,
38+
QLT has installed necessary actions for keeping your version of QLT and CodeQL current in `.github/actions/install-qlt`.
39+
40+
Note that for integration testing to work, you MUST create a directory `integration-test` in the root of your repository. Please
41+
consult the QLT documentation for details on how to structure this directory.
42+
43+
In addition to using QLT to generate your files you can also directly edit this file to fine tune its settings.
44+
45+
(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.)";
46+
47+
Log<InitLifecycleTarget>.G().LogInformation(message);
48+
}
49+
}
50+
}

src/CodeQLToolkit.Features/CodeQL/Commands/Targets/InstallCommand.cs

+3-2
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,10 @@ public override void Run()
2727
if (Packs!=null && Packs.Length > 0)
2828
{
2929
Log<InstallCommand>.G().LogInformation($"Overriding Packs on the command line. The following Packs will be packaged:");
30-
installation.CustomizationPacks = Packs.Select(p => new QLTCustomizationPack()
30+
installation.CodeQLPackConfiguration = Packs.Select(p => new CodeQLPackConfiguration()
3131
{
32-
Name = p
32+
Name = p,
33+
Bundle = true
3334
}).ToArray();
3435
}
3536
else

src/CodeQLToolkit.Features/CodeQLToolkit.Features.csproj

+6-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
</ItemGroup>
1212

1313
<ItemGroup>
14-
<Folder Include="Bundle\Lifecycle\Targets\Actions\" />
1514
<Folder Include="Bundle\Models\" />
1615
<Folder Include="Pack\" />
1716
<Folder Include="Templates\Validation\Actions\" />
@@ -22,6 +21,12 @@
2221
</ItemGroup>
2322

2423
<ItemGroup>
24+
<None Update="Templates\Bundle\Actions\install-qlt.liquid">
25+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
26+
</None>
27+
<None Update="Templates\Bundle\Actions\run-bundle-integration-tests.liquid">
28+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
29+
</None>
2530
<None Update="Templates\Query\codeql-workspace.liquid">
2631
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
2732
</None>

src/CodeQLToolkit.Features/Query/Commands/Targets/InstallQueryPacksCommandTarget.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,15 @@ public override void Run()
4141
Log<InstallQueryPacksCommandTarget>.G().LogInformation("In bundle mode so filtering bundled packs...");
4242

4343

44-
foreach (var pack in config.CustomizationPacks)
44+
foreach (var pack in config.CodeQLPackConfiguration)
4545
{
4646
Log<InstallQueryPacksCommandTarget>.G().LogInformation($"Pack {pack.Name} will NOT installed because it is part of the bundle...");
4747
}
4848

4949
files = files.Where(f =>
5050
// all things that are part of the customization pack must be excluded.
5151
// if it is exported is not relevant here.
52-
!config.CustomizationPacks.Any(p => CodeQLPackReader.read(f).Name == p.Name)
52+
!config.CodeQLPackConfiguration.Any(p => CodeQLPackReader.read(f).Name == p.Name && (p.Bundle==true || p.ReferencesBundle==true))
5353
).ToArray();
5454

5555
Log<InstallQueryPacksCommandTarget>.G().LogInformation($"Got {files.Length} packs after filtering...");

0 commit comments

Comments
 (0)