Skip to content

Commit 64cee5e

Browse files
committed
Improve runtime caching
1 parent 085a8c8 commit 64cee5e

File tree

6 files changed

+183
-30
lines changed

6 files changed

+183
-30
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
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+
- id: calculate-cache-key
27+
shell: bash
28+
run: |
29+
echo "key=runtime-${{ inputs.runtime }}-${{ hashFiles('.gitmodules', 'libc/libc.c', format('.github/workflows/runtime-{0}.yml', inputs.runtime)) }}" \
30+
>> "$GITHUB_OUTPUT"
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
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+
key:
19+
description: 'The key value for the runtime cache'
20+
value: ${{ steps.calculate-cache-key.outputs.key }}
21+
cache-hit:
22+
description: 'Indicates if the cache exists or not'
23+
value: ${{ steps.cache-lookup.outputs.cache-hit }}
24+
25+
runs:
26+
using: composite
27+
28+
steps:
29+
- id: calculate-cache-key
30+
uses: ./.github/actions/calculate-cache-key
31+
with:
32+
runtime: ${{ inputs.runtime }}
33+
34+
- id: cache-lookup
35+
uses: actions/cache/restore@v4
36+
with:
37+
key: ${{ steps.calculate-cache-key.outputs.key }}
38+
path: |
39+
Xmss/runtimes/**
40+
enableCrossOsArchive: true
41+
lookup-only: true
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
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 cache'
9+
10+
description: 'Restore 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+
- id: calculate-cache-key
22+
uses: ./.github/actions/calculate-cache-key
23+
with:
24+
runtime: ${{ inputs.runtime }}
25+
26+
- id: restore
27+
uses: actions/cache/restore@v4
28+
with:
29+
path: |
30+
Xmss/runtimes/**
31+
key: ${{ steps.calculate-cache-key.outputs.key }}
32+
fail-on-cache-miss: true
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
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: 'Save runtime cache'
9+
10+
description: 'Save the given runtime cache (which must exist as Xmss/runtimes/**)'
11+
12+
inputs:
13+
runtime:
14+
description: 'Runtime identifier'
15+
required: true
16+
17+
runs:
18+
using: composite
19+
20+
steps:
21+
- id: lookup-runtime-cache
22+
uses: ./.github/actions/lookup-runtime-cache
23+
with:
24+
runtime: ${{ inputs.runtime }}
25+
26+
- id: delete
27+
if: ${{ steps.lookup-runtime-cache.outputs.cache-hit }}
28+
uses: actions/github-script@v7
29+
with:
30+
script: |
31+
github.rest.actions.deleteActionsCacheById({
32+
owner: context.repo.owner,
33+
repo: context.repo.repo,
34+
cache_id: steps.lookup-runtime-cache.outputs.key,
35+
})
36+
37+
- id: save
38+
uses: actions/cache/save@v4
39+
with:
40+
path: |
41+
Xmss/runtimes/**
42+
key: ${{ steps.lookup-runtime-cache.outputs.key }}
43+
enableCrossOsArchive: 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
95+
uses: ./.github/actions/restore-runtime-cache
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: 4 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,6 @@ jobs:
3232
with:
3333
submodules: recursive
3434

35-
- name: Calculate cache key
36-
id: cache-key
37-
run: |
38-
echo "value=runtime-${{ env.RUNTIME }}-${{ hashFiles('.gitmodules', 'libc/libc.c', '.github/workflows/runtime-osx-arm64.yml') }}" \
39-
>> "$GITHUB_OUTPUT"
40-
4135
- name: Configure
4236
run: >
4337
cmake
@@ -60,28 +54,8 @@ jobs:
6054
mkdir -p "Xmss/runtimes/${{ env.RUNTIME }}/native"
6155
cp build/src/libxmss.dylib "Xmss/runtimes/${{ env.RUNTIME }}/native/xmss.dylib"
6256
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-
73-
- name: Delete existing cache
74-
if: ${{ steps.cache-check.outputs.cache-hit }}
75-
run: |
76-
gh extension install actions/gh-actions-cache
77-
gh actions-cache delete "${{ steps.cache-key.outputs.value }}" --confirm
78-
env:
79-
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
80-
81-
- name: Save cache
82-
uses: actions/cache/save@v4
57+
- name: Save runtime cache
58+
id: save-runtime-cache
59+
uses: ./.github/actions/save-runtime-cache
8360
with:
84-
path: |
85-
Xmss/runtimes/**
86-
key: ${{ steps.cache-key.outputs.value }}
87-
enableCrossOsArchive: true
61+
runtime: osx-arm64

0 commit comments

Comments
 (0)