From a5f435b17bb1b8999a9708760df63205fb3e5bb3 Mon Sep 17 00:00:00 2001 From: Henry Mercer Date: Tue, 16 May 2023 16:05:09 +0100 Subject: [PATCH 1/3] macOS: Simplify CodeQL toolcache version when tagged using semver We are migrating to versioning the CodeQL bundle using semantic versions rather than a date-based version. This lets us simplify how we version these bundles within the toolcache. --- images/macos/provision/core/codeql-bundle.sh | 28 +++++++++++++++++--- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/images/macos/provision/core/codeql-bundle.sh b/images/macos/provision/core/codeql-bundle.sh index 53210a3d9232..5a636933618c 100644 --- a/images/macos/provision/core/codeql-bundle.sh +++ b/images/macos/provision/core/codeql-bundle.sh @@ -1,16 +1,36 @@ #!/bin/bash -e -o pipefail source ~/utils/utils.sh -# Retrieve the name of the CodeQL bundle preferred by the Action (in the format codeql-bundle-YYYYMMDD). +# Retrieve the CLI versions and bundle tags of the latest two CodeQL bundles. base_url="$(curl -sSL https://raw.githubusercontent.com/github/codeql-action/v2/src/defaults.json)" codeql_tag_name="$(echo "$base_url" | jq -r '.bundleVersion')" codeql_cli_version="$(echo "$base_url" | jq -r '.cliVersion')" prior_codeql_tag_name="$(echo "$base_url" | jq -r '.priorBundleVersion')" prior_codeql_cli_version="$(echo "$base_url" | jq -r '.priorCliVersion')" -# Convert the tag names to bundles with a version number (x.y.z-YYYYMMDD). -codeql_bundle_version="${codeql_cli_version}-${codeql_tag_name##*-}" -prior_codeql_bundle_version="${prior_codeql_cli_version}-${prior_codeql_tag_name##*-}" +# Compute the toolcache version number for each bundle. This is either `x.y.z` or `x.y.z-YYYYMMDD`. +if [[ "${codeql_tag_name##*-}" == "v"* ]]; then + # Tag name of the format `codeql-bundle-vx.y.z`, where x.y.z is the CLI version. + # We don't need to include the tag name in the toolcache version number because it's derivable + # from the CLI version. + codeql_bundle_version="$codeql_cli_version" +else + # Tag name of the format `codeql-bundle-YYYYMMDD`. + # We need to include the tag name in the toolcache version number because it can't be derived + # from the CLI version. + codeql_bundle_version="$codeql_cli_version-${codeql_tag_name##*-}" +fi +if [[ "${prior_codeql_tag_name##*-}" == "v"* ]]; then + # Tag name of the format `codeql-bundle-vx.y.z`, where x.y.z is the CLI version. + # We don't need to include the tag name in the toolcache version number because it's derivable + # from the CLI version. + prior_codeql_bundle_version="$prior_codeql_cli_version" +else + # Tag name of the format `codeql-bundle-YYYYMMDD`. + # We need to include the tag name in the toolcache version number because it can't be derived + # from the CLI version. + prior_codeql_bundle_version="$prior_codeql_cli_version-${prior_codeql_tag_name##*-}" +fi # Download and name both CodeQL bundles. codeql_bundle_versions=("${codeql_bundle_version}" "${prior_codeql_bundle_version}") From 483fc63d2b8706e5ebc34e230effe91d22aae504 Mon Sep 17 00:00:00 2001 From: Henry Mercer Date: Fri, 19 May 2023 13:43:39 +0100 Subject: [PATCH 2/3] macOS: Error if unsupported CodeQL bundle tag name --- images/macos/provision/core/codeql-bundle.sh | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/images/macos/provision/core/codeql-bundle.sh b/images/macos/provision/core/codeql-bundle.sh index 5a636933618c..2bd8e0609c7b 100644 --- a/images/macos/provision/core/codeql-bundle.sh +++ b/images/macos/provision/core/codeql-bundle.sh @@ -14,22 +14,30 @@ if [[ "${codeql_tag_name##*-}" == "v"* ]]; then # We don't need to include the tag name in the toolcache version number because it's derivable # from the CLI version. codeql_bundle_version="$codeql_cli_version" -else +elif [[ "${codeql_tag_name##*-}" ~= ^[0-9]+$ ]]; then # Tag name of the format `codeql-bundle-YYYYMMDD`. # We need to include the tag name in the toolcache version number because it can't be derived # from the CLI version. codeql_bundle_version="$codeql_cli_version-${codeql_tag_name##*-}" +else + echo "Unrecognised current CodeQL bundle tag name: $codeql_tag_name." \ + "Could not compute toolcache version number." + exit 1 fi if [[ "${prior_codeql_tag_name##*-}" == "v"* ]]; then # Tag name of the format `codeql-bundle-vx.y.z`, where x.y.z is the CLI version. # We don't need to include the tag name in the toolcache version number because it's derivable # from the CLI version. prior_codeql_bundle_version="$prior_codeql_cli_version" -else +elif [[ "${prior_codeql_tag_name##*-}" ~= ^[0-9]+$ ]]; then # Tag name of the format `codeql-bundle-YYYYMMDD`. # We need to include the tag name in the toolcache version number because it can't be derived # from the CLI version. prior_codeql_bundle_version="$prior_codeql_cli_version-${prior_codeql_tag_name##*-}" +else + echo "Unrecognised prior CodeQL bundle tag name: $prior_codeql_tag_name." \ + "Could not compute toolcache version number." + exit 1 fi # Download and name both CodeQL bundles. From be459df875545be661cb320eefaa5ed7ac6d140a Mon Sep 17 00:00:00 2001 From: Henry Mercer Date: Tue, 23 May 2023 18:34:58 +0100 Subject: [PATCH 3/3] macOS: Fix typos --- images/macos/provision/core/codeql-bundle.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/images/macos/provision/core/codeql-bundle.sh b/images/macos/provision/core/codeql-bundle.sh index 2bd8e0609c7b..dab0f9dc015c 100644 --- a/images/macos/provision/core/codeql-bundle.sh +++ b/images/macos/provision/core/codeql-bundle.sh @@ -14,7 +14,7 @@ if [[ "${codeql_tag_name##*-}" == "v"* ]]; then # We don't need to include the tag name in the toolcache version number because it's derivable # from the CLI version. codeql_bundle_version="$codeql_cli_version" -elif [[ "${codeql_tag_name##*-}" ~= ^[0-9]+$ ]]; then +elif [[ "${codeql_tag_name##*-}" =~ ^[0-9]+$ ]]; then # Tag name of the format `codeql-bundle-YYYYMMDD`. # We need to include the tag name in the toolcache version number because it can't be derived # from the CLI version. @@ -29,7 +29,7 @@ if [[ "${prior_codeql_tag_name##*-}" == "v"* ]]; then # We don't need to include the tag name in the toolcache version number because it's derivable # from the CLI version. prior_codeql_bundle_version="$prior_codeql_cli_version" -elif [[ "${prior_codeql_tag_name##*-}" ~= ^[0-9]+$ ]]; then +elif [[ "${prior_codeql_tag_name##*-}" =~ ^[0-9]+$ ]]; then # Tag name of the format `codeql-bundle-YYYYMMDD`. # We need to include the tag name in the toolcache version number because it can't be derived # from the CLI version.