Add read-only feature by MartijnHols · Pull Request #474 · actions/cache

@MartijnHols

When read-only is true, the cache is only restored and not saved. This allows for sharing the cache with multiple steps even if these steps may change them. I tried to use inputs.read-only in the post-if since just starting the post-job takes precious seconds, but that always seems to be null.

Available as martijnhols/cache@read-only

Fixes #350, #334 and maybe #210

rcowsill, AaronDewes, roni-frantchi, lbruun, adrienbernede, ovr, dolfinus, quintstoffers, shaungrady, tampakrap, and 7 more reacted with thumbs up emoji ovr, shrink, hurrycaner, poldz123, and Renatopster reacted with heart emoji
When `read-only` is `true`, the cache is only restored and not saved. This allows for sharing the cache with multiple steps even if these steps may change them, and speeds them up regardless.

@MartijnHols

@MartijnHols

Does this PR have a future or is it best closed?

@MartijnHols

Seeing as my PRs to the GitHub repos have been ignored for almost a year, I closed all of them. To clean up my workflows I have decided to work on a fork instead with an (in my eyes) cleaner solution. See the repository for documentation: https://github.com/MartijnHols/actions-cache Here is what sharing cache across jobs would look like:

name: Build app

on: push

jobs:
  install:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v2

    - name: Restore "node_modules" from cache
      id: cache
      uses: martijnhols/actions-cache/restore@main
      with:
        path: node_modules
        key: ${{ runner.os }}-node_modules-${{ hashFiles('yarn.lock', 'patches') }}
        restore-keys: ${{ runner.os }}-node_modules

    - name: Install dependencies
      if: steps.cache.outputs.cache-hit != 'true'
      run: yarn install

    - name: Save "node_modules" to cache
      if: steps.cache.outputs.cache-hit != 'true'
      uses: martijnhols/actions-cache/save@main
      with:
        path: node_modules
        key: ${{ steps.cache.outputs.primary-key }}

  build:
    needs: [install]
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v2

    - name: Restore "node_modules" from cache
      uses: martijnhols/actions-cache/restore@main
      with:
        path: node_modules
        key: ${{ runner.os }}-node_modules-${{ hashFiles('yarn.lock', 'patches') }}
        # Fail when the cache could not be found (this should never happen unless you have a misconfiguration)
        required: true

    - name: Build app
      run: yarn build

@kotewar

Hey all, 👋🏽

We have created a discussion with a proposal that will solve this problem, do let us know your feedback, thanks 😊