cypress-io/github-action

workflow failing with EACCES: permission denied

raviteja83 opened this issue ยท 8 comments

This is the workflow that is run
image

It used to work till evening today. started failing from then. Am I missing something?

This is the error on workflow fail

image

I am encountering the exact same error, started after updating to node 16

Adding this after actions/cache@v2 and before cypress-io/github-action@v2 makes the workflow go through:

      - run: chown -R 1001:1001 /github/home/.cache && echo "pwn dat cache"

Cypress browsers images run as root, so actions/cache@v2 restores cache with a root:root owner, and cypress-io/github-action@v2 dislikes that.

Also running into this issue.. Does not seem to be fixed for me with @realies chown example:

jobs:
  install:
    runs-on: ubuntu-latest
    container: cypress/browsers:node16.5.0-chrome94-ff93
    steps:
      # Checkout the branch.
      - name: Checkout
        uses: actions/checkout@v2

      - name: Reclaim cache directory
        run: chown -R 1001:1001 /github/home/.cache && echo "pwn dat cache"

      # install Cypress, run lint and build
      - name: Cypress install
        uses: cypress-io/github-action@v2  # <----- This is where mine fails, when cypress is installing
        with:
          runTests: false
      - run: yarn cypress info
      - run: node -p 'os.cpus()'
      - run: yarn lint
      - run: yarn build

      # Upload build artifacts
      - name: Save build folder
        uses: actions/upload-artifact@v2
        with:
          name: build
          if-no-files-found: error
          path: build

I ran into this issue using a Cypress browser docker image with Node v16. I fixed the problem by running job as a non-root user according to the instructions in the action readme. (The instructions in the readme tell you to do this to make Firefox work, but the same fix seems to solve this permissions issue.) It looks like the home directory in the Cypress images is owned by user ID 1001, so I configured my job to run with the same ID.

Here is my setup job:

  setup-for-frontend-integration-tests:
    name: Set up for frontend tests
    runs-on: ubuntu-latest
    container:
      image: cypress/browsers:node16.5.0-chrome94-ff93
      options: --user 1001  # โ† THIS IS THE IMPORTANT LINE!
    steps:
      - uses: actions/checkout@v2

      - name: Persist Next.js build cache
        uses: actions/cache@v2
        with:
          path: ${{ github.workspace }}/.next/cache
          # Generate a new cache whenever packages or source files change.
          key: ${{ runner.os }}-nextjs-${{ hashFiles('yarn.lock') }}-${{ hashFiles('**.[jt]s', '**.[jt]sx') }}
          # If source files changed but packages didn't, rebuild from a prior cache.
          restore-keys: |
            ${{ runner.os }}-nextjs-${{ hashFiles('yarn.lock') }}-

      - name: Install and cache Cypress and npm dependencies, and build frontend server
        uses: cypress-io/github-action@v2
        with:
          # Don't run tests; we're only using the install and build steps here
          runTests: false
          build: yarn build

      - name: Save built frontend server
        uses: actions/upload-artifact@v2
        with:
          name: frontend-server
          path: .next
          if-no-files-found: error

Documentation in README.md actually mentions similar issue under Firefox:

In order to run Firefox, you need to use non-root user (Firefox security restriction).
Note: the magical user id 1001 works because it matches permissions settings on the home folder

Even though I'm running Chrome image the permission issue was still happening during the build step and adding options: --user 1001 solved it for me.

Unfortunately the fix doesnt handle creation of directories, for example for storing screenshots and videos of test recordings.

geryit commented

Had the same issue. This fixed it

@geryit

Had the same issue. This fixed it

Thanks for your feedback!

It's no longer necessary to run cypress-io/github-action in a container to get access to the regular browsers if you are using GitHub-hosted runners, since they already have browsers installed. See for instance ubuntu-22.04 browsers.