Skip to content

Conversation

MartijnHols
Copy link

@MartijnHols MartijnHols commented Nov 29, 2020

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

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
Copy link
Author

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

@MartijnHols MartijnHols closed this Nov 7, 2021
@MartijnHols
Copy link
Author

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
Copy link
Contributor

kotewar commented Dec 7, 2022

Hey all, 👋🏽

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Read only cache?
2 participants