diff --git a/.github/workflows/cache-minimal.yml b/.github/workflows/cache-minimal.yml new file mode 100644 index 00000000..5fc0332f --- /dev/null +++ b/.github/workflows/cache-minimal.yml @@ -0,0 +1,72 @@ +# 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 data1 + mkdir data2 + touch data1/thedata.txt + touch data2/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: | + data1 + data2 + key: ${{ steps.cache-key.outputs.key }} + lookup-only: true + + - name: Save cache + uses: actions/cache/save@v4 + with: + path: | + data1 + data2 + key: ${{ steps.cache-key.outputs.key }} + + - name: Query cache hit 1 + id: hit1 + uses: actions/cache/restore@v4 + with: + path: | + data1 + data2 + key: ${{ steps.cache-key.outputs.key }} + fail-on-cache-miss: false + lookup-only: true + + # NOTE inverted path order + - name: Query cache hit 2 + id: hit2 + uses: actions/cache/restore@v4 + with: + path: | + data2 + data1 + key: ${{ steps.cache-key.outputs.key }} + fail-on-cache-miss: false + lookup-only: true + + - name: Print both cache hit and miss + run: | + echo "Cache miss? ${{ steps.miss.outputs.cache-hit }}" + echo "Cache hit 1? ${{ steps.hit1.outputs.cache-hit }}" + echo "Cache hit 2? ${{ steps.hit2.outputs.cache-hit }}" diff --git a/.github/workflows/selftest.yml b/.github/workflows/selftest.yml index 9bd1e0de..12e9218f 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..044ae0ae 100644 --- a/.github/workflows/test-cache.yml +++ b/.github/workflows/test-cache.yml @@ -6,13 +6,18 @@ name: Test cache on: pull_request: + # branches: + # - disabled jobs: test-cache: 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: '' diff --git a/action.yml b/action.yml index e645c081..4a2180d4 100644 --- a/action.yml +++ b/action.yml @@ -24,7 +24,7 @@ inputs: outputs: cache_hit: description: Whether a cached installation was reused - value: ${{ steps.cache-alr.outputs.cache-hit }} + value: ${{ steps.cache-output.outputs.cache_hit }} runs: using: "composite" @@ -50,7 +50,7 @@ runs: 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 }}][f]" >> $GITHUB_OUTPUT # The last value in square brackets is to make the key unique for debugging - name: Reuse cached installation @@ -61,21 +61,33 @@ runs: path: | ~/.cache/alire ~/.config/alire - ./alire_install ~/.local/share/alire + ./alire_install ~/AppData/Local/alire - key: ${{steps.cache-key.outputs.key}} # .cache contains msys64 install on Windows # .config contains the toolchain at the default location, besides index config # ./alire_install contains alr itself # ~/AppData and ./local/share/alire is used with Alire 2.0 onwards # Note that '~' is recommended on Windows too: https://github.com/actions/cache + # THESE MUST BE EXACTLY THE SAME IN SAME ORDER IN ALL CACHE-RELATED STEPS + key: ${{steps.cache-key.outputs.key}} - name: Check cache output shell: bash run: | echo Cache hit result: [${{steps.cache-alr.outputs.cache-hit}}] cache-key: ${{steps.cache-key.outputs.key}} + # In case of miss, give an explicit 'false' which actions/cache doesn't provide + - name: Set cache_hit to false if needed + id: cache-output + shell: bash + run: | + if [[ "${{inputs.cache}}" == "true" && "${{steps.cache-alr.outputs.cache-hit}}" == "true" ]]; then + echo "cache_hit=true" >> $GITHUB_OUTPUT + else + echo "cache_hit=false" >> $GITHUB_OUTPUT + fi + # Ascertain if we need to install a toolchain for building from sources - name: Find GNAT shell: bash @@ -181,17 +193,20 @@ runs: ~/.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 + key: ${{ steps.cache-key.outputs.key }} # 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: | + ~/.cache/alire + ~/.config/alire + ~/.local/share/alire + ./alire_install + ~/AppData/Local/alire key: ${{steps.cache-key.outputs.key}} lookup-only: true - fail-on-cache-miss: true + fail-on-cache-miss: false