Github actions and NX monorepo fatal: No such ref:

Viewed 21

When I build my NX monorepo project with Github action workflow, I get the following error: fatal: No such ref: <COMMIT_HASH>.

This is my build step:

  build:
    name: Build
    needs: 
      - config
    runs-on: ubuntu-latest
    timeout-minutes: 2

    steps:
      - name: Pull the full git history
        uses: actions/checkout@v3
        with:
          fetch-depth: 0

      - name: Sets the base and head SHAs
        uses: nrwl/nx-set-shas@v3

      - name: Restore node modules from cache
        id: node-modules
        uses: actions/cache@v2
        with:
          path: ./node_modules
          key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}

      - name: Install Node.js
        uses: actions/setup-node@v2
        with:
          node-version: '16'
          check-latest: true

      - run: git fetch

      - name: Install node modules
        if: ${{ steps.node-modules.outputs.cache-hit != 'true' }}
        run: npm ci

      - name: Install SAM
        uses: aws-actions/setup-sam@v1

      - name: Restore repository from cache
        uses: actions/cache@v2
        with:
          path: |
            ./*
            !./node_modules
          key: ${{ github.sha }}-run-${{ needs.config.outputs.run-timestamp }}

      - name: Cache the build directory
        uses: actions/cache@v2
        with:
          path: ./.aws-sam/*
          key: ${{ github.sha }}-build-${{ needs.config.outputs.run-timestamp }}

      - name: Build the Lambda
        shell: bash
        run: npm run affected:build --args='--envType=prod'

The nrwl/nx-set-shas@v3 action injects the base and head automatically to the nx script. The build recognize and prints the base and the head SHAs:

enter image description here

This is my package.json script:

  "scripts": {
    "prepare": "cd ${pwd} && husky install ${pwd}/.husky",
    "lint": "nx lint --verbose",
    "affected:lint": "nx affected --target=lint --verbose",
    "test": "nx test --verbose",
    "affected:test": "nx affected --target=test --verbose",
    "build": "nx build --verbose",
    "affected:build": "nx affected --target=build --verbose",
    "deploy": "nx deploy --verbose",
    "affected:deploy": "nx affected --target=deploy --verbose"
  }

Any ideas?

0 Answers
Related