Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions .github/actions/calculate-cache-key/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# SPDX-FileCopyrightText: 2024 Frans van Dorsselaer
#
# SPDX-License-Identifier: MIT

---
# yaml-language-server: $schema=https://json.schemastore.org/github-action.json

name: 'Calculate cache key'

description: 'Calculate the cache key for the given runtime'

inputs:
runtime:
description: 'Runtime identifier'
required: true

outputs:
key:
description: 'The key value for the runtime cache'
value: ${{ steps.calculate-cache-key.outputs.key }}

runs:
using: composite

steps:
- id: calculate-cache-key
shell: bash
run: |
echo "key=runtime-${{ inputs.runtime }}-${{ hashFiles('.gitmodules', 'libc/libc.c', format('.github/workflows/runtime-{0}.yml', inputs.runtime)) }}" \
>> "$GITHUB_OUTPUT"
41 changes: 41 additions & 0 deletions .github/actions/lookup-runtime-cache/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# SPDX-FileCopyrightText: 2024 Frans van Dorsselaer
#
# SPDX-License-Identifier: MIT

---
# yaml-language-server: $schema=https://json.schemastore.org/github-action.json

name: 'Lookup runtime cache'

description: 'Checks if a cache exists for the given runtime'

inputs:
runtime:
description: 'Runtime identifier'
required: true

outputs:
key:
description: 'The key value for the runtime cache'
value: ${{ steps.calculate-cache-key.outputs.key }}
cache-hit:
description: 'Indicates if the cache exists or not'
value: ${{ steps.cache-lookup.outputs.cache-hit }}

runs:
using: composite

steps:
- id: calculate-cache-key
uses: ./.github/actions/calculate-cache-key
with:
runtime: ${{ inputs.runtime }}

- id: cache-lookup
uses: actions/cache/restore@v4
with:
key: ${{ steps.calculate-cache-key.outputs.key }}
path: |
Xmss/runtimes/**
enableCrossOsArchive: true
lookup-only: true
32 changes: 32 additions & 0 deletions .github/actions/restore-runtime-cache/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# SPDX-FileCopyrightText: 2024 Frans van Dorsselaer
#
# SPDX-License-Identifier: MIT

---
# yaml-language-server: $schema=https://json.schemastore.org/github-action.json

name: 'Restore runtime cache'

description: 'Restore a previously cached runtime (which must exists)'

inputs:
runtime:
description: 'Runtime identifier'
required: true

runs:
using: composite

steps:
- id: calculate-cache-key
uses: ./.github/actions/calculate-cache-key
with:
runtime: ${{ inputs.runtime }}

- id: restore
uses: actions/cache/restore@v4
with:
path: |
Xmss/runtimes/**
key: ${{ steps.calculate-cache-key.outputs.key }}
fail-on-cache-miss: true
43 changes: 43 additions & 0 deletions .github/actions/save-runtime-cache/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# SPDX-FileCopyrightText: 2024 Frans van Dorsselaer
#
# SPDX-License-Identifier: MIT

---
# yaml-language-server: $schema=https://json.schemastore.org/github-action.json

name: 'Save runtime cache'

description: 'Save the given runtime cache (which must exist as Xmss/runtimes/**)'

inputs:
runtime:
description: 'Runtime identifier'
required: true

runs:
using: composite

steps:
- id: lookup-runtime-cache
uses: ./.github/actions/lookup-runtime-cache
with:
runtime: ${{ inputs.runtime }}

- id: delete
if: ${{ steps.lookup-runtime-cache.outputs.cache-hit }}
uses: actions/github-script@v7
with:
script: |
github.rest.actions.deleteActionsCacheById({
owner: context.repo.owner,
repo: context.repo.repo,
cache_id: steps.lookup-runtime-cache.outputs.key,
})

- id: save
uses: actions/cache/save@v4
with:
path: |
Xmss/runtimes/**
key: ${{ steps.lookup-runtime-cache.outputs.key }}
enableCrossOsArchive: true
33 changes: 33 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,37 @@ jobs:
contents: read
actions: write

lookup-runtime-caches:
runs-on: ubuntu-latest

outputs:
osx-arm64: ${{ steps.lookup-osx-arm64.outputs.cache-hit }}

steps:
- name: Checkout
id: checkout
uses: actions/checkout@v4

- name: Lookup osx-arm64
id: lookup-osx-arm64
uses: ./.github/actions/lookup-runtime-cache
with:
runtime: osx-arm64

runtime-osx-arm64:
needs: lookup-runtime-caches
if: ${{ !needs.lookup-runtime-caches.outputs.osx-arm64 }}
uses: ./.github/workflows/runtime-osx-arm64.yml
permissions:
contents: read
actions: write

build-dotnet:
needs:
- cache-runtimes
- runtime-osx-arm64

if: always()

runs-on: ubuntu-latest

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

- name: Restore osx-arm64
uses: ./.github/actions/restore-runtime-cache
with:
runtime: osx-arm64

- name: Restore browser-wasm artifact
uses: actions/cache/restore@v4
with:
Expand Down
34 changes: 4 additions & 30 deletions .github/workflows/runtime-osx-arm64.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,6 @@ jobs:
with:
submodules: recursive

- name: Calculate cache key
id: cache-key
run: |
echo "value=runtime-${{ env.RUNTIME }}-${{ hashFiles('.gitmodules', 'libc/libc.c', '.github/workflows/runtime-osx-arm64.yml') }}" \
>> "$GITHUB_OUTPUT"

- name: Configure
run: >
cmake
Expand All @@ -60,28 +54,8 @@ jobs:
mkdir -p "Xmss/runtimes/${{ env.RUNTIME }}/native"
cp build/src/libxmss.dylib "Xmss/runtimes/${{ env.RUNTIME }}/native/xmss.dylib"

- name: Check existing cache
id: cache-check
uses: actions/cache/restore@v4
with:
path: |
Xmss/runtimes/**
key: ${{ steps.cache-key.outputs.value }}
enableCrossOsArchive: true
lookup-only: true

- name: Delete existing cache
if: ${{ steps.cache-check.outputs.cache-hit }}
run: |
gh extension install actions/gh-actions-cache
gh actions-cache delete "${{ steps.cache-key.outputs.value }}" --confirm
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Save cache
uses: actions/cache/save@v4
- name: Save runtime cache
id: save-runtime-cache
uses: ./.github/actions/save-runtime-cache
with:
path: |
Xmss/runtimes/**
key: ${{ steps.cache-key.outputs.value }}
enableCrossOsArchive: true
runtime: osx-arm64
Loading