Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(ci): Avoid writing to cache in workflows triggered by the merge queue #2341

Merged
merged 19 commits into from
Aug 16, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
38 changes: 38 additions & 0 deletions .github/actions/cache/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: Cache
description: 'A wrapper around `actions/cache` which exposes an additional `read-only` input to conditionally write new cache entries'

inputs:
path:
description: 'A list of files, directories, and wildcard patterns to cache and restore'
required: true
key:
description: 'An explicit key for restoring and saving the cache'
required: true
read-only:
description: 'Do not write cache artifacts in the case of a missed cache'
default: 'false'
required: false

outputs:
cache-hit:
description: 'A boolean value to indicate an exact match was found for the primary key'
value: ${{ steps.cache.outputs.cache-hit || steps.restore.outputs.cache-hit }}

runs:
using: composite
steps:

- id: restore
uses: actions/cache/restore@v3
if: ${{ inputs.read_only }}
with:
path: ${{ inputs.path }}
key: ${{ inputs.key }}

- id: cache
uses: actions/cache@v3
if: ${{ !inputs.read_only }}
with:
path: ${{ inputs.path }}
key: ${{ inputs.key }}
TomAFrench marked this conversation as resolved.
Show resolved Hide resolved

9 changes: 6 additions & 3 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ jobs:
echo "SDKROOT=$(xcrun -sdk macosx$(sw_vers -productVersion) --show-sdk-path)" >> $GITHUB_ENV
echo "MACOSX_DEPLOYMENT_TARGET=$(xcrun -sdk macosx$(sw_vers -productVersion) --show-sdk-platform-version)" >> $GITHUB_ENV

- uses: actions/cache@v3
- uses: ./.github/actions/cache
with:
path: |
~/.cargo/bin/
Expand All @@ -88,6 +88,7 @@ jobs:
~/.cargo/git/db/
target/
key: ${{ matrix.target }}-cargo-${{ hashFiles('**/Cargo.lock') }}
read-only: ${{ github.event_name == 'merge_group' }}

- name: Download artifact
uses: actions/download-artifact@v3
Expand Down Expand Up @@ -161,7 +162,7 @@ jobs:
with:
ref: ${{ inputs.tag || env.GITHUB_REF }}

- uses: actions/cache@v3
- uses: ./.github/actions/cache
with:
path: |
~/.cargo/bin/
Expand All @@ -170,6 +171,7 @@ jobs:
~/.cargo/git/db/
target/
key: ${{ matrix.target }}-cargo-${{ hashFiles('**/Cargo.lock') }}
read-only: ${{ github.event_name == 'merge_group' }}

- name: Download artifact
uses: actions/download-artifact@v3
Expand Down Expand Up @@ -237,7 +239,7 @@ jobs:
with:
ref: ${{ inputs.tag || env.GITHUB_REF }}

- uses: actions/cache@v3
- uses: ./.github/actions/cache
with:
path: |
~/.cargo/bin/
Expand All @@ -246,6 +248,7 @@ jobs:
~/.cargo/git/db/
target/
key: ${{ matrix.target }}-cargo-${{ hashFiles('**/Cargo.lock') }}
read-only: ${{ github.event_name == 'merge_group' }}

- name: Download artifact
uses: actions/download-artifact@v3
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,11 @@ jobs:

- name: Restore nix store cache
id: nix-store-cache
uses: actions/cache@v3
uses: ./.github/actions/cache
with:
path: /tmp/nix-cache
TomAFrench marked this conversation as resolved.
Show resolved Hide resolved
key: ${{ runner.os }}-flake-${{ hashFiles('*.lock') }}
read-only: ${{ github.event_name == 'merge_group' }}

# Based on https://github.com/marigold-dev/deku/blob/b5016f0cf4bf6ac48db9111b70dd7fb49b969dfd/.github/workflows/build.yml#L26
- name: Copy cache into nix store
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/wasm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ jobs:
- name: Checkout Noir repo
uses: actions/checkout@v3

- uses: actions/cache@v3
- uses: ./.github/actions/cache
with:
path: |
~/.cargo/bin/
Expand All @@ -63,6 +63,7 @@ jobs:
~/.cargo/git/db/
target/
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
read-only: ${{ github.event_name == 'merge_group' }}

- name: Download artifact
uses: actions/download-artifact@v3
Expand Down