Skip to content

Commit

Permalink
Minimal cache experiment
Browse files Browse the repository at this point in the history
  • Loading branch information
mosteo committed Jun 27, 2024
1 parent 9f17612 commit 84dc93c
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 26 deletions.
51 changes: 51 additions & 0 deletions .github/workflows/cache-minimal.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# Test minimal save/restore of a cache

name: Minimal cache test

on:
push:
branches:
- disabled

jobs:
minimal-cache:
runs-on: ubuntu-latest

steps:
- name: Create fake data
run: |
mkdir mydata
touch mydata/thedata.txt
- name: Create unique key
id: cache-key
run: |
echo "key=cache test $(date -u)" >> $GITHUB_OUTPUT
- name: Verify cache miss
id: miss
uses: actions/cache/restore@v4
with:
path: mydata
key: ${{ steps.cache-key.outputs.key }}
lookup-only: true

- name: Save cache
uses: actions/cache/save@v4
with:
path: mydata
key: ${{ steps.cache-key.outputs.key }}

- name: Query cache hit
id: hit
uses: actions/cache/restore@v4
with:
path: mydata
key: ${{ steps.cache-key.outputs.key }}
fail-on-cache-miss: true
lookup-only: true

- name: Print both cache hit and miss
run: |
echo "Cache miss? ${{ steps.miss.outputs.cache-hit }}"
echo "Cache hit? ${{ steps.hit.outputs.cache-hit }}"
5 changes: 4 additions & 1 deletion .github/workflows/selftest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@

name: Selftest

on: pull_request
on:
pull_request:
branches:
- disabled

jobs:
setup-alire:
Expand Down
17 changes: 10 additions & 7 deletions .github/workflows/test-cache.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,19 @@ jobs:
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
os:
# - macos-latest
- ubuntu-latest
# - windows-latest
config:
- version: '2.0.1'
branch: ''
- version: '1.2.2'
branch: ''
- version: 'nightly'
branch: ''
- version: ''
branch: 'master'
# - version: '1.2.2'
# branch: ''
# - version: 'nightly'
# branch: ''
# - version: ''
# branch: 'master'

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

Expand Down
42 changes: 24 additions & 18 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,24 +46,36 @@ runs:
echo "version=${{ inputs.version }}" >> $GITHUB_OUTPUT
fi
# This is to avoid repeating these paths. Turns out, they're used
# internally by the cache action for a unique hash of the cache, and even
# if we give the same paths but in different order, save/restore misbehave
# (restore misses but save hits). I should report this eventually...
- name: Generate cached paths
id: cached-paths
shell: bash
env:
CACHED_PATHS: |
~/.cache/alire
~/.config/alire
~/.local/share/alire
./alire_install
~/AppData/Local/alire
run:
echo "paths=xxx" >> GITHUB_OUTPUT

- name: Generate cache key
id: cache-key
shell: bash
run: |
echo "key=alr[${{ steps.find-hash.outputs.version }}][${{ inputs.toolchain }}][${{ runner.os }}][${{ steps.find-hash.outputs.hash }}][c]" >> $GITHUB_OUTPUT
echo "key=alr[${{ steps.find-hash.outputs.version }}][${{ inputs.toolchain }}][${{ runner.os }}][${{ steps.find-hash.outputs.hash }}][e]" >> $GITHUB_OUTPUT
# The last value in square brackets is to make the key unique for debugging

- name: Reuse cached installation
if: ${{ inputs.cache == 'true' }}
id: cache-alr
uses: actions/cache/restore@v4
with:
path: |
~/.cache/alire
~/.config/alire
./alire_install
~/.local/share/alire
~/AppData/Local/alire
path: ${{steps.cached-paths.outputs.paths}}
key: ${{steps.cache-key.outputs.key}}
# .cache contains msys64 install on Windows
# .config contains the toolchain at the default location, besides index config
Expand Down Expand Up @@ -175,23 +187,17 @@ runs:
if: ${{ inputs.cache == 'true' && steps.cache-alr.outputs.cache-hit != 'true' }}
uses: actions/cache/save@v4
with:
path: |
~/.cache/alire
~/.config/alire
~/.local/share/alire
./alire_install
~/AppData/Local/alire
key: ${{ steps.cache-alr.outputs.cache-primary-key }}
# Note that '~' is recommended on Windows too:
# https://github.com/actions/cache
path: ${{ env.CACHED_PATHS }}
key: ${{ steps.cache-key.outputs.key }}
# Note that '~' is recommended on Windows too: https://github.com/actions/cache

# Verify cache was saved properly
- name: Cache verify
if: ${{ inputs.cache == 'true' && steps.cache-alr.outputs.cache-hit != 'true' }}
uses: actions/cache/restore@v4
with:
path: unused # Forced to provide it
path: ${{ env.CACHED_PATHS }}
key: ${{steps.cache-key.outputs.key}}
lookup-only: true
fail-on-cache-miss: true
fail-on-cache-miss: true # REMOVE BEFORE MERGE

0 comments on commit 84dc93c

Please sign in to comment.