diff --git a/.github/actions/cache-query-compilation/action.yml b/.github/actions/cache-query-compilation/action.yml index e39216c9b7afb..44ec4dd7f340f 100644 --- a/.github/actions/cache-query-compilation/action.yml +++ b/.github/actions/cache-query-compilation/action.yml @@ -14,11 +14,45 @@ outputs: runs: using: composite steps: - - name: Cache the query compilation caches - uses: ./.github/actions/incremental-cache +# FIXME: because of https://github.com/actions/runner/issues/2009, nested composite actions with inputs have their +# post actions broken. So instead of reusing incremental-cache (which would have the nested cache action not able +# to save the cache in the post-action phase), we are just copy-pasting the steps here +# - name: Cache the query compilation caches +# uses: ./.github/actions/incremental-cache +# with: +# path: '**/.cache' +# key: codeql-compile-${{ inputs.key }} +# start of copy-paste from ./.github/actions/incremental-cache (replacing inputs.path with '**/.cache') + # calculate the merge-base with main, in a way that works both on PRs and pushes to main. + - name: Calculate merge-base + shell: bash + if: ${{ github.event_name == 'pull_request' }} + env: + BASE_BRANCH: ${{ github.base_ref }} + run: | + MERGE_BASE=$(git cat-file commit $GITHUB_SHA | grep '^parent ' | head -1 | cut -f 2 -d " ") + echo "merge_base=$MERGE_BASE" >> $GITHUB_ENV + - name: Restore read-only cache (PR) + if: ${{ github.event_name == 'pull_request' }} + uses: erik-krogh/actions-cache@a88d0603fe5fb5606db9f002dfcadeb32b5f84c6 + with: + path: '**/.cache' + read-only: true + key: ${{ inputs.key }}-pr-${{ github.sha }} + restore-keys: | + ${{ inputs.key }}-${{ github.base_ref }}-${{ env.merge_base }} + ${{ inputs.key }}-${{ github.base_ref }}- + ${{ inputs.key }}-main- + - name: Fill cache (push) + if: ${{ github.event_name != 'pull_request' }} + uses: erik-krogh/actions-cache@a88d0603fe5fb5606db9f002dfcadeb32b5f84c6 with: path: '**/.cache' - key: codeql-compile-${{ inputs.key }} + key: ${{ inputs.key }}-${{ github.ref_name }}-${{ github.sha }} # just fill on main + restore-keys: | # restore the latest cache if the exact cache is unavailable, to speed up compilation. + ${{ inputs.key }}-${{ github.ref_name }}- + ${{ inputs.key }}-main- +# end of copy-paste - name: Fill compilation cache directory id: fill-compilation-dir shell: bash