Skip to content

Commit d165c49

Browse files
committed
CI: add workaround for nested composite actions issue
Because of actions/runner#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.
1 parent 22eb619 commit d165c49

File tree

3 files changed

+63
-60
lines changed

3 files changed

+63
-60
lines changed

.github/actions/cache-query-compilation/action.yml

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,35 @@ outputs:
1414
runs:
1515
using: composite
1616
steps:
17-
- name: Cache the query compilation caches
18-
uses: ./.github/actions/incremental-cache
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+
shell: bash
20+
if: ${{ github.event_name == 'pull_request' }}
21+
env:
22+
BASE_BRANCH: ${{ github.base_ref }}
23+
run: |
24+
MERGE_BASE=$(git cat-file commit $GITHUB_SHA | grep '^parent ' | head -1 | cut -f 2 -d " ")
25+
echo "merge_base=$MERGE_BASE" >> $GITHUB_ENV
26+
- name: Restore read-only cache (PR)
27+
if: ${{ github.event_name == 'pull_request' }}
28+
uses: erik-krogh/actions-cache@a88d0603fe5fb5606db9f002dfcadeb32b5f84c6
29+
with:
30+
path: '**/.cache'
31+
read-only: true
32+
key: ${{ inputs.key }}-pr-${{ github.sha }}
33+
restore-keys: |
34+
${{ inputs.key }}-${{ github.base_ref }}-${{ env.merge_base }}
35+
${{ inputs.key }}-${{ github.base_ref }}-
36+
${{ inputs.key }}-main-
37+
- name: Fill cache (push)
38+
if: ${{ github.event_name != 'pull_request' }}
39+
uses: erik-krogh/actions-cache@a88d0603fe5fb5606db9f002dfcadeb32b5f84c6
1940
with:
2041
path: '**/.cache'
21-
key: codeql-compile-${{ inputs.key }}
42+
key: ${{ inputs.key }}-${{ github.ref_name }}-${{ github.sha }} # just fill on main
43+
restore-keys: | # restore the latest cache if the exact cache is unavailable, to speed up compilation.
44+
${{ inputs.key }}-${{ github.ref_name }}-
45+
${{ inputs.key }}-main-
2246
- name: Fill compilation cache directory
2347
id: fill-compilation-dir
2448
shell: bash

.github/actions/incremental-cache/action.yml

Lines changed: 0 additions & 44 deletions
This file was deleted.

swift/actions/build-and-test/action.yml

Lines changed: 36 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,43 @@ runs:
77
- uses: actions/setup-python@v4
88
with:
99
python-version-file: 'swift/.python-version'
10-
- name: Mount bazel cache
11-
uses: ./.github/actions/incremental-cache
10+
# FIXME: this is copy-pasted from .github/actions/cache-query-compilation, but we cannot factor it out to a common
11+
# composite action because of https://github.com/actions/runner/issues/2009 (cache fails to save in the post action
12+
# phase because its inputs were lost in the meantime)
13+
# calculate the merge-base with main, in a way that works both on PRs and pushes to main.
14+
- name: Calculate merge-base
15+
shell: bash
16+
if: ${{ github.event_name == 'pull_request' }}
17+
env:
18+
BASE_BRANCH: ${{ github.base_ref }}
19+
run: |
20+
MERGE_BASE=$(git cat-file commit $GITHUB_SHA | grep '^parent ' | head -1 | cut -f 2 -d " ")
21+
echo "merge_base=$MERGE_BASE" >> $GITHUB_ENV
22+
- name: Restore read-only cache (PR)
23+
if: ${{ github.event_name == 'pull_request' }}
24+
uses: erik-krogh/actions-cache@a88d0603fe5fb5606db9f002dfcadeb32b5f84c6
1225
with:
13-
path: bazel-repository-cache
14-
key: bazel-cache-${{ runner.os }}-${{ runner.arch }}
15-
- name: Mount bazel disk cache
16-
uses: ./.github/actions/incremental-cache
26+
path: 'bazel-cache'
27+
read-only: true
28+
key: bazel-pr-${{ github.sha }}
29+
restore-keys: |
30+
bazel-${{ github.base_ref }}-${{ env.merge_base }}
31+
bazel-${{ github.base_ref }}-
32+
bazel-main-
33+
- name: Fill cache (push)
34+
if: ${{ github.event_name != 'pull_request' }}
35+
uses: erik-krogh/actions-cache@a88d0603fe5fb5606db9f002dfcadeb32b5f84c6
1736
with:
18-
path: bazel-disk-cache
19-
key: bazel-disk-cache-${{ runner.os }}-${{ runner.arch }}
20-
- name: Configure bazel cache
37+
path: 'bazel-cache'
38+
key: bazel-${{ github.ref_name }}-${{ github.sha }} # just fill on main
39+
restore-keys: | # restore the latest cache if the exact cache is unavailable, to speed up compilation.
40+
bazel-${{ github.ref_name }}-
41+
bazel-main-
42+
- name: Configure bazel
2143
shell: bash
2244
run: |
23-
mkdir bazel-repository-cache bazel-disk-cache
24-
echo build --repository_cache=bazel-repository-cache --disk_cache=bazel-disk-cache > local.bazelrc
45+
mkdir -p bazel-cache/{repository,disk}
46+
echo build --repository_cache=bazel-cache/repository --disk_cache=bazel-cache/disk > local.bazelrc
2547
echo test --test_output=errors >> local.bazelrc
2648
- name: Print unextracted entities
2749
shell: bash
@@ -51,5 +73,6 @@ runs:
5173
if: ${{ github.event_name != 'pull_request' }}
5274
shell: bash
5375
run: |
54-
find bazel-repository-cache bazel-disk-cache -atime +0 -type f -delete
55-
du -sh bazel-repository-cache bazel-disk-cache
76+
du -sh bazel-cache/*
77+
find bazel-cache -atime +0 -type f -delete
78+
du -sh bazel-cache/*

0 commit comments

Comments
 (0)