From 84dc93c0c82c9dee9ebbc445d1cc7eed899f1ce7 Mon Sep 17 00:00:00 2001 From: "Alejandro R. Mosteo" Date: Thu, 27 Jun 2024 18:48:18 +0200 Subject: [PATCH] Minimal cache experiment --- .github/workflows/cache-minimal.yml | 51 +++++++++++++++++++++++++++++ .github/workflows/selftest.yml | 5 ++- .github/workflows/test-cache.yml | 17 ++++++---- action.yml | 42 ++++++++++++++---------- 4 files changed, 89 insertions(+), 26 deletions(-) create mode 100644 .github/workflows/cache-minimal.yml diff --git a/.github/workflows/cache-minimal.yml b/.github/workflows/cache-minimal.yml new file mode 100644 index 00000000..db32ba6f --- /dev/null +++ b/.github/workflows/cache-minimal.yml @@ -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 }}" diff --git a/.github/workflows/selftest.yml b/.github/workflows/selftest.yml index 9bd1e0de..92468fe1 100644 --- a/.github/workflows/selftest.yml +++ b/.github/workflows/selftest.yml @@ -4,7 +4,10 @@ name: Selftest -on: pull_request +on: + pull_request: + branches: + - disabled jobs: setup-alire: diff --git a/.github/workflows/test-cache.yml b/.github/workflows/test-cache.yml index dbeab342..85a5ad31 100644 --- a/.github/workflows/test-cache.yml +++ b/.github/workflows/test-cache.yml @@ -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 }} diff --git a/action.yml b/action.yml index e645c081..be1d6e2f 100644 --- a/action.yml +++ b/action.yml @@ -46,11 +46,28 @@ 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 @@ -58,12 +75,7 @@ runs: 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 @@ -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