nienbo / cache-buildkite-plugin

Tarball, Rsync & S3 Cache Kit for Buildkite. Supports Linux, macOS and Windows
https://buildkite.com/plugins
MIT License
67 stars 39 forks source link

Can't access cached npm or pnpm from next job/step (step label: 'npm or pnpm work?') #67

Open mannycolon opened 9 months ago

mannycolon commented 9 months ago

image

common:
  - assume-ops-services-platform-role: &assume-ops-services-platform-role
      role-arn: $CI_ROLE_ARN
  - node-cache: &node-cache
      id: node
      backend: s3
      key: "v1-cache-{{ id }}-{{ runner.os }}-{{ checksum 'pnpm-lock.yaml' }}"
      restore-keys:
        - 'v1-cache-{{ id }}-{{ runner.os }}-'
        - 'v1-cache-{{ id }}-'
      # compress: true # Optional. Create tar.gz instead of .tar (Compressed) Defaults to `false`.
      # compress-program: gzip # Optional. Allows for custom compression backends - i.e. pigz. Defaults to `gzip`.
      s3:
        bucket: e2-dev-buildkite-cache
        # save-cache: true # Optional. Saves the cache on temp folder and keep between builds/jobs on the same machine.
      paths:
        - node_modules
        - .npm-cache
        - apps/**/node_modules

steps:
 - group: ':open-pull-request: PR Checks'
    if: build.branch != "main"
    steps:
      - label: ':broom: All the things!'
        key: 'pr-checks'
        plugins:
          - *permissions
          - aws-assume-role-with-web-identity: *assume-ops-services-platform-role
          - nienbo/cache#v2.4.15: *node-cache
        commands:
          - '.buildkite/scripts/slack-message-user.sh'
          - 'apk add --no-cache tar' # Required for cache plugin to work correctly
          - 'apk add --update npm'
          - 'npm install -g pnpm'
          - 'pnpm install  --no-prefer-frozen-lockfile'
          - 'pnpm exec nx affected -t prisma-generate ${NX_AFFECTED_PR_OPTS}'
          - 'pnpm exec nx affected -t lint ${NX_AFFECTED_PR_OPTS}'
          - 'pnpm exec nx affected -t test ${NX_AFFECTED_PR_OPTS}'
          - 'pnpm exec nx affected -t build ${NX_AFFECTED_PR_OPTS}'
          # TODO: Add step to check serverless package build
      - wait: ~
      - label: 'npm or pnpm work?'
        key: 'pr-checks2'
        plugins:
          - *permissions
          - aws-assume-role-with-web-identity: *assume-ops-services-platform-role
          - nienbo/cache#v2.4.15: *node-cache
        commands:
          - 'ls -a'
          - 'apk add --update npm'
          - 'pnpm list'
gencer commented 9 months ago

I'm trying to understand what might goes wrong here by looking your YAML file, however, I'm not sure if the root cause is cache plugin.

For example, what happens when you completely remove cache & restore steps and run pnpm --version (or equivelant) on both steps? It seems bash cannot find the pnpm binary rather than cache/restore issue.