From 09dcae0f24d4b0ea85b4c9ae637d0f4aa065215f Mon Sep 17 00:00:00 2001 From: Chris Gavin Date: Tue, 8 Sep 2020 10:59:26 +0100 Subject: [PATCH] Install the CodeQL bundle in the toolcache. --- .../linux/scripts/installers/codeql-bundle.sh | 19 ++++++++++++++ .../Installers/Install-CodeQLBundle.ps1 | 26 +++++++++++++++++++ 2 files changed, 45 insertions(+) create mode 100644 images/linux/scripts/installers/codeql-bundle.sh create mode 100644 images/win/scripts/Installers/Install-CodeQLBundle.ps1 diff --git a/images/linux/scripts/installers/codeql-bundle.sh b/images/linux/scripts/installers/codeql-bundle.sh new file mode 100644 index 000000000..37e89abda --- /dev/null +++ b/images/linux/scripts/installers/codeql-bundle.sh @@ -0,0 +1,19 @@ +#!/bin/bash +################################################################################ +## File: codeql-bundle.sh +## Desc: Install the CodeQL CLI Bundle to the toolcache. +################################################################################ + +# Retrieve the name of the CodeQL bundle preferred by the Action (in the format codeql-bundle-YYYYMMDD). +codeql_bundle_name="$(curl -sSL https://raw.githubusercontent.com/github/codeql-action/main/src/defaults.json | jq -r .bundleVersion)" +# Convert the bundle name to a version number (0.0.0-YYYYMMDD). +codeql_bundle_version="0.0.0-${codeql_bundle_name##*-}" + +extraction_directory="$AGENT_TOOLSDIRECTORY/CodeQL/$codeql_bundle_version/x64" +mkdir -p "$extraction_directory" + +>&2 echo "Downloading CodeQL bundle $codeql_bundle_version..." +curl -sSL "https://github.com/github/codeql-action/releases/download/$codeql_bundle_name/codeql-bundle.tar.gz" | tar -xzC "$extraction_directory" + +# Test that the tool has been extracted successfully. +"$AGENT_TOOLSDIRECTORY/CodeQL/$codeql_bundle_version/x64/codeql/codeql" version diff --git a/images/win/scripts/Installers/Install-CodeQLBundle.ps1 b/images/win/scripts/Installers/Install-CodeQLBundle.ps1 new file mode 100644 index 000000000..6f25fa468 --- /dev/null +++ b/images/win/scripts/Installers/Install-CodeQLBundle.ps1 @@ -0,0 +1,26 @@ +################################################################################ +## File: Install-CodeQLBundle.ps1 +## Desc: Install the CodeQL CLI Bundle to the toolcache. +################################################################################ + +Import-Module -Name ImageHelpers + +# Retrieve the name of the CodeQL bundle preferred by the Action (in the format codeql-bundle-YYYYMMDD). +$CodeQLBundleName = (Invoke-WebRequest "https://raw.githubusercontent.com/github/codeql-action/main/src/defaults.json" | ConvertFrom-Json).bundleVersion +# Convert the bundle name to a version number (0.0.0-YYYYMMDD). +$CodeQLBundleVersion = "0.0.0-" + $CodeQLBundleName.split("-")[-1] + +$ExtractionDirectory = "$Env:AGENT_TOOLSDIRECTORY/CodeQL/$CodeQLBundleVersion/x64" +New-Item -Path $ExtractionDirectory -ItemType Directory -Force | Out-Null + +Write-Host "Downloading CodeQL bundle $CodeQLBundleVersion..." +$CodeQLBundlePath = Start-DownloadWithRetry -Url "https://github.com/github/codeql-action/releases/download/$CodeQLBundleName/codeql-bundle.tar.gz" -Name "codeql-bundle.tar.gz" +$DownloadDirectoryPath = (Get-Item $CodeQLBundlePath).Directory.FullName +Extract-7Zip -Path $CodeQLBundlePath -DestinationPath $DownloadDirectoryPath +Remove-Item -Path $CodeQLBundlePath +$UnGzipedCodeQLBundlePath = (Join-Path $DownloadDirectoryPath "codeql-bundle.tar") +Extract-7Zip -Path $UnGzipedCodeQLBundlePath -DestinationPath $ExtractionDirectory +Remove-Item -Path $UnGzipedCodeQLBundlePath + +# Test that the tool has been extracted successfully. +& (Join-Path $ExtractionDirectory "codeql" "codeql.exe") version