skip to Main Content

Here’s my workflow file:

name: Build Pipeline
on: push
env:
  NODE_VERSION: 11

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - uses: actions/setup-node@v2
        with:
          node-version: ${{ env.NODE_VERSION }}
      - id: cache-node-modules
        uses: actions/cache@v2
        with:
          path: ${{ github.workspace }}/node_modules
          key: node_modules-${{ hashFiles('package-lock.json') }}
          restore-keys: node_modules
      - uses: actions/cache@v2
        with:
          path: ${{ github.workspace }}/build
          key: build-${{ github.sha }}
          restore-keys: build
      - if: steps.cache-node-modules.outputs.cache-hit != 'true'
        run: npm install
      - run: npm run build -- --incremental
  npm-scripts:
    needs: [build]
    runs-on: ubuntu-latest
    strategy:
      matrix:
        script: ['lint:pipeline', 'lint:exports', 'i18n:pipeline', 'schema:validate']
    steps:
      - uses: actions/checkout@v2
      - uses: actions/setup-node@v2
        with:
          node-version: ${{ env.NODE_VERSION }}
      - id: cache-node-modules
        uses: actions/cache@v2
        with:
          path: ${{ github.workspace }}/node_modules
          key: node_modules-${{ hashFiles('package-lock.json') }}
      - if: steps.cache-node-modules.outputs.cache-hit != 'true'
        run: |
          echo 'Expected to have a cache hit for "node_modules", since this job runs after the "build" job, which caches the latest version of "node_modules". Not having a cache hit means probably there is a bug with the workflow file.'
          exit 1
      - id: cache-build-output
        uses: actions/cache@v2
        with:
          path: ${{ github.workspace }}/build
          key: build-${{ github.sha }}
      - if: steps.cache-build-output.outputs.cache-hit != 'true'
        run: |
          echo 'Expected to have a cache hit for the build output folder, since this job runs after the "build" job, which caches the latest version of the "build" folder. Not having a cache hit means probably there is a bug with the workflow file.'
          exit 1
      - run: npm run ${{ matrix.script }}
  jest-tests:
    needs: [build]
    runs-on: ubuntu-latest
    container: node:11
    services:
      postgres:
        image: postgres
        env:
          POSTGRES_DB: localhost
          POSTGRES_USER: postgres
          POSTGRES_PASSWORD: password
      redis:
        image: redis
    steps:
      - uses: actions/checkout@v2
      - id: cache-node-modules
        uses: actions/cache@v2
        with:
          path: ${{ github.workspace }}/node_modules
          key: node_modules-${{ hashFiles('package-lock.json') }}
      - if: steps.cache-node-modules.outputs.cache-hit != 'true'
        run: |
          echo 'Expected to have a cache hit for "node_modules", since this job runs after the "build" job, which caches the latest version of "node_modules". Not having a cache hit means probably there is a bug with the workflow file.'
          exit 1
      - id: cache-build-output
        uses: actions/cache@v2
        with:
          path: ${{ github.workspace }}/build
          key: build-${{ github.sha }}
      - if: steps.cache-build-output.outputs.cache-hit != 'true'
        run: |
          echo 'Expected to have a cache hit for the build output folder, since this job runs after the "build" job, which caches the latest version of the "build" folder. Not having a cache hit means probably there is a bug with the workflow file.'
          exit 1
      - run: echo

node_modules and build folders are cached in the build job. These caches are able to be restored without a problem in the npm-scripts job. However, they are not able to be restored in the jest-tests job, where it gets a Cache not found for input keys error.

I don’t know how this is possible, since the exact same cache keys are able to be restored without a problem in all of the npm-scripts jobs.

When I remove the:

container: node:11
services:
  postgres:
    image: postgres
    env:
      POSTGRES_DB: localhost
      POSTGRES_USER: postgres
      POSTGRES_PASSWORD: password
  redis:
    image: redis

part (and hence let the job run on ubuntu-latest, instead of a Docker container), the cache is able to be restored again properly. So not sure what’s going on here.

3

Answers


  1. Chosen as BEST ANSWER

    It is a weird bug. The workaround that I found is not running the jest-tests job in a container. That is, running the jest-tests job in a regular, ubuntu-latest machine, and mapping the service container ports like:

    jest-tests:
      needs: [build]
      runs-on: ubuntu-latest
      services:
        postgres:
          image: postgres
          ports:
            - 5432:5432
          env:
            POSTGRES_DB: localhost
            POSTGRES_USER: postgres
            POSTGRES_PASSWORD: password
        redis:
          image: redis
          ports:
            - 6379:6379
    

  2. It seems that the @actions/cache job silently fails if there is no zstd binary available in the PATH in the container that you are running in. This may be the case for your Node container.

    I found this out by setting ACTIONS_STEP_DEBUG to true in the repository secrets. The debug log shows that the action tries to run zstd and can’t, but it is instead reported as a cache miss. Once I figured that out, I found that there is a bug report open for it: https://github.com/actions/cache/issues/580

    Login or Signup to reply.
  3. I’m using a custom image and just by adding zstd package to the image, it made the action/cache to work.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search