Skip to content

Commit 3575d92

Browse files
committed
Improve runtime caching
1 parent 085a8c8 commit 3575d92

File tree

5 files changed

+166
-11
lines changed

5 files changed

+166
-11
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# SPDX-FileCopyrightText: 2024 Frans van Dorsselaer
2+
#
3+
# SPDX-License-Identifier: MIT
4+
5+
---
6+
# yaml-language-server: $schema=https://json.schemastore.org/github-action.json
7+
8+
name: 'Calculate cache key'
9+
10+
description: 'Calculate the cache key for the given runtime'
11+
12+
inputs:
13+
runtime:
14+
description: 'Runtime identifier'
15+
required: true
16+
17+
outputs:
18+
key:
19+
description: 'The key value for the runtime cache'
20+
value: ${{ steps.calculate-cache-key.outputs.key }}
21+
22+
runs:
23+
using: composite
24+
25+
steps:
26+
- name: Calculate cache key for ${{ inputs.runtime }}
27+
id: calculate-cache-key
28+
shell: bash
29+
run: |
30+
echo "key=runtime-${{ inputs.runtime }}-${{ hashFiles('.gitmodules', 'libc/libc.c', format('.github/workflows/runtime-{0}.yml', inputs.runtime)) }}" \
31+
>> "$GITHUB_OUTPUT"
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# SPDX-FileCopyrightText: 2024 Frans van Dorsselaer
2+
#
3+
# SPDX-License-Identifier: MIT
4+
5+
---
6+
# yaml-language-server: $schema=https://json.schemastore.org/github-action.json
7+
8+
name: 'Lookup runtime cache'
9+
10+
description: 'Checks if a cache exists for the given runtime'
11+
12+
inputs:
13+
runtime:
14+
description: 'Runtime identifier'
15+
required: true
16+
17+
outputs:
18+
cache-hit:
19+
description: 'Indicates if the cache exists or not'
20+
value: ${{ steps.cache-lookup.outputs.cache-hit }}
21+
22+
runs:
23+
using: composite
24+
25+
steps:
26+
- name: Calculate cache key for ${{ inputs.runtime }}
27+
id: calculate-cache-key
28+
uses: ./.github/actions/calculate-cache-key
29+
with:
30+
runtime: ${{ inputs.runtime }}
31+
32+
- name: Lookup ${{ inputs.runtime }}
33+
id: cache-lookup
34+
uses: actions/cache/restore@v4
35+
with:
36+
key: ${{ steps.calculate-cache-key.outputs.key }}
37+
path: |
38+
Xmss/runtimes/**
39+
enableCrossOsArchive: true
40+
lookup-only: true
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# SPDX-FileCopyrightText: 2024 Frans van Dorsselaer
2+
#
3+
# SPDX-License-Identifier: MIT
4+
5+
---
6+
# yaml-language-server: $schema=https://json.schemastore.org/github-action.json
7+
8+
name: 'Restore runtime'
9+
10+
description: 'Retrieve a previously cached runtime (which must exists)'
11+
12+
inputs:
13+
runtime:
14+
description: 'Runtime identifier'
15+
required: true
16+
17+
runs:
18+
using: composite
19+
20+
steps:
21+
- name: Calculate cache key for ${{ inputs.runtime }}
22+
id: calculate-cache-key
23+
uses: ./.github/actions/calculate-cache-key
24+
with:
25+
runtime: ${{ inputs.runtime }}
26+
27+
- name: Restore runtime for ${{ inputs.runtime }}
28+
id: restore
29+
uses: actions/cache/restore@v4
30+
with:
31+
path: |
32+
Xmss/runtimes/**
33+
key: ${{ steps.calculate-cache-key.outputs.key }}
34+
fail-on-cache-miss: true

.github/workflows/build.yml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,37 @@ jobs:
3535
contents: read
3636
actions: write
3737

38+
lookup-runtime-caches:
39+
runs-on: ubuntu-latest
40+
41+
outputs:
42+
osx-arm64: ${{ steps.lookup-osx-arm64.outputs.cache-hit }}
43+
44+
steps:
45+
- name: Checkout
46+
id: checkout
47+
uses: actions/checkout@v4
48+
49+
- name: Lookup osx-arm64
50+
id: lookup-osx-arm64
51+
uses: ./.github/actions/lookup-runtime-cache
52+
with:
53+
runtime: osx-arm64
54+
55+
runtime-osx-arm64:
56+
needs: lookup-runtime-caches
57+
if: ${{ !needs.lookup-runtime-caches.outputs.osx-arm64 }}
58+
uses: ./.github/workflows/runtime-osx-arm64.yml
59+
permissions:
60+
contents: read
61+
actions: write
62+
3863
build-dotnet:
3964
needs:
4065
- cache-runtimes
66+
- runtime-osx-arm64
67+
68+
if: always()
4169

4270
runs-on: ubuntu-latest
4371

@@ -63,6 +91,11 @@ jobs:
6391
key: runtime-win-x64-${{ hashFiles('.gitmodules', 'libc/libc.c', '.github/workflows/runtime-win-x64.yml') }}
6492
fail-on-cache-miss: true
6593

94+
- name: Restore osx-arm64 runtime
95+
uses: ./.github/actions/restore-runtime
96+
with:
97+
runtime: osx-arm64
98+
6699
- name: Restore browser-wasm artifact
67100
uses: actions/cache/restore@v4
68101
with:

.github/workflows/runtime-osx-arm64.yml

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,19 @@ name: Runtime osx-arm64
1313

1414
on:
1515
workflow_dispatch:
16+
inputs:
17+
ignore_cache:
18+
description: 'Force building of the runtime, even if a cached result already exists.'
19+
type: boolean
20+
required: true
21+
default: true
1622
workflow_call:
23+
inputs:
24+
ignore_cache:
25+
description: 'Force building of the runtime, even if a cached result already exists.'
26+
type: boolean
27+
required: false
28+
default: false
1729

1830
env:
1931
RUNTIME: osx-arm64
@@ -38,7 +50,18 @@ jobs:
3850
echo "value=runtime-${{ env.RUNTIME }}-${{ hashFiles('.gitmodules', 'libc/libc.c', '.github/workflows/runtime-osx-arm64.yml') }}" \
3951
>> "$GITHUB_OUTPUT"
4052
53+
- name: Check existing cache
54+
id: cache-check
55+
uses: actions/cache/restore@v4
56+
with:
57+
path: |
58+
Xmss/runtimes/**
59+
key: ${{ steps.cache-key.outputs.value }}
60+
enableCrossOsArchive: true
61+
lookup-only: true
62+
4163
- name: Configure
64+
if: ${{ inputs.ignore_cache || !steps.cache-check.outputs.cache-hit }}
4265
run: >
4366
cmake
4467
-S xmss-library
@@ -49,36 +72,30 @@ jobs:
4972
-DCMAKE_C_FLAGS="-Wno-error=implicit-int-conversion"
5073
5174
- name: Build
75+
if: ${{ inputs.ignore_cache || !steps.cache-check.outputs.cache-hit }}
5276
run: cmake --build build
5377

5478
- name: Test
79+
if: ${{ inputs.ignore_cache || !steps.cache-check.outputs.cache-hit }}
5580
working-directory: build
5681
run: ctest
5782

5883
- name: Copy artifact
84+
if: ${{ inputs.ignore_cache || !steps.cache-check.outputs.cache-hit }}
5985
run: |
6086
mkdir -p "Xmss/runtimes/${{ env.RUNTIME }}/native"
6187
cp build/src/libxmss.dylib "Xmss/runtimes/${{ env.RUNTIME }}/native/xmss.dylib"
6288
63-
- name: Check existing cache
64-
id: cache-check
65-
uses: actions/cache/restore@v4
66-
with:
67-
path: |
68-
Xmss/runtimes/**
69-
key: ${{ steps.cache-key.outputs.value }}
70-
enableCrossOsArchive: true
71-
lookup-only: true
72-
7389
- name: Delete existing cache
74-
if: ${{ steps.cache-check.outputs.cache-hit }}
90+
if: ${{ inputs.ignore_cache && steps.cache-check.outputs.cache-hit }}
7591
run: |
7692
gh extension install actions/gh-actions-cache
7793
gh actions-cache delete "${{ steps.cache-key.outputs.value }}" --confirm
7894
env:
7995
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
8096

8197
- name: Save cache
98+
if: ${{ inputs.ignore_cache || !steps.cache-check.outputs.cache-hit }}
8299
uses: actions/cache/save@v4
83100
with:
84101
path: |

0 commit comments

Comments
 (0)