Skip to content

Commit 3d531e5

Browse files
committed
fix(workflows): pin codeql/* library deps to the CLI-bundle version before upgrade
codeql pack upgrade resolves unconstrained '*' dependencies to the latest-ever-published registry version, completely independent of the CLI version pinned in .codeqlversion. This caused e.g. codeql/go-all to jump to 7.2.0 (registry-latest) instead of 4.2.6 (the version actually shipped with/tested against CLI 2.21.4), and caused 'codeql/namebinding not found in the registry' fatal errors for other languages since registry-latest go-all depends on packages not present at the versions being resolved. Add .github/scripts/pin-codeql-library-versions.sh, which downloads the official CodeQL Bundle (github/codeql-action release codeql-bundle-v<version>) for the target CLI version and rewrites every codeql/<lang>-all / codeql/<lang>-queries dependency across all qlpack.yml files from '*' to that exact bundled version, before codeql pack upgrade runs. Internal githubsecuritylab/* cross-pack dependencies are left untouched (they intentionally track our own latest published versions).
1 parent ebfb97f commit 3d531e5

2 files changed

Lines changed: 105 additions & 8 deletions

File tree

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
#!/usr/bin/env bash
2+
# Pins every `codeql/<name>: '*'` dependency in this repo's qlpack.yml files to
3+
# the exact library version shipped in the official CodeQL Bundle for a given
4+
# CLI release.
5+
#
6+
# Why this exists: `codeql pack upgrade` resolves an unconstrained `'*'`
7+
# dependency to the *latest-ever-published* version in the configured
8+
# registry (GHCR) - completely independent of whatever CodeQL CLI version is
9+
# pinned in `.codeqlversion`. That mismatch can jump `codeql/<lang>-all`
10+
# several major versions ahead of what the pinned CLI actually ships/tests
11+
# against, which can silently break analyses (see CONTRIBUTING.md's
12+
# "Updating the pinned CodeQL CLI/library version" section for a worked
13+
# example). Pinning these `codeql/*` deps to the exact bundle-paired version
14+
# before running `codeql pack upgrade` makes that resolution deterministic
15+
# and keeps every pack's declared library dependency in lockstep with the
16+
# CLI version this repo says it supports.
17+
#
18+
# Usage: pin-codeql-library-versions.sh <cli-version>
19+
# e.g. pin-codeql-library-versions.sh 2.21.4
20+
#
21+
# Requires: gh (authenticated), tar, sed, find. Run from the repo root.
22+
set -euo pipefail
23+
24+
if [[ $# -ne 1 ]]; then
25+
echo "Usage: $0 <cli-version>" >&2
26+
exit 1
27+
fi
28+
29+
VERSION="$1"
30+
BUNDLE_TAG="codeql-bundle-v${VERSION}"
31+
WORKDIR="$(mktemp -d)"
32+
trap 'rm -rf "$WORKDIR"' EXIT
33+
34+
echo "Determining codeql/* library versions bundled with CodeQL CLI ${VERSION}..."
35+
echo "(source of truth: github/codeql-action release '${BUNDLE_TAG}', asset codeql-bundle-linux64.tar.gz)"
36+
37+
if ! gh release download "$BUNDLE_TAG" --repo github/codeql-action \
38+
--pattern "codeql-bundle-linux64.tar.gz" --dir "$WORKDIR" --clobber; then
39+
echo "::error::Could not download the CodeQL Bundle for tag '${BUNDLE_TAG}' from github/codeql-action releases." >&2
40+
echo "Every CLI release published to github/codeql-cli-binaries should have a matching 'codeql-bundle-v<version>' release in github/codeql-action - check that the tag exists." >&2
41+
exit 1
42+
fi
43+
44+
# List every bundled `codeql/<name>` qlpack and its exact version WITHOUT
45+
# extracting any file contents - the bundle is large (~500MB) and we only
46+
# need the directory listing (name + version are encoded in the path).
47+
VERSIONS_FILE="$WORKDIR/versions.txt"
48+
tar tzf "$WORKDIR/codeql-bundle-linux64.tar.gz" \
49+
| grep -E '^codeql/qlpacks/codeql/[^/]+/[^/]+/$' \
50+
| sed -E 's#^codeql/qlpacks/codeql/([^/]+)/([^/]+)/$#\1 \2#' \
51+
| sort -u > "$VERSIONS_FILE"
52+
53+
echo "Discovered $(wc -l < "$VERSIONS_FILE") bundled codeql/* packages for CLI ${VERSION}."
54+
55+
# Every real qlpack.yml in the repo, excluding gitignored local build
56+
# artifacts (.codeql/ pack caches, the /codeql cloned-repo checkout dir).
57+
mapfile -t QLPACK_FILES < <(find . -name qlpack.yml -not -path "*/.codeql/*" -not -path "./codeql/*")
58+
59+
declare -A PINNED_COUNT=()
60+
while read -r pkg ver; do
61+
[[ -z "$pkg" ]] && continue
62+
count=0
63+
for file in "${QLPACK_FILES[@]}"; do
64+
# Only touch lines declaring an unconstrained `codeql/<pkg>: '*'` (or
65+
# unquoted / double-quoted `*`) dependency; any trailing comment is left
66+
# untouched since the substitution only replaces the matched quote-star-quote.
67+
if grep -qE "^[[:space:]]*codeql/${pkg}:[[:space:]]*[\"']?\\*[\"']?[[:space:]]*(#.*)?\$" "$file"; then
68+
sed -i -E "s#^([[:space:]]*codeql/${pkg}:[[:space:]]*)([\"']?)\\*\\2#\\1\\2${ver}\\2#" "$file"
69+
count=$((count + 1))
70+
fi
71+
done
72+
if [[ $count -gt 0 ]]; then
73+
PINNED_COUNT["$pkg@$ver"]=$count
74+
fi
75+
done < "$VERSIONS_FILE"
76+
77+
echo
78+
echo "Pinned codeql/* dependencies:"
79+
for key in "${!PINNED_COUNT[@]}"; do
80+
echo " - ${key} (${PINNED_COUNT[$key]} file(s))"
81+
done | sort
82+
83+
# Surface any remaining unconstrained codeql/* dependency that this script
84+
# did NOT pin (e.g. it isn't one of the standard per-language bundle
85+
# packages) so it doesn't silently keep resolving to registry-latest.
86+
echo
87+
echo "codeql/* dependencies left unpinned (not found in the CodeQL Bundle):"
88+
REMAINING=0
89+
for file in "${QLPACK_FILES[@]}"; do
90+
if grep -qE "^[[:space:]]*codeql/[A-Za-z0-9_.-]+:[[:space:]]*[\"']?\*[\"']?[[:space:]]*(#.*)?\$" "$file"; then
91+
grep -nE "^[[:space:]]*codeql/[A-Za-z0-9_.-]+:[[:space:]]*[\"']?\*[\"']?[[:space:]]*(#.*)?\$" "$file" | sed "s#^# ${file}:#"
92+
REMAINING=1
93+
fi
94+
done
95+
if [[ "$REMAINING" -eq 0 ]]; then
96+
echo " (none)"
97+
fi

‎.github/workflows/update-codeql-version.yml‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,16 +49,11 @@ jobs:
4949
- name: Setup CodeQL
5050
uses: ./.github/actions/install-codeql
5151

52-
- name: DEBUG codeql-action bundle qlpacks
52+
- name: Pin codeql/* library dependencies to the CodeQL Bundle version
5353
env:
5454
GH_TOKEN: ${{ github.token }}
5555
run: |
56-
set -x
57-
BUNDLE_TAG="codeql-bundle-v${{ steps.version.outputs.version }}"
58-
mkdir -p /tmp/bundle
59-
gh release download "$BUNDLE_TAG" --repo github/codeql-action --pattern "codeql-bundle-linux64.tar.gz" --dir /tmp/bundle
60-
echo "--- listing all codeql/qlpacks/codeql/<pkg>/<version>/ dir entries (no extraction) ---"
61-
tar tzf /tmp/bundle/codeql-bundle-linux64.tar.gz | grep -E '^codeql/qlpacks/codeql/[^/]+/[^/]+/$' | sort -u
56+
.github/scripts/pin-codeql-library-versions.sh "${{ steps.version.outputs.version }}"
6257
6358
- name: Upgrade every pack's dependencies
6459
env:
@@ -98,8 +93,13 @@ jobs:
9893
9994
This PR:
10095
- Updates `.codeqlversion` to `${{ steps.version.outputs.version }}`.
96+
- Pins every `codeql/<lang>-all` / `codeql/<lang>-queries` dependency across all
97+
`qlpack.yml` files to the exact version shipped in the official CodeQL Bundle
98+
for this CLI release (see `.github/scripts/pin-codeql-library-versions.sh`) -
99+
this keeps `codeql pack upgrade` from jumping those libraries to
100+
registry-latest instead of the version this CLI actually ships/tests against.
101101
- Runs `codeql pack upgrade <dir>` for every pack directory to refresh its
102-
`codeql-pack.lock.yml` against the new CLI.
102+
`codeql-pack.lock.yml` against the new CLI and pinned library versions.
103103
104104
**This PR does not publish anything by itself** - no pack `version:` field is
105105
bumped here, so `publish.yml`'s version-diff trigger won't fire for it yet.

0 commit comments

Comments
 (0)