Skip to content

Commit 4d5cb8a

Browse files
author
Nicolas Kraiouchkine
authored
Merge pull request #25 from kraiouchkine/multi-platform-bundles
Add support for multi-platform bundle generation and additional files/certs
2 parents baf8c6a + 0fc5ed3 commit 4d5cb8a

34 files changed

+272
-415
lines changed

.github/actions/install-qlt-local/action.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ runs:
6060
pip install -U pyinstaller
6161
6262
# run the packaging
63-
./scripts/build_codeql_bundle_dist.ps1 -Version 0.2.0 -WorkDirectory dist -DestinationDirectory ./src/CodeQLToolkit.Core/bin/Release/net6.0/publish/linux-x64/tools/
63+
./scripts/build_codeql_bundle_dist.ps1 -Version 0.3.0 -WorkDirectory dist -DestinationDirectory ./src/CodeQLToolkit.Core/bin/Release/net6.0/publish/linux-x64/tools/
6464
env:
6565
GH_TOKEN: ${{ github.token }}
6666

.github/workflows/internal-build-release-linux64.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ jobs:
5050
pip install -U pyinstaller
5151
5252
# run the packaging
53-
./scripts/build_codeql_bundle_dist.ps1 -Version 0.2.0 -WorkDirectory dist -DestinationDirectory ./src/CodeQLToolkit.Core/bin/Release/net6.0/publish/linux-x64/tools/
53+
./scripts/build_codeql_bundle_dist.ps1 -Version 0.3.0 -WorkDirectory dist -DestinationDirectory ./src/CodeQLToolkit.Core/bin/Release/net6.0/publish/linux-x64/tools/
5454
env:
5555
GH_TOKEN: ${{ github.token }}
5656

.github/workflows/internal-build-release-macos64.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ jobs:
4848
pip install -U pyinstaller
4949
5050
# run the packaging
51-
./scripts/build_codeql_bundle_dist.ps1 -Version 0.2.0 -WorkDirectory dist -DestinationDirectory ./src/CodeQLToolkit.Core/bin/Release/net6.0/publish/macos-arm64/tools/
51+
./scripts/build_codeql_bundle_dist.ps1 -Version 0.3.0 -WorkDirectory dist -DestinationDirectory ./src/CodeQLToolkit.Core/bin/Release/net6.0/publish/macos-arm64/tools/
5252
env:
5353
GH_TOKEN: ${{ github.token }}
5454

.github/workflows/internal-build-release-win64.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ jobs:
4545
pip install -U pyinstaller
4646
4747
# run the packaging
48-
.\scripts\build_codeql_bundle_dist.ps1 -Version 0.2.0 -WorkDirectory dist -DestinationDirectory .\src\CodeQLToolkit.Core\bin\Release\net6.0\publish\windows-x64\tools\
48+
.\scripts\build_codeql_bundle_dist.ps1 -Version 0.3.0 -WorkDirectory dist -DestinationDirectory .\src\CodeQLToolkit.Core\bin\Release\net6.0\publish\windows-x64\tools\
4949
env:
5050
GH_TOKEN: ${{ github.token }}
5151

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

+6-3
Original file line numberDiff line numberDiff line change
@@ -92,13 +92,16 @@ jobs:
9292
${{ steps.analysis.outputs.sarif-output }}/*.sarif
9393
if-no-files-found: error
9494

95-
- name: Upload Bundle Used
95+
- name: Upload Bundles
9696
uses: actions/upload-artifact@v2
9797
with:
98-
name: codeql-bundle.tar.gz
98+
name: codeql-bundles
9999
path: |
100-
${{ env.QLT_CODEQL_BUNDLE_PATH }}
100+
${{ env.QLT_CODEQL_BUNDLE_PATH_LINUX64 }}
101+
${{ env.QLT_CODEQL_BUNDLE_PATH_WIN64 }}
102+
${{ env.QLT_CODEQL_BUNDLE_PATH_OSX64 }}
101103
if-no-files-found: error
104+
compression-level: 0
102105

103106
- name: Validate SARIF Results
104107
shell: bash

.github/workflows/run-bundle-integration-tests-cpp.yml

+6-4
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ jobs:
5252
fi
5353
5454
# ensure bundle runs
55-
5655
if ! qlt query run install-packs --use-bundle --base example/ ; then
5756
echo "Failed to install query packs with tool."
5857
exit 1
@@ -65,13 +64,16 @@ jobs:
6564
echo "Checking Bundle Existence"
6665
ls -l ${{ env.QLT_CODEQL_HOME }}/../out/
6766
68-
- name: Upload Bundle Used
67+
- name: Upload Bundles
6968
uses: actions/upload-artifact@v2
7069
with:
71-
name: codeql-bundle.tar.gz
70+
name: codeql-bundles
7271
path: |
73-
${{ env.QLT_CODEQL_BUNDLE_PATH }}
72+
${{ env.QLT_CODEQL_BUNDLE_PATH_LINUX64 }}
73+
${{ env.QLT_CODEQL_BUNDLE_PATH_WIN64 }}
74+
${{ env.QLT_CODEQL_BUNDLE_PATH_OSX64 }}
7475
if-no-files-found: error
76+
compression-level: 0
7577

7678
- name: Initialize CodeQL
7779
uses: github/codeql-action/init@v2

developer_guide.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ Note that we keep recent copies of tools (for local debugging purposes) in the `
1515
**CodeQL Bundle**
1616

1717
```
18-
./scripts/build_codeql_bundle_dist.ps1 -Version 0.2.0 -WorkDirectory dist -DestinationDirectory ./src/CodeQLToolkit.Core/bin/Debug/net6.0/tools
18+
./scripts/build_codeql_bundle_dist.ps1 -Version 0.3.0 -WorkDirectory dist -DestinationDirectory ./src/CodeQLToolkit.Core/bin/Debug/net6.0/tools
1919
```
2020

2121

scripts/build_codeql_bundle_dist.ps1

+7-6
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
param(
2-
[Parameter(Mandatory=$true)]
2+
[Parameter(Mandatory = $true)]
33
[string]
44
$Version,
5-
[Parameter(Mandatory=$true)]
5+
[Parameter(Mandatory = $true)]
66
[string]
77
$WorkDirectory,
88

9-
[Parameter(Mandatory=$true)]
9+
[Parameter(Mandatory = $true)]
1010
[string]
1111
$DestinationDirectory
1212
)
@@ -20,7 +20,7 @@ if (-not (Test-Path $DestinationDirectory)) {
2020
}
2121

2222
# download a copy of the release from GitHub
23-
gh release download "v$Version" --repo https://github.com/jsinglet/codeql-bundle -D $WorkDirectory -A zip
23+
gh release download "v$Version" --repo https://github.com/kraiouchkine/codeql-bundle -D $WorkDirectory -A zip
2424

2525
# extract the zip file
2626
Expand-Archive -Path "$WorkDirectory\codeql-bundle-$Version.zip" -DestinationPath $WorkDirectory
@@ -45,9 +45,10 @@ pyinstaller -F -n codeql_bundle cli.py
4545
Pop-Location
4646
Pop-Location
4747

48-
if($IsWindows){
48+
if ($IsWindows) {
4949
$OutputFile = Join-Path $ArchiveDirectory "codeql_bundle" "dist" "codeql_bundle.exe"
50-
}else{
50+
}
51+
else {
5152
$OutputFile = Join-Path $ArchiveDirectory "codeql_bundle" "dist" "codeql_bundle"
5253
}
5354

src/CodeQLToolkit.Features/Bundle/BundleFeatureMain.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ private BundleFeatureMain()
2929
commandFeature = new BundleCommandFeature();
3030
lifecycleFeature = new BundleLifecycleFeature();
3131
}
32-
public static BundleFeatureMain Instance { get { return instance; } }
32+
public static BundleFeatureMain Instance => instance;
3333

3434
public void Register(Command parentCommand)
3535
{

src/CodeQLToolkit.Features/Bundle/Commands/BundleCommandFeature.cs

+2-5
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,7 @@ namespace CodeQLToolkit.Features.Bundle.Commands
1111
{
1212
public class BundleCommandFeature : FeatureBase, IToolkitLifecycleFeature
1313
{
14-
public override LanguageType[] SupportedLangauges
15-
{
16-
get => new LanguageType[] {
14+
public override LanguageType[] SupportedLangauges => new LanguageType[] {
1715
LanguageType.C,
1816
LanguageType.CPP,
1917
LanguageType.CSHARP,
@@ -23,7 +21,6 @@ public override LanguageType[] SupportedLangauges
2321
LanguageType.RUBY,
2422
LanguageType.PYTHON
2523
};
26-
}
2724

2825
public BundleCommandFeature()
2926
{
@@ -62,7 +59,7 @@ public void Register(Command parentCommand)
6259

6360
}.Run();
6461

65-
},Globals.BasePathOption, expectedOption, actualOption);
62+
}, Globals.BasePathOption, expectedOption, actualOption);
6663
}
6764

6865
public int Run()

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

+3-6
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,12 @@ namespace CodeQLToolkit.Features.Bundle.Lifecycle
77
{
88
public class BundleLifecycleFeature : FeatureBase, IToolkitLifecycleFeature
99
{
10-
public BundleLifecycleFeature()
10+
public BundleLifecycleFeature()
1111
{
1212
FeatureName = "Bundle";
1313
}
1414

15-
public override LanguageType[] SupportedLangauges
16-
{
17-
get => new LanguageType[] {
15+
public override LanguageType[] SupportedLangauges => new LanguageType[] {
1816
LanguageType.C,
1917
LanguageType.CPP,
2018
LanguageType.CSHARP,
@@ -24,7 +22,6 @@ public override LanguageType[] SupportedLangauges
2422
LanguageType.RUBY,
2523
LanguageType.PYTHON
2624
};
27-
}
2825

2926
public void Register(Command parentCommand)
3027
{
@@ -44,7 +41,7 @@ public void Register(Command parentCommand)
4441
var setCommand = new Command("set", "Functions pertaining to setting variables related to custom CodeQL bundles.");
4542
//parentCommand.Add(setCommand);
4643

47-
var enableCommand = new Command("enable-custom-bundles", "Enables custom CodeQL Bundles.");
44+
var enableCommand = new Command("enable-custom-bundles", "Enables custom CodeQL Bundles.");
4845
//setCommand.Add(enableCommand);
4946

5047
var disableCommand = new Command("disable-custom-bundles", "Disables custom CodeQL Bundles.");

src/CodeQLToolkit.Features/CodeQL/CodeQLFeatureMain.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
namespace CodeQLToolkit.Features.CodeQL
99
{
10-
public class CodeQLFeatureMain : IToolkitFeature
10+
public class CodeQLFeatureMain : IToolkitFeature
1111
{
1212
readonly CodeQLLifecycleFeature lifecycleFeature;
1313
readonly CodeQLCommandFeature commandFeature;
@@ -24,7 +24,7 @@ private CodeQLFeatureMain()
2424
commandFeature = new CodeQLCommandFeature();
2525
}
2626

27-
public static CodeQLFeatureMain Instance { get { return instance; } }
27+
public static CodeQLFeatureMain Instance => instance;
2828

2929
public int Run()
3030
{
@@ -36,7 +36,7 @@ public void Register(Command parentCommand)
3636
{
3737
var queryCommand = new Command("codeql", "Use the features related to managing the version of CodeQL used by this repository.");
3838
parentCommand.Add(queryCommand);
39-
39+
4040
Log<CodeQLFeatureMain>.G().LogInformation("Registering scaffolding submodule.");
4141
lifecycleFeature.Register(queryCommand);
4242

src/CodeQLToolkit.Features/CodeQL/Commands/CodeQLCommandFeature.cs

+7-7
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,16 @@ namespace CodeQLToolkit.Features.CodeQL.Commands
1515
{
1616
public class CodeQLCommandFeature : FeatureBase, IToolkitLifecycleFeature
1717
{
18-
public override LanguageType[] SupportedLangauges { get => new LanguageType[] {
18+
public override LanguageType[] SupportedLangauges => new LanguageType[] {
1919
LanguageType.C,
2020
LanguageType.CPP,
2121
LanguageType.CSHARP,
2222
LanguageType.JAVA,
2323
LanguageType.JAVASCRIPT,
2424
LanguageType.GO,
2525
LanguageType.RUBY,
26-
LanguageType.PYTHON
27-
}; }
26+
LanguageType.PYTHON
27+
};
2828

2929
public CodeQLCommandFeature()
3030
{
@@ -37,18 +37,18 @@ public void Register(Command parentCommand)
3737

3838
var runCommand = new Command("run", "Functions pertaining to running codeql-related commands.");
3939
parentCommand.Add(runCommand);
40-
40+
4141
var installCommand = new Command("install", "Installs CodeQL (bundle or release distribution) locally.");
42-
var customBundleOption = new Option<bool>("--custom-bundle", () => false, "Build a custom bundle and compile the bundle.") { IsRequired = true};
43-
var quickBundleOption = new Option<bool>("--quick-bundle", () => false, "Build a custom bundle and DO NOT compile the bundle.") { IsRequired = true};
42+
var customBundleOption = new Option<bool>("--custom-bundle", () => false, "Build a custom bundle and compile the bundle.") { IsRequired = true };
43+
var quickBundleOption = new Option<bool>("--quick-bundle", () => false, "Build a custom bundle and DO NOT compile the bundle.") { IsRequired = true };
4444
var packsOption = new Option<string[]>("--packs", "When creating bundles, this specifies the packs to include, Example `pack1 pack2 pack3`. You may specify also as `--pack pack1 --pack2 --pack3`") { IsRequired = false, AllowMultipleArgumentsPerToken = true };
4545

4646
installCommand.Add(customBundleOption);
4747
installCommand.Add(quickBundleOption);
4848
installCommand.Add(packsOption);
4949

5050
runCommand.Add(installCommand);
51-
51+
5252
installCommand.SetHandler((basePath, automationType, customBundleOption, quickBundleOption, packs) =>
5353
{
5454
Log<CodeQLCommandFeature>.G().LogInformation("Executing install command...");

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

+38-31
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,45 @@ public class InstallCommand : CommandTarget
1515
public bool CustomBundles { get; set; }
1616
public bool QuickBundles { get; set; }
1717
public string[] Packs { get; set; }
18+
19+
void SetEnvironmentVariableMultiTarget(string name, string value)
20+
{
21+
Log<InstallCommand>.G().LogInformation($"Setting {name} to {value}...");
22+
23+
Environment.SetEnvironmentVariable(name, value);
24+
25+
if (AutomationTypeHelper.AutomationTypeFromString(AutomationTarget) == AutomationType.ACTIONS)
26+
{
27+
string? githubEnvPath = Environment.GetEnvironmentVariable("GITHUB_ENV");
28+
try
29+
{
30+
if (File.Exists(githubEnvPath))
31+
{
32+
File.AppendAllText(githubEnvPath, $"{name}={value}\n");
33+
}
34+
else
35+
{
36+
throw new Exception("Could not find GITHUB_ENV file.");
37+
}
38+
}
39+
catch (Exception)
40+
{
41+
Log<InstallCommand>.G().LogError($"Could not write to GITHUB_ENV file.");
42+
throw;
43+
}
44+
}
45+
}
46+
1847
public override void Run()
1948
{
2049
Log<InstallCommand>.G().LogInformation($"Running Install command");
2150

2251
// First, check if CodeQL is installed.
2352
var installation = CodeQLInstallation.LoadFromConfig(Base);
24-
if(CustomBundles || QuickBundles)
53+
if (CustomBundles || QuickBundles)
2554
{
2655
installation.EnableCustomCodeQLBundles = true;
27-
if (Packs!=null && Packs.Length > 0)
56+
if (Packs != null && Packs.Length > 0)
2857
{
2958
Log<InstallCommand>.G().LogInformation($"Overriding Packs on the command line. The following Packs will be packaged:");
3059
installation.CodeQLPackConfiguration = Packs.Select(p => new CodeQLPackConfiguration()
@@ -40,14 +69,12 @@ public override void Run()
4069

4170
installation.LogPacksToBeBuilt();
4271

43-
4472
installation.QuickBundle = QuickBundles;
4573
}
4674

4775
Log<InstallCommand>.G().LogInformation($"Checking for installation...");
4876

49-
// if it is the case that it is installed but we are in custom bundle mode we RE install it.
50-
77+
// If CodeQL is already installed, but custom bundles are enabled, reinstall CodeQL anyway to ensure use of the correct custom bundle.
5178
if (installation.IsInstalled() && !installation.EnableCustomCodeQLBundles)
5279
{
5380
Log<InstallCommand>.G().LogInformation($"CodeQL is already installed at that version. Please delete the installation directory to reinstall.");
@@ -57,39 +84,19 @@ public override void Run()
5784
Log<InstallCommand>.G().LogInformation($"Installing CodeQL...");
5885
installation.Install();
5986

60-
// set the environment variable
61-
Log<InstallCommand>.G().LogInformation($"Setting QLT_CODEQL_HOME to {installation.CodeQLHome}...");
62-
Log<InstallCommand>.G().LogInformation($"Setting QLT_CODEQL_PATH to {installation.CodeQLToolBinary}...");
87+
SetEnvironmentVariableMultiTarget("QLT_CODEQL_HOME", installation.CodeQLHome);
88+
SetEnvironmentVariableMultiTarget("QLT_CODEQL_PATH", installation.CodeQLToolBinary);
6389

64-
Environment.SetEnvironmentVariable("QLT_CODEQL_HOME", installation.CodeQLHome);
65-
Environment.SetEnvironmentVariable("QLT_CODEQL_PATH", installation.CodeQLToolBinary);
6690
if (CustomBundles || QuickBundles)
6791
{
68-
Environment.SetEnvironmentVariable("QLT_CODEQL_BUNDLE_PATH", installation.CustomBundleOutputBundle);
69-
}
70-
71-
if (AutomationTypeHelper.AutomationTypeFromString(AutomationTarget) == AutomationType.ACTIONS)
72-
{
73-
if (Environment.GetEnvironmentVariable("GITHUB_ENV") != null && File.Exists(Environment.GetEnvironmentVariable("GITHUB_ENV")))
74-
{
75-
76-
File.AppendAllText(Environment.GetEnvironmentVariable("GITHUB_ENV"), $"QLT_CODEQL_HOME={installation.CodeQLHome}" + "\n");
77-
File.AppendAllText(Environment.GetEnvironmentVariable("GITHUB_ENV"), $"QLT_CODEQL_PATH={installation.CodeQLToolBinary}" + "\n");
78-
if (CustomBundles || QuickBundles)
79-
{
80-
File.AppendAllText(Environment.GetEnvironmentVariable("GITHUB_ENV"), $"QLT_CODEQL_BUNDLE_PATH={installation.CustomBundleOutputBundle}" + "\n");
81-
}
82-
}
92+
SetEnvironmentVariableMultiTarget("QLT_CODEQL_BUNDLE_PATH", installation.CustomBundleOutputBundleCurrentPlatform);
93+
SetEnvironmentVariableMultiTarget("QLT_CODEQL_BUNDLE_PATH_WIN64", installation.CustomBundleOutputBundleWindows);
94+
SetEnvironmentVariableMultiTarget("QLT_CODEQL_BUNDLE_PATH_OSX64", installation.CustomBundleOutputBundleOSX);
95+
SetEnvironmentVariableMultiTarget("QLT_CODEQL_BUNDLE_PATH_LINUX64", installation.CustomBundleOutputBundleLinux);
8396
}
84-
8597
}
8698

87-
8899
Log<InstallCommand>.G().LogInformation($"Done.");
89-
90-
91-
92-
93100
}
94101
}
95102
}

0 commit comments

Comments
 (0)