mirror of
https://github.com/github/codeql.git
synced 2026-04-30 03:05:15 +02:00
CI: add workaround for nested composite actions issue
Because of https://github.com/actions/runner/issues/2009 the deeply nested action cache was failing to save the cache in the post run phase. For the moment we just avoid the nesting with a copy-pasted action snippet.
This commit is contained in:
@@ -14,11 +14,35 @@ outputs:
|
||||
runs:
|
||||
using: composite
|
||||
steps:
|
||||
- name: Cache the query compilation caches
|
||||
uses: ./.github/actions/incremental-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'
|
||||
key: codeql-compile-${{ inputs.key }}
|
||||
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: ${{ 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-
|
||||
- name: Fill compilation cache directory
|
||||
id: fill-compilation-dir
|
||||
shell: bash
|
||||
|
||||
44
.github/actions/incremental-cache/action.yml
vendored
44
.github/actions/incremental-cache/action.yml
vendored
@@ -1,44 +0,0 @@
|
||||
name: Setup an incremental cache
|
||||
description: Special cache wrapper to be run on pull requests and pushes, that will try to restore
|
||||
a cache as close as possible to the merge base
|
||||
|
||||
inputs:
|
||||
path:
|
||||
description: 'The path to cache'
|
||||
required: true
|
||||
key:
|
||||
description: 'The cache key to use - should be unique to the workflow'
|
||||
required: true
|
||||
|
||||
runs:
|
||||
using: composite
|
||||
steps:
|
||||
# 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: ${{ inputs.path }}
|
||||
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: ${{ inputs.path }}
|
||||
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-
|
||||
Reference in New Issue
Block a user