actions / setup-node

Set up your GitHub Actions workflow with a specific version of node.js
MIT License
3.85k stars 1.26k forks source link

Yarn cache not found #441

Closed mdgeorge4153 closed 2 years ago

mdgeorge4153 commented 2 years ago

Description: I get repeated misses for the yarn cache: ```Run actions/setup-node@v2 with: node-version: 16.x check-latest: true cache: yarn always-auth: false token: *** Attempt to resolve the latest version from manifest... Resolved as '16.14.0' Found in cache @ /opt/hostedtoolcache/node/16.14.0/x64 /usr/local/bin/yarn --version 1.22.17 /usr/local/bin/yarn cache dir /home/runner/.cache/yarn/v6

yarn cache is not found```

Action version: v2

Platform:

Runner type:

Tools version: node-version: 16.x

Repro steps:
Public repo: https://github.com/Certora/rocket-joe-1/commit/ab70fe2af9afd51447945e0a3fcf6ad7745eff98

Expected behavior: Cache hit

Actual behavior: Cache miss after repeated reruns

mdgeorge4153 commented 2 years ago

This seems to be similar to bug #410 , but I have a public repo.

mdgeorge4153 commented 2 years ago

This also suddenly resolved for me. I think what may have been happening is that the cache gets updated later in the job, and if another job fails it fails fast and doesn't get around to doing the cleanup. I notice that the same issue was happening with setup-python and the pip cache, and resolved itself at the same time.

mdgeorge4153 commented 2 years ago

Actually it has reoccurred; I guess it is nondeterministic

dmitry-shibanov commented 2 years ago

Hello @mdgeorge4153. Thank you for your report. Does the error still reproduce?

marko-zivic-93 commented 2 years ago

Hello @mdgeorge4153 Just a gentle reminder. Could you confirm that you can still reproduce this issue?

marko-zivic-93 commented 2 years ago

I will close this issue. If you experience this issue again, please feel free to leave a comment here or to create a new issue.

just-Bri commented 1 year ago

Preface: I'm on yarn@1.22.19 - can't upgrade to 3 because of snyk :/

I've been seeing this issue since enabling cache: 'yarn' Private repo unfortunately.

I've tried doing a couple small pushes with no package.json or yarn.lock changes to see if those changes were causing the cache not to be found but no luck so far.

damhonglinh commented 1 year ago

I had the same issue and found a way to solve this.

I checked the log in the later job Post Run actions/setup-node@v3 and found that there was a warning /bin/tar: unrecognized option: posix so the cache couldn't be built. It was because I was using alpine Linux image (more explanation here).

So changing to use normal Linux image solved this for me.

wildstyles commented 4 months ago

Seems it caches only after job is succeeded

Знімок екрана 2024-05-03 о 18 13 26

With code below I managed to configure best caching despite workflow fails or not.

name: Check With Full Cache Workflow

on:
  push:
    branches:
      - master
  pull_request:
    branches:
      - master

jobs:
  run-linters:
    name: Run Linters
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v4

      - name: Use Node.js
        uses: actions/setup-node@v4
        with:
          node-version-file: .nvmrc

      - name: Get Yarn Cache Directory Path
        id: yarn-cache-dir-path
        run: echo "dir=$(yarn cache dir)" >> $GITHUB_OUTPUT

      - name: Restore Dependencies Cache
        uses: actions/cache/restore@v3
        id: restore-cache
        with:
          path: |
            node_modules
            ${{ steps.yarn-cache-dir-path.outputs.dir }}
          key: ${{ runner.os }}-${{ hashFiles('yarn.lock') }}
          restore-keys: ${{ runner.os }}-

      - name: Install Dependencies
        run: yarn

      - name: Cache Dependencies
        uses: actions/cache/save@v3
        if: steps.restore-cache.outputs.cache-hit != 'true'
        with:
          path: |
            node_modules
            ${{ steps.yarn-cache-dir-path.outputs.dir }}
          key: ${{ runner.os }}-${{ hashFiles('yarn.lock') }}

      - name: Lint
        run: yarn lint