8000 Use recent versions of the cli for running the tests · github/gh-codeql@f4192df · GitHub
[go: up one dir, main page]

Skip to content

Commit f4192df

Browse files
committed
Use recent versions of the cli for running the tests
This workflow was failing since it was using an old version of the cli that can't run the latest queries. Instead, always ensure we are running the latest CLI and the two previous instances.
1 parent 8efc4e5 commit f4192df

File tree

2 files changed

+65
-38
lines changed

2 files changed

+65
-38
lines changed

.github/workflows/pr-checks.yml

Lines changed: 64 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -20,30 +20,46 @@ jobs:
2020
uses: actions/checkout@v2
2121

2222
- name: Install extension
23-
shell: bash
2423
run: |
2524
gh extensions install .
2625
27-
- name: Check automatically installs latest
26+
- name: Get recent CLI versions
2827
shell: bash
2928
run: |
30-
LATEST=`gh release list --repo github/codeql-cli-binaries -L 1 | cut -f 3`
29+
THREE_VERSIONS="$(gh release list --repo github/codeql-cli-binaries -L 3 | cut -f 3)"
30+
LATEST="$(echo $THREE_VERSIONS | awk '{print $1}')"
31+
SECOND_LATEST="$(echo $THREE_VERSIONS | awk '{print $2}')"
32+
THIRD_LATEST="$(echo $THREE_VERSIONS | awk '{print $3}')"
33+
34+
# Remove the leading v
35+
LATEST=${LATEST:1}
36+
SECOND_LATEST=${SECOND_LATEST:1}
37+
THIRD_LATEST=${THIRD_LATEST:1}
38+
39+
echo "Using versions $LATEST, $SECOND_LATEST, : $THIRD_LATEST"
3140
41+
8000 echo "LATEST=$LATEST" >> $GITHUB_ENV
42+
echo "SECOND_LATEST=$SECOND_LATEST" >> $GITHUB_ENV
43+
echo "THIRD_LATEST=$THIRD_LATEST" >> $GITHUB_ENV
44+
45+
- name: Check automatically installs latest
46+
shell: bash
47+
run: |
3248
# Note we need to run a command before trying to parse the output below, or the
3349
# messages from the download will end up in the JSON that jq tries to parse
34-
gh codeql version
50+
gh codeql version
3551
3652
INSTALLED=`gh codeql version --format json | jq -r '.version'`
37-
if [[ "v$INSTALLED" != $LATEST ]]; then
38-
echo "::error::Expected latest version of $LATEST to be installed, but found v$INSTALLED"
53+
if [[ "$INSTALLED" != $LATEST ]]; then
54+
echo "::error::Expected latest version of $LATEST to be installed, but found $INSTALLED"
3955
exit 1
4056
fi
4157
4258
- name: Check basic functionality
4359
working-directory: test-resources
4460
shell: bash
4561
run: |
46-
gh codeql set-version 2.6.1
62+
gh codeql set-version "$LATEST"
4763
gh codeql database create -l cpp -s test-repo -c "gcc -o main main.c" test-db
4864
gh codeql pack install test-pack
4965
gh codeql database analyze --format=sarif-latest --output=out.sarif test-db test-pack/allExpressions.ql
@@ -57,17 +73,17 @@ jobs:
5773
shell: bash
5874
run: |
5975
# Set the version without a v prefix
60-
gh codeql set-version 2.5.9
76+
gh codeql set-version "$SECOND_LATEST"
6177
VERSION=`gh codeql version --format json | jq -r '.version'`
62-
if [[ $VERSION != "2.5.9" ]]; then
63-
echo "::error::Expected version 2.5.9 but got $VERSION"
78+
if [[ $VERSION != "$SECOND_LATEST" ]]; then
79+
echo "::error::Expected version $SECOND_LATEST but got $VERSION"
6480
exit 1
6581
fi
66-
gh codeql list-installed | grep v2.5.9
82+
gh codeql list-installed | grep v$SECOND_LATEST
6783
6884
# Set the version with a v prefix
6985
COUNT_BEFORE=`gh codeql list-installed | wc -l`
70-
gh codeql set-version v2.5.9
86+
gh codeql set-version v$SECOND_LATEST
7187
COUNT_AFTER=`gh codeql list-installed | wc -l`
7288
if [[ $COUNT_BEFORE != $COUNT_BEFORE ]]; then
7389
echo "::error::Installing an already installed version changed the number of installed versions from $COUNT_BEFORE to $COUNT_AFTER!"
@@ -79,8 +95,8 @@ jobs:
7995
run: |
8096
gh codeql set-version latest
8197
VERSION=`gh codeql version --format json | jq -r '.version'`
82-
if [[ $VERSION == "2.5.9" ]]; then
83-
echo "::error::Expected latest version but got 2.5.9"
98+
if [[ $VERSION == "$SECOND_LATEST" ]]; then
99+
echo "::error::Expected latest version but got $SECOND_LATEST"
84100
exit 1
85101
fi
86102
@@ -93,10 +109,10 @@ jobs:
93109
# Get the latest installed version
94110
LATEST=`gh codeql version --format json | jq -r '.version'`
95111
# Set a local version
96-
gh codeql set-local-version 2.5.9
112+
gh codeql set-local-version $SECOND_LATEST
97113
VERSION=`gh codeql version --format json | jq -r '.version'`
98-
if [[ $VERSION != "2.5.9" ]]; then
99-
echo "::error::Expected version 2.5.9 but got $VERSION"
114+
if [[ $VERSION != "$SECOND_LATEST" ]]; then
115+
echo "::error::Expected version $SECOND_LATEST but got $VERSION"
100116
exit 1
101117
fi
102118
@@ -124,11 +140,11 @@ jobs:
124140
# Get the latest installed version
125141
LATEST=`gh codeql version --format json | jq -r '.version'`
126142
# Set a local version
127-
gh codeql set-local-version 2.5.9
143+
gh codeql set-local-version $SECOND_LATEST
128144
# Unset the local version
129145
gh codeql unset-local-version
130-
if [[ $VERSION == "2.5.9" ]]; then
131-
echo "::error::Expected $LATEST version but got 2.5.9"
146+
if [[ $VERSION == "$SECOND_LATEST" ]]; then
147+
echo "::error::Expected $LATEST version but got $SECOND_LATEST"
132148
exit 1
133149
fi
134150
# Disable local version support
@@ -143,20 +159,20 @@ jobs:
143159
# Get the latest installed version
144160
LATEST=`gh codeql version --format json | jq -r '.version'`
145161
# Set a local version
146-
gh codeql set-local-version 2.5.9
162+
gh codeql set-local-version $SECOND_LATEST
147163
VERSION=`gh codeql version --format json | jq -r '.version'`
148-
if [[ $VERSION != "2.5.9" ]]; then
149-
echo "::error::Expected version 2.5.9 but got $VERSION"
164+
if [[ $VERSION != "$SECOND_LATEST" ]]; then
165+
echo "::error::Expected version $SECOND_LATEST but got $VERSION"
150166
exit 1
151167
fi
152168
153169
# Modify the pinned version without using the CLI
154-
echo v2.7.6 > .codeql-version
170+
echo v$THIRD_LATEST > .codeql-version
155171
# We run the command twice to prevent cURL output from causing a `jq` parser error.
156172
gh codeql version
157173
VERSION=`gh codeql version --format json | jq -r '.version'`
158-
if [[ $VERSION != "2.7.6" ]]; then
159-
echo "::error::Expected version 2.7.6 but got $VERSION"
174+
if [[ $VERSION != "$THIRD_LATEST" ]]; then
175+
echo "::error::Expected version $THIRD_LATEST but got $VERSION"
160176
exit 1
161177
fi
162178
gh codeql unset-local-version
@@ -168,43 +184,54 @@ jobs:
168184
run: |
169185
gh codeql set-version latest
170186
# Get the latest installed version
171-
LATEST=`gh codeql version --format json | jq -r '.version'`
187+
LATEST_INSTALLED=`gh codeql version --format json | jq -r '.version'`
172188
173189
# Modify the pinned version without using the CLI
174-
echo v2.7.6 > .codeql CEAB -version
190+
echo v$SECOND_LATEST > .codeql-version
175191
# We run the command twice to prevent cURL output from causing a `jq` parser error.
176192
gh codeql version
177193
VERSION=`gh codeql version --format json | jq -r '.version'`
178-
if [[ $VERSION = "2.7.6" ]]; then
179-
echo "::error::Expected version $LATEST but got $VERSION"
194+
if [[ $VERSION = "$SECOND_LATEST" ]]; then
195+
echo "::error::Expected version $LATEST_INSTALLED but got $VERSION"
180196
exit 1
181197
fi
182198
rm .codeql-version
183199
184200
- name: Check getting nightly version
185201
shell: bash
186202
run: |
203+
set -exu
204+
205+
# unfortunately for nightly builds the tag name does not match with the version name
206+
# (as it does for releases). So, we need to download by tag name and then check the version name.
207+
LATEST_NIGHTLY_TAG="$(gh api "repos/dsp-testing/codeql-cli-nightlies/releases" --jq ".[] | select(.draft == false) | .tag_name" | head -1)"
208+
209+
# slightly hacky way of getting the version. Hopefully, we don't change how we format the release body.
210+
LATEST_NIGHTLY_VERSION="$(gh api "repos/dsp-testing/codeql-cli-nightlies/releases" --jq '.[] | select(.draft == false) | .body '| head -n 1 | awk '{print $4}')"
211+
echo "Download nightly version $LATEST_NIGHTLY_VERSION and tag $LATEST_NIGHTLY_TAG"
212+
187213
gh codeql set-channel nightly
188-
gh codeql set-version codeql-bundle-20210831-manual
214+
gh codeql set-version "$LATEST_NIGHTLY_TAG"
189215
VERSION=`gh codeql version --format json | jq -r '.version'`
190-
if [[ $VERSION != "2.6.0+202108311306" ]]; then
191-
echo "::error::Expected version 2.6.0+202108311306 but got $VERSION"
216+
if [[ "v$VERSION" != "$LATEST_NIGHTLY_VERSION" ]]; then
217+
echo "::error::Expected version $LATEST_NIGHTLY_VERSION but got v$VERSION"
192218
exit 1
193219
fi
194220
gh codeql set-channel release
195221
196222
- name: Check version override
197223
shell: bash
198224
run: |
225+
gh codeql set-channel release
199226
gh codeql set-version latest
200227
# We run the command with a version override twice such that first run will download the CodeQL CLI
201228
# and the cURL output doesn't confuse the `jq` parser in the second run.
202229
# This implicit download is to test that we properly support the implicit download of a requested version if it is not present.
203-
GH_CODEQL_VERSION=v2.7.6 gh codeql version
204-
VERSION=`GH_CODEQL_VERSION=v2.7.6 gh codeql version --format json | jq -r '.version'`
230+
GH_CODEQL_VERSION=v$SECOND_LATEST gh codeql version
231+
VERSION=`GH_CODEQL_VERSION=v$SECOND_LATEST gh codeql version --format json | jq -r '.version'`
205232
206-
if [[ $VERSION != "2.7.6" ]]; then
207-
echo "::error::Expected version 2.7.6 but got $VERSION"
233+
if [[ $VERSION != "$SECOND_LATEST" ]]; then
234+
echo "::error::Expected version $SECOND_LATEST but got $VERSION"
208235
exit 1
209236
fi
210237

test-resources/test-pack/qlpack.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
name: test-cpp-querypack
22
version: 0.0.1
33
dependencies:
4-
codeql/cpp-all: "0.0.2"
4+
codeql/cpp-all: "*"

0 commit comments

Comments
 (0)
0