diff --git a/.github/actions/calculate-cache-key/action.yml b/.github/actions/calculate-cache-key/action.yml new file mode 100644 index 0000000..f6f11be --- /dev/null +++ b/.github/actions/calculate-cache-key/action.yml @@ -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" diff --git a/.github/actions/lookup-runtime-cache/action.yml b/.github/actions/lookup-runtime-cache/action.yml new file mode 100644 index 0000000..0263d61 --- /dev/null +++ b/.github/actions/lookup-runtime-cache/action.yml @@ -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 diff --git a/.github/actions/restore-runtime-cache/action.yml b/.github/actions/restore-runtime-cache/action.yml new file mode 100644 index 0000000..c822dd4 --- /dev/null +++ b/.github/actions/restore-runtime-cache/action.yml @@ -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 diff --git a/.github/actions/save-runtime-cache/action.yml b/.github/actions/save-runtime-cache/action.yml new file mode 100644 index 0000000..d38ef95 --- /dev/null +++ b/.github/actions/save-runtime-cache/action.yml @@ -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 diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 884e2dd..63e5076 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -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 @@ -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: diff --git a/.github/workflows/runtime-osx-arm64.yml b/.github/workflows/runtime-osx-arm64.yml index c29bcf8..68a21b0 100644 --- a/.github/workflows/runtime-osx-arm64.yml +++ b/.github/workflows/runtime-osx-arm64.yml @@ -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 @@ -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