@@ -14,58 +14,26 @@ jobs:
14
14
15
15
steps :
16
16
- uses : actions/checkout@v3
17
- # calculate the merge-base with main, in a way that works both on PRs and pushes to main.
18
- - name : Calculate merge-base
19
- if : ${{ github.event_name == 'pull_request' }}
20
- env :
21
- BASE_BRANCH : ${{ github.base_ref }}
22
- run : |
23
- MERGE_BASE=$(git cat-file commit $GITHUB_SHA | grep '^parent ' | head -1 | cut -f 2 -d " ")
24
- echo "merge-base=$MERGE_BASE" >> $GITHUB_ENV
25
- - name : Read CodeQL query compilation - PR
26
- if : ${{ github.event_name == 'pull_request' }}
27
- uses : actions/cache@v3
28
- with :
29
- path : ' **/.cache'
30
- key : codeql-compile-pr-${{ github.sha }} # deliberately not using the `compile-compile-main` keys here.
31
- restore-keys : |
32
- codeql-compile-${{ github.base_ref }}-${{ env.merge-base }}
33
- codeql-compile-${{ github.base_ref }}-
34
- codeql-compile-main-
35
- - name : Fill CodeQL query compilation cache - main
36
- if : ${{ github.event_name != 'pull_request' }}
37
- uses : actions/cache@v3
38
- with :
39
- path : ' **/.cache'
40
- key : codeql-compile-${{ github.ref_name }}-${{ github.sha }} # just fill on main
41
- restore-keys : | # restore from another random commit, to speed up compilation.
42
- codeql-compile-${{ github.ref_name }}-
43
- codeql-compile-main-
44
17
- name : Setup CodeQL
45
18
uses : ./.github/actions/fetch-codeql
46
19
with :
47
20
channel : ' release'
21
+ - name : Cache compilation cache
22
+ id : query-cache
23
+ uses : ./.github/actions/cache-query-compilation
24
+ with :
25
+ key : all-queries
48
26
- name : check formatting
49
27
run : find */ql -type f \( -name "*.qll" -o -name "*.ql" \) -print0 | xargs -0 codeql query format --check-only
50
28
- name : compile queries - check-only
51
29
# run with --check-only if running in a PR (github.sha != main)
52
30
if : ${{ github.event_name == 'pull_request' }}
53
31
shell : bash
54
- run : codeql query compile -j0 */ql/{src,examples} --keep-going --warnings=error --check-only
32
+ run : codeql query compile -j0 */ql/{src,examples} --keep-going --warnings=error --check-only --compilation-cache "${{ steps.query-cache.outputs.cache-dir }}"
55
33
- name : compile queries - full
56
34
# do full compile if running on main - this populates the cache
57
35
if : ${{ github.event_name != 'pull_request' }}
58
36
shell : bash
59
- run : |
60
- # Move all the existing cache into another folder, so we only preserve the cache for the current queries.
61
- mkdir -p ${COMBINED_CACHE_DIR}
62
- rm -f */ql/{src,examples}/.cache/{lock,size} # -f to avoid errors if the cache is empty.
63
- # copy the contents of the .cache folders into the combined cache folder.
64
- cp -r */ql/{src,examples}/.cache/* ${COMBINED_CACHE_DIR}/ || : # ignore missing files
65
- # clean up the .cache folders
66
- rm -rf */ql/{src,examples}/.cache/*
67
-
68
- # compile the queries
69
- codeql query compile -j0 */ql/{src,examples} --keep-going --warnings=error --compilation-cache ${COMBINED_CACHE_DIR}
37
+ run : codeql query compile -j0 */ql/{src,examples} --keep-going --warnings=error --compilation-cache "${{ steps.query-cache.outputs.cache-dir }}"
70
38
env :
71
39
COMBINED_CACHE_DIR : ${{ github.workspace }}/compilation-dir
0 commit comments