Skip to content

Cache never hits between 2 tags even when the key is the same #344

@felixmosh

Description

@felixmosh

I'm trying to apply 2 type of caches,

  1. cache for yarn on my build step.
  2. cache for my 3 next apps

The project is uses yarn workspaces which has 3 projects under /packages/renderers/
My build is triggered by tag creation.

name: Build & Deploy
on:
  push:
    tags:
      - 'v1.*'
jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - uses: actions/setup-node@v1
        with:
          node-version: 12.x

      - name: Get yarn cache directory path
        id: yarn-cache-dir-path
        run: echo "::set-output name=dir::$(yarn cache dir)"

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

      - uses: actions/cache@v2
        with:
          path: |
            ${{ github.workspace }}/packages/renderers/*/.next/cache

          key: ${{ runner.os }}-nextjs-${{ hashFiles('yarn.lock') }}

      - name: Install Packages
        run: yarn install --frozen-lockfile
        env:
          CI: true

      - name: Build artifacts
        run: yarn build
        env:
          CI: true

image
image

I've tried to debug, found out that the recommended doc config for yarn cache which uses hashFiles('**/yarn.lock') is wrong cause it picks yarn.lock files from node_module (as part of the key) at the end of the build, but tries to restore with empty node_modules which produced different hash.
I've changed this and now the restore key is the same but it still claims that cache not found.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions