nrwl / nx

Smart Monorepos · Fast CI
https://nx.dev
MIT License
23.75k stars 2.37k forks source link

NX_REJECT_UNKNOWN_LOCAL_CACHE fails when upgrading from v19 to v20 #28914

Open ethanr-bjss opened 1 week ago

ethanr-bjss commented 1 week ago

Current Behavior

We are using GitHub Actions cache as our NX cache, which we require due to organisational constraints. In line with guidance here, we have set NX_REJECT_UNKNOWN_LOCAL_CACHE=0 on all of our jobs.

In version 19.8.x, this works to prevent additional build/lint/test when there has been no change.

Since upgrading to 20.0.x, we are seeing the "Unrecognised cache artifacts" error when trying to load the GitHub cache.

Expected Behavior

NX does not reject the unknown local cache, and uses it to prevent duplicate build/lint/test.

GitHub Repo

https://github.com/ethanr-bjss/nx-local-cache-reproduce

Steps to Reproduce

In the attached repository, I've set up two action runs. The first was run

v19 (see retry for cache usage) - https://github.com/ethanr-bjss/nx-local-cache-reproduce/actions/runs/11814791261 commit - https://github.com/ethanr-bjss/nx-local-cache-reproduce/commit/bb22fc9bc6c9d047658bbaaf63f60bdb088a8ef5

v20 - https://github.com/ethanr-bjss/nx-local-cache-reproduce/actions/runs/11814867370 commit - https://github.com/ethanr-bjss/nx-local-cache-reproduce/commit/50382374d75f17977ae8eaef465cd2c3c7e629be

I suggest cloning this repository, and manually running the action as required.

Nx Report

NX   Report complete - copy this into the issue template
Node           : 20.18.0
OS             : linux-x64
Native Target  : x86_64-linux
pnpm           : 9.7.1
nx          : 20.1.0
typescript  : 5.5.4

Failure Logs

NX   Unrecognized Cache Artifacts
Nx found unrecognized artifacts in the cache directory and will not be able to use them.
Nx can only restore artifacts it has metadata about.
Read about this warning and how to address it here: https://nx.dev/troubleshooting/unknown-local-cache

Package Manager Version

pnpm@9.7.1

Operating System

Additional Information

No response

dustyhorizon commented 1 week ago

FWIW I have the same setup, the following worked for me

...
- name: Restore Nx cache
        id: restore_nx_cache
        uses: actions/cache/restore@v4
        with:
          path: |
            ${{ github.workspace }}/src/.nx
            !${{ github.workspace }}/src/.nx/workspace-data/d
          key: nx-cache
          restore-keys: |
            nx-cache-
...
- name: Save Nx cache
        if: ${{ always() }}
        uses: actions/cache/save@v4
        with:
          path: |
            ${{ github.workspace }}/src/.nx
            !${{ github.workspace }}/src/.nx/workspace-data/d
          key: nx-cache-${{ hashFiles('src/.nx/**', '!src/.nx/workspace-data/d/**') }}
...

and these environment variables set

NX_DISABLE_DB: true
NX_DB_CACHE: false