Skip to content

Commit

Permalink
feat: cache test workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
mosteo committed Oct 13, 2024
1 parent 9b61e79 commit beab168
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 1 deletion.
65 changes: 65 additions & 0 deletions .github/workflows/testcache.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
name: Test cache

on:
pull_request:
workflow_dispatch:

jobs:
test-cache:
strategy:
fail-fast: false
matrix:
os:
- macos-13 # x64
- macos-latest # arm64
- ubuntu-latest
- windows-latest

runs-on: ${{ matrix.os }}

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

# This might hit cache

- name: Check action itself (attempt 1)
id: attempt_1
uses: ./
with:
crates: gprbuild hello
prefix: alire_prefix

# We want to later on test the pristine prefix restored from cache
- name: Clean prefix for next attempt
run: rm -rf alire_prefix

# Next attemp should hit cache given the previous run

- name: Check action itself (attempt 2)
if: steps.attempt_1.outputs.cache_hit != 'true'
id: attempt_2
uses: ./
with:
crates: gprbuild hello
prefix: alire_prefix

- name: Diagnose cache use
shell: bash
run: |
echo "Caching attempt 1: ${{steps.attempt_1.outputs.cache_hit}}"
echo "Caching attempt 2: ${{steps.attempt_2.outputs.cache_hit}}"
# Fail if no cache was hit
- if: (steps.attempt_1.outputs.cache_hit != 'true') && (steps.attempt_2.outputs.cache_hit != 'true')
uses: actions/github-script@v3
with:
script: |
core.setFailed('FAIL: No cache hit observed')
- name: Run check
shell: bash
run: |
which gprbuild && \
gprbuild --version && \
hello | grep "Hello, world!"
18 changes: 17 additions & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ inputs:
required: false
default: true

outputs:
cache_hit:
description: Whether the cache was hit
value: ${{ steps.cache-output.outputs.cache_hit }}

runs:
using: "composite"
steps:
Expand Down Expand Up @@ -86,11 +91,22 @@ runs:
${{inputs.prefix}}
key: ${{steps.cache-key.outputs.key}}

# In case of miss, give an explicit 'false' which actions/cache doesn't provide
- name: Set cache_hit output
id: cache-output
shell: bash
run: |
if [[ "${{inputs.cache}}" == "true" && "${{steps.cache-install.outputs.cache-hit}}" == "true" ]]; then
echo "cache_hit=true" >> $GITHUB_OUTPUT
else
echo "cache_hit=false" >> $GITHUB_OUTPUT
fi
- name: Diagnose cache usage
shell: bash
run: |
echo "alr-install cache requested: ${{inputs.cache}}"
echo "alr-install cache hit: ${{steps.cache-install.outputs.cache-hit}}"
echo "alr-install cache hit: ${{steps.cache-output.outputs.cache_hit}}"
echo "alr-install cache key: ${{steps.cache-key.outputs.key}}"
- name: Run `alr install`
Expand Down

0 comments on commit beab168

Please sign in to comment.