nrwl / nx-set-shas

:sparkles: A Github Action which sets the base and head SHAs required for `nx affected` commands in CI
https://nx.dev
MIT License
162 stars 76 forks source link

fails when using nektos/act (running locally) #125

Open techieshark opened 1 year ago

techieshark commented 1 year ago

I'm trying to use https://github.com/nektos/act to run the github actions workflow locally, during development.

I'm getting this error though:

[Pull Request CI/main]   🐳  docker exec cmd=[bash --noprofile --norc -e -o pipefail /var/run/act/workflow/3-composite-setSHAs.sh] user= workdir=
| /run/act/actions/nrwl-nx-set-shas@v3/dist/index.js:14919
|     if ((['pull_request', 'pull_request_target'].includes(eventName) && !github.context.payload.pull_request.merged) ||
|                                                                                                              ^
|
| TypeError: Cannot read properties of undefined (reading 'merged')
|     at /run/act/actions/nrwl-nx-set-shas@v3/dist/index.js:14919:110
|     at Generator.next (<anonymous>)
|     at /run/act/actions/nrwl-nx-set-shas@v3/dist/index.js:14889:71
|     at new Promise (<anonymous>)
|     at __webpack_modules__.5468.__awaiter (/run/act/actions/nrwl-nx-set-shas@v3/dist/index.js:14885:12)
|     at /run/act/actions/nrwl-nx-set-shas@v3/dist/index.js:14907:8
|     at 5468 (/run/act/actions/nrwl-nx-set-shas@v3/dist/index.js:14966:4)
|     at __nccwpck_require__ (/run/act/actions/nrwl-nx-set-shas@v3/dist/index.js:15256:43)
|     at /run/act/actions/nrwl-nx-set-shas@v3/dist/index.js:15276:37
|     at Object.<anonymous> (/run/act/actions/nrwl-nx-set-shas@v3/dist/index.js:15279:12)
|
| Node.js v18.18.0

The .github/workflows/file.yaml is like this:

name: Pull Request CI
on:
  pull_request:
    branches:
      develop

jobs:
  main:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
        with:
          fetch-depth: 0

      - name: Install Yarn
        run: yarn --version 2> /dev/null || echo 'yarn was missing so we will install it now' && npm install -g yarn

      # allow the nx command to work when using 'act' to run github action locally for development/testing
      # see https://github.com/nrwl/nx-set-shas/issues/118#issuecomment-1738657287
      - name: Set Directory as Safe
        run: |
          git config --system --add safe.directory "$GITHUB_WORKSPACE"

      - uses: nrwl/nx-set-shas@v3
        with:
          main-branch-name: 'develop'

To run it in the repo, I just do

brew install act
act

and that's where I get the error up top.

According to https://docs.github.com/en/actions/learn-github-actions/contexts#github-context I'm guessing perhaps it would work if the code accessed github.event.merged rather than github.context.payload.pull_request.merged ? It's a bit unclear to me if this is an issue in this repo or perhaps some failing in act, to not mirror the properties in the two different object locations or something. (I'm a bit new to github actions as well, so perhaps I'm missing something else)

meeroslav commented 1 year ago

Thank you @techieshark, for reporting this. I will investigate as soon as possible.

JamesHenry commented 1 year ago

Surely if act is not aligned with GitHub, then this is an issue on the act side? Have you reported it there or discussed it on their gitter?

jantoodre commented 11 months ago

I managed to get it running by doing the following:

  1. Create event file event.json
  2. Provide the pull_request event payload:
    act pull_request -W .github/workflows/file.yaml --eventpath event.json

I'm using act v0.2.54 and nrwl/nx-set-shas@v4

mandarini commented 6 months ago

Do we think that this is a bug with nx-set-shas, or something that can be configured and possibly on the arc side? @jantoodre @techieshark