From 52a535463da03986d089f8204c79c6f4be5e46e6 Mon Sep 17 00:00:00 2001 From: Owen Mansel-Chan Date: Fri, 12 Mar 2021 09:13:49 +0000 Subject: [PATCH] Find latest release of the CLI automatically Also download OS-specific zip files while we're at it. There are two files in `codeql-win64.zip` called `codeql/codeql` and `codeql/codeql.exe`. Because of the order they were put into the zip, they come out in the order `codeql/codeql.exe` followed by `codeql/codeql`, and something on Windows thinks that the second file has the same name as the first. It's because it's trying to emulate linux and running `codeql/codeql` could run either one of them. We need to make sure we definitely have the `.exe` file, so we explicitly extract it again afterwards. This workaround is already used in some other places. The order that the zip file is made in has now been fixed so this shouldn't be a problem for future releases, so this workaround can be removed in future. --- .github/workflows/codeqltest.yml | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/.github/workflows/codeqltest.yml b/.github/workflows/codeqltest.yml index f5b8aa55d36..ab25e15dcab 100644 --- a/.github/workflows/codeqltest.yml +++ b/.github/workflows/codeqltest.yml @@ -20,12 +20,15 @@ jobs: echo "Done" cd $HOME echo "Downloading CodeQL CLI..." - curl https://github.com/github/codeql-cli-binaries/releases/download/v2.4.3/codeql.zip -L -o codeql.zip + LATEST=$(gh release list --repo https://github.com/github/codeql-cli-binaries | cut -f 1 | sort --version-sort | tail -1) + gh release download --repo https://github.com/github/codeql-cli-binaries --pattern codeql-linux64.zip "$LATEST" echo "Done" echo "Unpacking CodeQL CLI..." - unzip -q codeql.zip - rm -f codeql.zip + unzip -q codeql-linux64.zip + rm -f codeql-linux64.zip echo "Done" + env: + GITHUB_TOKEN: ${{ github.token }} - name: Check out code uses: actions/checkout@v2 @@ -69,12 +72,15 @@ jobs: echo "Done" cd $HOME echo "Downloading CodeQL CLI..." - curl https://github.com/github/codeql-cli-binaries/releases/download/v2.4.3/codeql.zip -L -o codeql.zip + LATEST=$(gh release list --repo https://github.com/github/codeql-cli-binaries | cut -f 1 | sort --version-sort | tail -1) + gh release download --repo https://github.com/github/codeql-cli-binaries --pattern codeql-osx64.zip "$LATEST" echo "Done" echo "Unpacking CodeQL CLI..." - unzip -q codeql.zip - rm -f codeql.zip + unzip -q codeql-osx64.zip + rm -f codeql-osx64.zip echo "Done" + env: + GITHUB_TOKEN: ${{ github.token }} - name: Check out code uses: actions/checkout@v2 @@ -102,16 +108,22 @@ jobs: - name: Set up CodeQL CLI run: | echo "Removing old CodeQL Directory..." - rmdir "$HOME\codeql" -Recurse -Force -ErrorAction SilentlyContinue + rm -rf $HOME/codeql echo "Done" cd "$HOME" echo "Downloading CodeQL CLI..." - Invoke-WebRequest -Uri https://github.com/github/codeql-cli-binaries/releases/download/v2.4.3/codeql.zip -OutFile codeql.zip + LATEST=$(gh release list --repo https://github.com/github/codeql-cli-binaries | cut -f 1 | sort --version-sort | tail -1) + gh release download --repo https://github.com/github/codeql-cli-binaries --pattern codeql-win64.zip "$LATEST" echo "Done" echo "Unpacking CodeQL CLI..." - Expand-Archive codeql.zip -DestinationPath $HOME - rm -fo codeql.zip + unzip -q -o codeql-win64.zip + unzip -q -o codeql-win64.zip codeql/codeql.exe + rm -f codeql-win64.zip echo "Done" + env: + GITHUB_TOKEN: ${{ github.token }} + shell: + bash - name: Check out code uses: actions/checkout@v2