Skip to content

Commit b4bbafa

Browse files
committed
Make compile-queries.yml sharded based on language
1 parent cc4926a commit b4bbafa

File tree

1 file changed

+37
-5
lines changed

1 file changed

+37
-5
lines changed

.github/workflows/compile-queries.yml

Lines changed: 37 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,41 @@ permissions:
1717
contents: read
1818

1919
jobs:
20-
compile-queries:
20+
detect-changes:
2121
if: github.repository_owner == 'github'
22+
runs-on: ubuntu-latest
23+
outputs:
24+
languages: ${{ steps.detect.outputs.languages }}
25+
steps:
26+
- uses: actions/checkout@v5
27+
- name: Detect changed languages
28+
id: detect
29+
run: |
30+
if [[ "${{ github.event_name }}" == "pull_request" ]]; then
31+
# For PRs, detect which languages have changes
32+
changed_files=$(gh pr view ${{ github.event.pull_request.number }} --json files --jq '.files.[].path')
33+
languages=()
34+
for lang in actions cpp csharp go java javascript python ql ruby rust swift; do
35+
if echo "$changed_files" | grep -qE "^($lang/|shared/)" ; then
36+
languages+=("$lang")
37+
fi
38+
done
39+
echo "languages=$(jq -c -n '$ARGS.positional' --args "${languages[@]}")" >> $GITHUB_OUTPUT
40+
else
41+
# For pushes to main/rc branches, run all languages
42+
echo 'languages=["actions","cpp","csharp","go","java","javascript","python","ql","ruby","rust","swift"]' >> $GITHUB_OUTPUT
43+
fi
44+
env:
45+
GH_TOKEN: ${{ github.token }}
46+
47+
compile-queries:
48+
needs: detect-changes
49+
if: github.repository_owner == 'github' && needs.detect-changes.outputs.languages != '[]'
2250
runs-on: ubuntu-latest-xl
51+
strategy:
52+
fail-fast: false
53+
matrix:
54+
language: ${{ fromJson(needs.detect-changes.outputs.languages) }}
2355

2456
steps:
2557
- uses: actions/checkout@v5
@@ -31,16 +63,16 @@ jobs:
3163
id: query-cache
3264
uses: ./.github/actions/cache-query-compilation
3365
with:
34-
key: all-queries
66+
key: ${{ matrix.language }}-queries
3567
- name: check formatting
36-
run: find shared */ql -type f \( -name "*.qll" -o -name "*.ql" \) -print0 | xargs -0 -n 3000 -P 10 codeql query format -q --check-only
68+
run: find shared ${{ matrix.language }}/ql -type f \( -name "*.qll" -o -name "*.ql" \) -print0 | xargs -0 -n 3000 -P 10 codeql query format -q --check-only
3769
- name: compile queries - check-only
3870
# run with --check-only if running in a PR (github.sha != main)
3971
if : ${{ github.event_name == 'pull_request' }}
4072
shell: bash
41-
run: codeql query compile -q -j0 */ql/{src,examples} --keep-going --warnings=error --check-only --compilation-cache "${{ steps.query-cache.outputs.cache-dir }}" --compilation-cache-size=500 --ram=56000
73+
run: codeql query compile -q -j0 ${{ matrix.language }}/ql/{src,examples} --keep-going --warnings=error --check-only --compilation-cache "${{ steps.query-cache.outputs.cache-dir }}" --compilation-cache-size=500 --ram=56000
4274
- name: compile queries - full
4375
# do full compile if running on main - this populates the cache
4476
if : ${{ github.event_name != 'pull_request' }}
4577
shell: bash
46-
run: codeql query compile -q -j0 */ql/{src,examples} --keep-going --warnings=error --compilation-cache "${{ steps.query-cache.outputs.cache-dir }}" --compilation-cache-size=500 --ram=56000
78+
run: codeql query compile -q -j0 ${{ matrix.language }}/ql/{src,examples} --keep-going --warnings=error --compilation-cache "${{ steps.query-cache.outputs.cache-dir }}" --compilation-cache-size=500 --ram=56000

0 commit comments

Comments
 (0)