Skip to content

Commit

Permalink
Merge pull request #122 from dorssel/refactor_caching
Browse files Browse the repository at this point in the history
Refactor runtime caching
  • Loading branch information
dorssel authored Dec 30, 2024
2 parents 42bf7ee + df357d6 commit 07642c0
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 223 deletions.
42 changes: 0 additions & 42 deletions .github/workflows/build-runtime.yml

This file was deleted.

64 changes: 38 additions & 26 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,31 +21,26 @@ permissions:
actions: write

jobs:
cache-runtimes:
strategy:
matrix:
runtime:
- linux-x64
- browser-wasm
uses: ./.github/workflows/cache-runtime.yml
with:
runtime: ${{ matrix.runtime }}
permissions:
contents: read
actions: write

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

outputs:
linux-x64: ${{ steps.lookup-linux-x64.outputs.cache-hit }}
win-x64: ${{ steps.lookup-win-x64.outputs.cache-hit }}
osx-arm64: ${{ steps.lookup-osx-arm64.outputs.cache-hit }}
browser-wasm: ${{ steps.lookup-browser-wasm.outputs.cache-hit }}

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

- name: Lookup linux-x64
id: lookup-linux-x64
uses: ./.github/actions/lookup-runtime-cache
with:
runtime: linux-x64

- name: Lookup win-x64
id: lookup-win-x64
uses: ./.github/actions/lookup-runtime-cache
Expand All @@ -58,6 +53,20 @@ jobs:
with:
runtime: osx-arm64

- name: Lookup browser-wasm
id: lookup-browser-wasm
uses: ./.github/actions/lookup-runtime-cache
with:
runtime: browser-wasm

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

runtime-win-x64:
needs: lookup-runtime-caches
if: ${{ !needs.lookup-runtime-caches.outputs.win-x64 }}
Expand All @@ -74,11 +83,20 @@ jobs:
contents: read
actions: write

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

build-dotnet:
needs:
- cache-runtimes
- runtime-linux-x64
- runtime-win-x64
- runtime-osx-arm64
- runtime-browser-wasm

if: always()

Expand All @@ -90,13 +108,10 @@ jobs:
with:
fetch-depth: 0

- name: Restore linux-x64 artifact
uses: actions/cache/restore@v4
- name: Restore linux-x64
uses: ./.github/actions/restore-runtime-cache
with:
path: |
Xmss/runtimes/**
key: runtime-linux-x64-${{ hashFiles('.gitmodules', 'libc/libc.c', '.github/workflows/runtime-linux-x64.yml') }}
fail-on-cache-miss: true
runtime: linux-x64

- name: Restore win-x64
uses: ./.github/actions/restore-runtime-cache
Expand All @@ -108,13 +123,10 @@ jobs:
with:
runtime: osx-arm64

- name: Restore browser-wasm artifact
uses: actions/cache/restore@v4
- name: Restore browser-wasm
uses: ./.github/actions/restore-runtime-cache
with:
path: |
Xmss/runtimes/**
key: runtime-browser-wasm-${{ hashFiles('.gitmodules', 'libc/libc.c', '.github/workflows/runtime-browser-wasm.yml') }}
fail-on-cache-miss: true
runtime: browser-wasm

- name: Setup .NET
uses: actions/setup-dotnet@v4
Expand Down
72 changes: 0 additions & 72 deletions .github/workflows/cache-runtime.yml

This file was deleted.

9 changes: 3 additions & 6 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,10 @@ jobs:
# echo "Run, Build Application using script"
# ./location_of_script_within_repo/buildscript.sh

- name: Restore browser-wasm artifact
uses: actions/cache/restore@v4
- name: Restore browser-wasm
uses: ./.github/actions/restore-runtime-cache
with:
path: |
Xmss/runtimes/**
key: runtime-browser-wasm-${{ hashFiles('.gitmodules', 'libc/libc.c', '.github/workflows/runtime-browser-wasm.yml') }}
fail-on-cache-miss: true
runtime: browser-wasm

- name: Setup .NET
uses: actions/setup-dotnet@v4
Expand Down
38 changes: 5 additions & 33 deletions .github/workflows/runtime-browser-wasm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
#
# SPDX-License-Identifier: MIT

# This file requires LF line endings, as it is used in GitHub action hashes.

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

Expand All @@ -23,7 +21,7 @@ permissions:
actions: write

jobs:
build-browser-wasm:
build:
runs-on: ubuntu-latest

steps:
Expand All @@ -32,12 +30,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-browser-wasm.yml') }}" \
>> "$GITHUB_OUTPUT"
- name: Prepare packages
run: |
sudo apt-get update
Expand All @@ -59,28 +51,8 @@ jobs:
mkdir -p "Xmss/runtimes/${{ env.RUNTIME }}/nativeassets"
cp build/src/libxmss.a "Xmss/runtimes/${{ env.RUNTIME }}/nativeassets/xmss.a"
- 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: ${{ env.RUNTIME }}
38 changes: 5 additions & 33 deletions .github/workflows/runtime-linux-x64.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
#
# SPDX-License-Identifier: MIT

# This file requires LF line endings, as it is used in GitHub action hashes.

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

Expand All @@ -23,7 +21,7 @@ permissions:
actions: write

jobs:
build-linux-x64:
build:
runs-on: ubuntu-latest

steps:
Expand All @@ -32,12 +30,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-linux-x64.yml') }}" \
>> "$GITHUB_OUTPUT"
- name: Configure
run: >
cmake
Expand All @@ -62,28 +54,8 @@ jobs:
mkdir -p "Xmss/runtimes/${{ env.RUNTIME }}/native"
cp build/src/libxmss.so "Xmss/runtimes/${{ env.RUNTIME }}/native/xmss.so"
- 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: ${{ env.RUNTIME }}
2 changes: 1 addition & 1 deletion Examples/WebAssembly/Properties/launchSettings.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"$schema": "http://json.schemastore.org/launchsettings.json",
"$schema": "https://json.schemastore.org/launchsettings.json",
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
Expand Down
Loading

0 comments on commit 07642c0

Please sign in to comment.