diff --git a/.github/workflows/testcache.yml b/.github/workflows/testcache.yml new file mode 100644 index 0000000..2e75154 --- /dev/null +++ b/.github/workflows/testcache.yml @@ -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!" \ No newline at end of file diff --git a/action.yml b/action.yml index 786879e..243418a 100644 --- a/action.yml +++ b/action.yml @@ -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: @@ -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`