|
3 | 3 | ## Desc: Install the CodeQL CLI Bundle to the toolcache. |
4 | 4 | ################################################################################ |
5 | 5 |
|
6 | | -# Retrieve the CLI versions and bundle tags of the latest two CodeQL bundles. |
| 6 | +# Retrieve the CLI version of the latest CodeQL bundle. |
7 | 7 | $Defaults = (Invoke-RestMethod "https://raw.githubusercontent.com/github/codeql-action/v2/src/defaults.json") |
8 | | -$CodeQLTagName = $Defaults.bundleVersion |
9 | | -$CodeQLCliVersion = $Defaults.cliVersion |
10 | | -$PriorCodeQLTagName = $Defaults.priorBundleVersion |
11 | | -$PriorCodeQLCliVersion = $Defaults.priorCliVersion |
| 8 | +$CliVersion = $Defaults.cliVersion |
| 9 | +$TagName = "codeql-bundle-v" + $CliVersion |
12 | 10 |
|
13 | | -# Compute the toolcache version number for each bundle. This is either `x.y.z` or `x.y.z-YYYYMMDD`. |
14 | | -if ($CodeQLTagName.split("-")[-1].StartsWith("v")) { |
15 | | - # Tag name of the format `codeql-bundle-vx.y.z`, where x.y.z is the CLI version. |
16 | | - # We don't need to include the tag name in the toolcache version number because it's derivable |
17 | | - # from the CLI version. |
18 | | - $CodeQLBundleVersion = $CodeQLCliVersion |
19 | | -} elseif ($CodeQLTagName.split("-")[-1] -match "^\d+$") { |
20 | | - # Tag name of the format `codeql-bundle-YYYYMMDD`. |
21 | | - # We need to include the tag name in the toolcache version number because it can't be derived |
22 | | - # from the CLI version. |
23 | | - $CodeQLBundleVersion = $CodeQLCliVersion + "-" + $CodeQLTagName.split("-")[-1] |
24 | | -} else { |
25 | | - Write-Error "Unrecognised current CodeQL bundle tag name: $CodeQLTagName. Could not compute toolcache version number." |
26 | | - exit 1 |
27 | | -} |
28 | | -if ($PriorCodeQLTagName.split("-")[-1].StartsWith("v")) { |
29 | | - # Tag name of the format `codeql-bundle-vx.y.z`, where x.y.z is the CLI version. |
30 | | - # We don't need to include the tag name in the toolcache version number because it's derivable |
31 | | - # from the CLI version. |
32 | | - $PriorCodeQLBundleVersion = $PriorCodeQLCliVersion |
33 | | -} elseif ($PriorCodeQLTagName.split("-")[-1] -match "^\d+$") { |
34 | | - # Tag name of the format `codeql-bundle-YYYYMMDD`. |
35 | | - # We need to include the tag name in the toolcache version number because it can't be derived |
36 | | - # from the CLI version. |
37 | | - $PriorCodeQLBundleVersion = $PriorCodeQLCliVersion + "-" + $PriorCodeQLTagName.split("-")[-1] |
38 | | -} else { |
39 | | - Write-Error "Unrecognised prior CodeQL bundle tag name: $PriorCodeQLTagName. Could not compute toolcache version number." |
40 | | - exit 1 |
41 | | -} |
| 11 | +Write-Host "Downloading CodeQL bundle $($CliVersion)..." |
| 12 | +# Note that this is the all-platforms CodeQL bundle, to support scenarios where customers run |
| 13 | +# different operating systems within containers. |
| 14 | +$CodeQLBundlePath = Start-DownloadWithRetry -Url "https://github.com/github/codeql-action/releases/download/$($TagName)/codeql-bundle.tar.gz" -Name "codeql-bundle.tar.gz" |
| 15 | +$DownloadDirectoryPath = (Get-Item $CodeQLBundlePath).Directory.FullName |
42 | 16 |
|
43 | | -$Bundles = @( |
44 | | - [PSCustomObject]@{ |
45 | | - TagName=$CodeQLTagName; |
46 | | - BundleVersion=$CodeQLBundleVersion; |
47 | | - }, |
48 | | - [PSCustomObject]@{ |
49 | | - TagName=$PriorCodeQLTagName; |
50 | | - BundleVersion=$PriorCodeQLBundleVersion; |
51 | | - } |
52 | | -) |
| 17 | +$CodeQLToolcachePath = Join-Path $Env:AGENT_TOOLSDIRECTORY -ChildPath "CodeQL" | Join-Path -ChildPath $CliVersion | Join-Path -ChildPath "x64" |
| 18 | +New-Item -Path $CodeQLToolcachePath -ItemType Directory -Force | Out-Null |
53 | 19 |
|
54 | | -foreach ($Bundle in $Bundles) { |
55 | | - Write-Host "Downloading CodeQL bundle $($Bundle.BundleVersion)..." |
56 | | - $CodeQLBundlePath = Start-DownloadWithRetry -Url "https://github.com/github/codeql-action/releases/download/$($Bundle.TagName)/codeql-bundle.tar.gz" -Name "codeql-bundle.tar.gz" |
57 | | - $DownloadDirectoryPath = (Get-Item $CodeQLBundlePath).Directory.FullName |
| 20 | +Write-Host "Unpacking the downloaded CodeQL bundle archive..." |
| 21 | +Extract-7Zip -Path $CodeQLBundlePath -DestinationPath $DownloadDirectoryPath |
| 22 | +$UnGzipedCodeQLBundlePath = Join-Path $DownloadDirectoryPath "codeql-bundle.tar" |
| 23 | +Extract-7Zip -Path $UnGzipedCodeQLBundlePath -DestinationPath $CodeQLToolcachePath |
58 | 24 |
|
59 | | - $CodeQLToolcachePath = Join-Path $Env:AGENT_TOOLSDIRECTORY -ChildPath "CodeQL" | Join-Path -ChildPath $Bundle.BundleVersion | Join-Path -ChildPath "x64" |
60 | | - New-Item -Path $CodeQLToolcachePath -ItemType Directory -Force | Out-Null |
| 25 | +Write-Host "CodeQL bundle at $($CodeQLToolcachePath) contains the following directories:" |
| 26 | +Get-ChildItem -Path $CodeQLToolcachePath -Depth 2 |
61 | 27 |
|
62 | | - Write-Host "Unpacking the downloaded CodeQL bundle archive..." |
63 | | - Extract-7Zip -Path $CodeQLBundlePath -DestinationPath $DownloadDirectoryPath |
64 | | - $UnGzipedCodeQLBundlePath = Join-Path $DownloadDirectoryPath "codeql-bundle.tar" |
65 | | - Extract-7Zip -Path $UnGzipedCodeQLBundlePath -DestinationPath $CodeQLToolcachePath |
| 28 | +# Touch a file to indicate to the CodeQL Action that this bundle shipped with the toolcache. This is |
| 29 | +# to support overriding the CodeQL version specified in defaults.json on GitHub Enterprise. |
| 30 | +New-Item -ItemType file (Join-Path $CodeQLToolcachePath -ChildPath "pinned-version") |
66 | 31 |
|
67 | | - # We only pin the latest version in the toolcache, to support overriding the CodeQL version specified in defaults.json on GitHub Enterprise. |
68 | | - if ($Bundle.BundleVersion -eq $CodeQLBundleVersion) { |
69 | | - New-Item -ItemType file (Join-Path $CodeQLToolcachePath -ChildPath "pinned-version") |
70 | | - } |
71 | | - |
72 | | - # Touch a file to indicate to the toolcache that setting up CodeQL is complete. |
73 | | - New-Item -ItemType file "$CodeQLToolcachePath.complete" |
74 | | -} |
| 32 | +# Touch a file to indicate to the toolcache that setting up CodeQL is complete. |
| 33 | +New-Item -ItemType file "$CodeQLToolcachePath.complete" |
75 | 34 |
|
76 | 35 | # Test that the tools have been extracted successfully. |
77 | | -Invoke-PesterTests -TestFile "Tools" -TestName "CodeQLBundles" |
| 36 | +Invoke-PesterTests -TestFile "Tools" -TestName "CodeQL Bundle" |
0 commit comments