Skip to content

Commit 19bbdb9

Browse files
committed
ci: support full validation on workflow_dispatch (no PR context)
The Build CodeQL Packs workflow (ci.yml) previously assumed every run had a PR context (github.event.number). For workflow_dispatch runs this value is empty, which caused two problems: 1. Unquoted script arguments (pr-compile.sh, pr-suites-packs.sh) meant an empty github.event.number was dropped entirely by bash word-splitting, shifting the language argument into position 1 and leaving position 2 unset - crashing immediately under set -u ("unbound variable") before any query compilation happened. 2. Every step was gated on dorny/paths-filter's src output, which is PR-diff-based and not meaningful for a manual "verify everything" run. Fixes: - Quote the PR-number/language args passed to pr-compile.sh and pr-suites-packs.sh so an empty value is passed as an explicit empty string instead of vanishing. - Add || github.event_name == 'workflow_dispatch' to every steps.changes.outputs.src == 'true' step condition (12 occurrences across compile-and-test, extensions, library-sources, and configs jobs) so a manual dispatch always runs every step regardless of path-filter. - Give pr-compile.sh, pr-suites-packs.sh, and pr-configs.sh a "full mode" fallback that activates whenever PR_NUMBER is empty: instead of calling gh pr view / gh pr comment (which require a PR), each script now enumerates the relevant files directly from the filesystem (full --warnings=error compile of the language, find over suites/*.qls, glob over configs/*.yml) and skips any PR-comment logic. This keeps a single dual-mode script per concern instead of forking separate PR/non-PR script files, avoiding future logic drift between the two paths. This lets ci.yml be dispatched manually on any branch (including main) to get a real, full compile-and-test validation without requiring an open pull request - closing the validation gap that let PR #179 get merged on the strength of the wrong CI signal.
1 parent c444769 commit 19bbdb9

4 files changed

Lines changed: 85 additions & 36 deletions

File tree

‎.github/scripts/pr-compile.sh‎

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,24 @@
11
#!/bin/bash
22
set -euo pipefail
33

4-
PR_NUMBER=${1}
4+
PR_NUMBER=${1:-}
55
LANGUAGE=${2}
66
# to stop recompiling all queries if multiple files are modified
77
LIBRARY_SCANNED=false
88

99
echo "[+] Compiling all queries in $LANGUAGE"
1010
codeql query compile --threads=0 --check-only "./$LANGUAGE/"
1111

12+
if [[ -z "$PR_NUMBER" ]]; then
13+
# No PR context (e.g. workflow_dispatch run directly on a branch) - there is no PR
14+
# file list to walk, so do a full strict compile (--warnings=error) of every query
15+
# in the language instead. This is at least as strict as the per-file PR-mode loop below.
16+
echo "[+] No PR number provided - running full strict compile (--warnings=error) for $LANGUAGE"
17+
codeql query compile --threads=0 --check-only --warnings=error "./$LANGUAGE/"
18+
echo "[+] Complete"
19+
exit 0
20+
fi
21+
1222
for file in $(gh pr view "$PR_NUMBER" --json files --jq '.files.[].path'); do
1323
if [[ ! -f "$file" ]]; then
1424
continue
@@ -31,4 +41,4 @@ for file in $(gh pr view "$PR_NUMBER" --json files --jq '.files.[].path'); do
3141
fi
3242
done
3343

34-
echo "[+] Complete"
44+
echo "[+] Complete"

‎.github/scripts/pr-configs.sh‎

Lines changed: 34 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,48 @@
11
#!/bin/bash
22
set -euo pipefail
33

4-
PR_NUMBER=${1}
4+
PR_NUMBER=${1:-}
55

66
codeql_code="/tmp/codeql-test-code"
77
codeql_db="/tmp/codeql-test-database"
88

9-
for file in $(gh pr view $PR_NUMBER --json files --jq '.files.[].path'); do
9+
compile_config() {
10+
local file=$1
11+
echo "[+] Compiling Config :: $file"
12+
13+
if [[ -d "$codeql_db" ]]; then
14+
rm -rf "$codeql_db"
15+
fi
16+
17+
mkdir -p "$codeql_code"
18+
echo "print('Hello, World!')" > "$codeql_code/main.py"
19+
20+
codeql database create \
21+
--source-root=$codeql_code \
22+
--language=python \
23+
--codescanning-config=$file \
24+
"$codeql_db"
25+
}
26+
27+
if [[ -z "$PR_NUMBER" ]]; then
28+
# No PR context (e.g. workflow_dispatch run directly on a branch) - there is no PR
29+
# file list to walk, so validate every config directly from the filesystem instead.
30+
echo "[+] No PR number provided - validating all configs/*.yml"
31+
for file in configs/*.yml; do
32+
[[ -f "$file" ]] || continue
33+
compile_config "$file"
34+
done
35+
echo "[+] Complete"
36+
exit 0
37+
fi
38+
39+
for file in $(gh pr view "$PR_NUMBER" --json files --jq '.files.[].path'); do
1040
if [[ ! -f "$file" ]]; then
1141
continue
1242
fi
1343

1444
# config file
1545
if [[ "$file" == configs/*.yml ]]; then
16-
echo "[+] Compiling Config :: $file"
17-
18-
if [[ -d "$codeql_db" ]]; then
19-
rm -rf "$codeql_db"
20-
fi
21-
22-
mkdir -p "$codeql_code"
23-
echo "print('Hello, World!')" > "$codeql_code/main.py"
24-
25-
codeql database create \
26-
--source-root=$codeql_code \
27-
--language=python \
28-
--codescanning-config=$file \
29-
"$codeql_db"
46+
compile_config "$file"
3047
fi
31-
done
48+
done

‎.github/scripts/pr-suites-packs.sh‎

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,32 @@
11
#!/bin/bash
22
set -euo pipefail
33

4-
PR_NUMBER=${1}
4+
PR_NUMBER=${1:-}
55
LANGUAGE=${2}
66
PACK_COMPILED=false
77

8+
if [[ -z "$PR_NUMBER" ]]; then
9+
# No PR context (e.g. workflow_dispatch run directly on a branch) - there is no PR
10+
# file list to walk, so resolve every suite and (re)build the language's packs
11+
# directly. There is no PR to comment on, so the version-diff-comment logic below
12+
# is intentionally skipped in this mode.
13+
echo "[+] No PR number provided - running full suite/pack validation for $LANGUAGE"
14+
15+
if [[ -d "$LANGUAGE/suites" ]]; then
16+
while IFS= read -r -d '' suite; do
17+
echo "[+] Compiling Suite: $suite"
18+
codeql resolve queries "$suite"
19+
done < <(find "$LANGUAGE/suites" -name '*.qls' -print0)
20+
fi
21+
22+
echo "[+] Compiling Pack: $LANGUAGE"
23+
codeql pack install "$LANGUAGE"
24+
codeql pack create "$LANGUAGE"
25+
26+
echo "[+] Complete"
27+
exit 0
28+
fi
29+
830
for file in $(gh pr view "$PR_NUMBER" --json files --jq '.files.[].path'); do
931
if [[ ! -f "$file" ]]; then
1032
continue
@@ -72,4 +94,4 @@ for file in $(gh pr view "$PR_NUMBER" --json files --jq '.files.[].path'); do
7294
fi
7395
done
7496

75-
echo "[+] Complete"
97+
echo "[+] Complete"

‎.github/workflows/ci.yml‎

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,12 @@ jobs:
3737
- '.github/**'
3838
3939
- name: Setup CodeQL
40-
if: steps.changes.outputs.src == 'true'
40+
if: steps.changes.outputs.src == 'true' || github.event_name == 'workflow_dispatch'
4141
id: install-codeql
4242
uses: ./.github/actions/install-codeql
4343

4444
- name: Install Packs
45-
if: steps.changes.outputs.src == 'true'
45+
if: steps.changes.outputs.src == 'true' || github.event_name == 'workflow_dispatch'
4646
env:
4747
GITHUB_TOKEN: ${{ github.token }}
4848
CODEQL_CLI_VERSION: ${{ steps.install-codeql.outputs.codeql-cli-version }}
@@ -53,14 +53,14 @@ jobs:
5353
codeql pack install "${{ matrix.language }}/test"
5454
5555
- name: Compile Queries
56-
if: steps.changes.outputs.src == 'true'
56+
if: steps.changes.outputs.src == 'true' || github.event_name == 'workflow_dispatch'
5757
env:
5858
GITHUB_TOKEN: ${{ github.token }}
5959
run: |
60-
./.github/scripts/pr-compile.sh ${{ github.event.number }} ${{ matrix.language }}
60+
./.github/scripts/pr-compile.sh "${{ github.event.number }}" "${{ matrix.language }}"
6161
6262
- name: Test Queries
63-
if: steps.changes.outputs.src == 'true'
63+
if: steps.changes.outputs.src == 'true' || github.event_name == 'workflow_dispatch'
6464
env:
6565
RUNNER_TEMP: ${{ runner.temp }}
6666
shell: python
@@ -110,7 +110,7 @@ jobs:
110110
file.close()
111111
112112
- name: Upload test results
113-
if: steps.changes.outputs.src == 'true'
113+
if: steps.changes.outputs.src == 'true' || github.event_name == 'workflow_dispatch'
114114
uses: actions/upload-artifact@v7
115115
with:
116116
name: ${{ matrix.language }}-test-results
@@ -119,11 +119,11 @@ jobs:
119119
if-no-files-found: error
120120

121121
- name: Compile / Check Suites & Packs
122-
if: steps.changes.outputs.src == 'true'
122+
if: steps.changes.outputs.src == 'true' || github.event_name == 'workflow_dispatch'
123123
env:
124124
GITHUB_TOKEN: ${{ github.token }}
125125
run: |
126-
./.github/scripts/pr-suites-packs.sh ${{ github.event.number }} ${{ matrix.language }}
126+
./.github/scripts/pr-suites-packs.sh "${{ github.event.number }}" "${{ matrix.language }}"
127127
128128
validate-test-results:
129129
name: Validate test results
@@ -180,11 +180,11 @@ jobs:
180180
- '${{ matrix.language }}/ext/**'
181181
182182
- name: Setup CodeQL
183-
if: steps.changes.outputs.src == 'true'
183+
if: steps.changes.outputs.src == 'true' || github.event_name == 'workflow_dispatch'
184184
uses: ./.github/actions/install-codeql
185185

186186
- name: Install Packs
187-
if: steps.changes.outputs.src == 'true'
187+
if: steps.changes.outputs.src == 'true' || github.event_name == 'workflow_dispatch'
188188
env:
189189
GITHUB_TOKEN: ${{ github.token }}
190190
run: |
@@ -213,11 +213,11 @@ jobs:
213213
- '${{ matrix.language }}/ext-library-sources/**'
214214
215215
- name: Setup CodeQL
216-
if: steps.changes.outputs.src == 'true'
216+
if: steps.changes.outputs.src == 'true' || github.event_name == 'workflow_dispatch'
217217
uses: ./.github/actions/install-codeql
218218

219219
- name: Install CodeQL
220-
if: steps.changes.outputs.src == 'true'
220+
if: steps.changes.outputs.src == 'true' || github.event_name == 'workflow_dispatch'
221221
env:
222222
GITHUB_TOKEN: ${{ github.token }}
223223
run: |
@@ -242,12 +242,12 @@ jobs:
242242
- 'configs/**'
243243
244244
- name: Setup CodeQL
245-
if: steps.changes.outputs.src == 'true'
245+
if: steps.changes.outputs.src == 'true' || github.event_name == 'workflow_dispatch'
246246
uses: ./.github/actions/install-codeql
247247

248248
- name: "Check Configurations"
249-
if: steps.changes.outputs.src == 'true'
249+
if: steps.changes.outputs.src == 'true' || github.event_name == 'workflow_dispatch'
250250
env:
251251
GITHUB_TOKEN: ${{ github.token }}
252252
run: |
253-
./.github/scripts/pr-configs.sh "${{ github.event.number }}"
253+
./.github/scripts/pr-configs.sh "${{ github.event.number }}"

0 commit comments

Comments
 (0)