|
1 | 1 | #!/bin/bash -e -o pipefail |
2 | 2 | source ~/utils/utils.sh |
3 | 3 |
|
4 | | -# Retrieve the CLI versions and bundle tags of the latest two CodeQL bundles. |
| 4 | +# Retrieve the CLI version of the latest CodeQL bundle. |
5 | 5 | base_url="$(curl -fsSL https://raw.githubusercontent.com/github/codeql-action/v2/src/defaults.json)" |
6 | | -codeql_tag_name="$(echo "$base_url" | jq -r '.bundleVersion')" |
7 | | -codeql_cli_version="$(echo "$base_url" | jq -r '.cliVersion')" |
8 | | -prior_codeql_tag_name="$(echo "$base_url" | jq -r '.priorBundleVersion')" |
9 | | -prior_codeql_cli_version="$(echo "$base_url" | jq -r '.priorCliVersion')" |
| 6 | +bundle_version="$(echo "$base_url" | jq -r '.cliVersion')" |
| 7 | +bundle_tag_name="codeql-bundle-v$bundle_version" |
10 | 8 |
|
11 | | -# Compute the toolcache version number for each bundle. This is either `x.y.z` or `x.y.z-YYYYMMDD`. |
12 | | -if [[ "${codeql_tag_name##*-}" == "v"* ]]; then |
13 | | - # Tag name of the format `codeql-bundle-vx.y.z`, where x.y.z is the CLI version. |
14 | | - # We don't need to include the tag name in the toolcache version number because it's derivable |
15 | | - # from the CLI version. |
16 | | - codeql_bundle_version="$codeql_cli_version" |
17 | | -elif [[ "${codeql_tag_name##*-}" =~ ^[0-9]+$ ]]; then |
18 | | - # Tag name of the format `codeql-bundle-YYYYMMDD`. |
19 | | - # We need to include the tag name in the toolcache version number because it can't be derived |
20 | | - # from the CLI version. |
21 | | - codeql_bundle_version="$codeql_cli_version-${codeql_tag_name##*-}" |
22 | | -else |
23 | | - echo "Unrecognised current CodeQL bundle tag name: $codeql_tag_name." \ |
24 | | - "Could not compute toolcache version number." |
25 | | - exit 1 |
26 | | -fi |
27 | | -if [[ "${prior_codeql_tag_name##*-}" == "v"* ]]; then |
28 | | - # Tag name of the format `codeql-bundle-vx.y.z`, where x.y.z is the CLI version. |
29 | | - # We don't need to include the tag name in the toolcache version number because it's derivable |
30 | | - # from the CLI version. |
31 | | - prior_codeql_bundle_version="$prior_codeql_cli_version" |
32 | | -elif [[ "${prior_codeql_tag_name##*-}" =~ ^[0-9]+$ ]]; then |
33 | | - # Tag name of the format `codeql-bundle-YYYYMMDD`. |
34 | | - # We need to include the tag name in the toolcache version number because it can't be derived |
35 | | - # from the CLI version. |
36 | | - prior_codeql_bundle_version="$prior_codeql_cli_version-${prior_codeql_tag_name##*-}" |
37 | | -else |
38 | | - echo "Unrecognised prior CodeQL bundle tag name: $prior_codeql_tag_name." \ |
39 | | - "Could not compute toolcache version number." |
40 | | - exit 1 |
41 | | -fi |
| 9 | +echo "Downloading CodeQL bundle $bundle_version..." |
| 10 | +# Note that this is the all-platforms CodeQL bundle, to support scenarios where customers run |
| 11 | +# different operating systems within containers. |
| 12 | +download_with_retries "https://github.com/github/codeql-action/releases/download/$bundle_tag_name/codeql-bundle.tar.gz" "/tmp" "codeql-bundle.tar.gz" |
| 13 | +codeql_archive="/tmp/codeql-bundle.tar.gz" |
42 | 14 |
|
43 | | -# Download and name both CodeQL bundles. |
44 | | -codeql_bundle_versions=("${codeql_bundle_version}" "${prior_codeql_bundle_version}") |
45 | | -codeql_tag_names=("${codeql_tag_name}" "${prior_codeql_tag_name}") |
| 15 | +codeql_toolcache_path="$AGENT_TOOLSDIRECTORY/CodeQL/$bundle_version/x64" |
| 16 | +mkdir -p "$codeql_toolcache_path" |
46 | 17 |
|
47 | | -for index in "${!codeql_bundle_versions[@]}"; do |
48 | | - bundle_version="${codeql_bundle_versions[$index]}" |
49 | | - bundle_tag_name="${codeql_tag_names[$index]}" |
50 | | - |
51 | | - echo "Downloading CodeQL bundle $bundle_version..." |
52 | | - download_with_retries "https://github.com/github/codeql-action/releases/download/$bundle_tag_name/codeql-bundle.tar.gz" "/tmp" "codeql-bundle.tar.gz" |
53 | | - codeql_archive="/tmp/codeql-bundle.tar.gz" |
| 18 | +echo "Unpacking the downloaded CodeQL bundle archive..." |
| 19 | +tar -xzf "$codeql_archive" -C "$codeql_toolcache_path" |
54 | 20 |
|
55 | | - codeql_toolcache_path="$AGENT_TOOLSDIRECTORY/CodeQL/$bundle_version/x64" |
56 | | - mkdir -p "$codeql_toolcache_path" |
| 21 | +# Touch a file to indicate to the CodeQL Action that this bundle shipped with the toolcache. This is |
| 22 | +# to support overriding the CodeQL version specified in defaults.json on GitHub Enterprise. |
| 23 | +touch "$codeql_toolcache_path/pinned-version" |
57 | 24 |
|
58 | | - echo "Unpacking the downloaded CodeQL bundle archive..." |
59 | | - tar -xzf "$codeql_archive" -C "$codeql_toolcache_path" |
| 25 | +# Touch a file to indicate to the toolcache that setting up CodeQL is complete. |
| 26 | +touch "$codeql_toolcache_path.complete" |
60 | 27 |
|
61 | | - # We only pin the latest version in the toolcache, to support overriding the CodeQL version specified in defaults.json on GitHub Enterprise. |
62 | | - if [[ "$bundle_version" == "$codeql_bundle_version" ]]; then |
63 | | - touch "$codeql_toolcache_path/pinned-version" |
64 | | - fi |
65 | | - |
66 | | - # Touch a file to indicate to the toolcache that setting up CodeQL is complete. |
67 | | - touch "$codeql_toolcache_path.complete" |
68 | | -done |
69 | | - |
70 | | -invoke_tests "Common" "CodeQLBundles" |
| 28 | +invoke_tests "Common" "CodeQL Bundle" |
0 commit comments