Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NX monorepo missing package manager lockfile #1079

Closed
Lezzio opened this issue Nov 13, 2023 · 2 comments
Closed

NX monorepo missing package manager lockfile #1079

Lezzio opened this issue Nov 13, 2023 · 2 comments
Assignees

Comments

@Lezzio
Copy link

Lezzio commented Nov 13, 2023

Hi,

I'm running a NX monorepo with pnpm as a package manager and I wish to use Cypress cloud with this GitHub action integration to trigger the tests on chosen apps.

I have a folder apps which contains all our web applications, I try to run Cypress as such in a workflow:

on:
  pull_request:
    types: [opened, synchronize, reopened]

name: ⛷ Preview Tests

permissions:
  actions: read
  contents: read
  deployments: write
  id-token: write
  packages: write
  security-events: write
  statuses: read

defaults:
  run:
    shell: bash

jobs:
  test-preview-env:
    name: 💨 Run Smoke Tests
    runs-on: ubuntu-latest
    environment:
      name: test
    env:
      AKAMAI_CLIENT_ID: [YOUR_AKAMAI_CLIENT_ID]
      AKAMAI_OWNER_CLIENT_ID: [YOUR_AKAMAI_OWNER_CLIENT_ID]
      APP_URL: [YOUR_APP_URL]
      PR_NUMBER: ${{ github.event.pull_request.number }}
    steps:
      - name: Configure AWS Credentials
        uses: aws-actions/configure-aws-credentials@v1
        with:
          role-to-assume: ${{ secrets.ARN_GITHUB_TEST }}
          aws-region: us-east-1
      - name: '🌳 Setup job environment variables'
        run: |
          app_id=$(aws amplify list-apps --query "apps[?name=='HCP Portal'].appId" --output text)
          echo "APP_ID=$app_id" >> $GITHUB_ENV
      - name: Extract AKAMAI_FR_ACCESS
        run: |
          sudo apt-get update && sudo apt-get install -y jq
          FR_ACCESS=$(echo "${{ secrets.AKAMAI_SECRETS }}" | base64 --decode | jq -r '.fr.access')
          echo "AKAMAI_FR_ACCESS=$FR_ACCESS" >> $GITHUB_ENV
      - uses: actions/checkout@v4
        with:
          ref: ${{ github.event.pull_request.head.sha }}
          fetch-depth: 0
      - uses: nrwl/nx-set-shas@v3
        with:
          main-branch-name: ${{ github.base_ref }}
      - uses: pnpm/action-setup@v2.2.4
        with:
         version: 8.3.1
      - name: Use Node.js
        uses: actions/setup-node@v3
        with:
          node-version-file: '.nvmrc'
          cache: 'pnpm'
          cache-dependency-path: './pnpm-lock.yaml'
      - name: Configure .npmrc file
        run: echo "//npm.pkg.github.com/:_authToken=${{ secrets.GITHUB_TOKEN }}" >> .npmrc
      - name: Install Dependencies
        run: pnpm install
      - name: Cypress run smoke tests
        uses: cypress-io/github-action@v6
        with:
          install: true
          working-directory: ./apps/campus
          command: pnpm cypress run
          config-file: cypress.config.ts
          spec: cypress/smoke/**/*
          config: baseUrl=[YOUR_BASE_URL]
          wait-on: https://pr-${{ env.PR_NUMBER }}.${{ env.APP_URL }}
          wait-on-timeout: 900
          group: "UI - Chrome"
          browser: chrome
          record: true
          parallel: false # Runs test in parallel using settings above
          env: AKAMAI_OWNER_CLIENT_SECRET=${{ env.AKAMAI_FR_ACCESS }}
        env:
          CYPRESS_RECORD_KEY: ${{ secrets.HCP_PORTAL_CYPRESS_RECORD_KEY }}
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          COMMIT_INFO_MESSAGE: ${{github.event.pull_request.title}}
          COMMIT_INFO_SHA: ${{github.event.pull_request.head.sha}}

However, I am getting the following error:
Error: Action failed. Missing package manager lockfile. Expecting one of package-lock.json (npm), pnpm-lock.yaml (pnpm) or yarn.lock (yarn) in working-directory /home/runner/work/hcpportal-front-web/hcpportal-front-web/apps/campus

Which is expected given the code:
#848

How can we make it work and compatible with monorepos ? The package manager lockfile is only at the root of the monorepo and not in each of its application. Would it be possible to configure the location of the package manager lockfile ?

@MikeMcC399
Copy link
Collaborator

@Lezzio

The package manager lockfile is only at the root of the monorepo and not in each of its application. Would it be possible to configure the location of the package manager lockfile ?

Since the action install parameter is set to true (which is also the default setting), the action looks for a lockfile in the working directory and fails if none is found.

You may be able to use the project parameter instead of the working-directory parameter to point to ./apps/campus. That would work if your directory structure corresponds to the project example on https://github.com/cypress-io/cypress-test-nested-projects (which is unfortunately a legacy version example, but the principle is the same with current versions).

In that case, you would then want to remove the following instructions, because github-action would carry out the installation based on your pnpm-lock.yaml file in the root directory:

      - name: Install Dependencies
        run: pnpm install

Use of

command: pnpm cypress run

is problematic, as described in Custom test command

Caution: using the action parameter command causes multiple other parameters to be ignored including: auto-cancel-after-failures, browser, ci-build-id, command-prefix, component, config, config-file, env, group, headed, parallel, project, publish-summary, quiet, record, spec and tag.

You can probably just delete this line, as the action's default mode is runTests: true.

@Lezzio
Copy link
Author

Lezzio commented Nov 15, 2023

Thank you very much for the detailed answer! It seems to do the job 👍

@Lezzio Lezzio closed this as completed Nov 15, 2023
@MikeMcC399 MikeMcC399 self-assigned this Dec 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants