e-square-io / nx-github-actions

A set of Github Actions for NX workspaces
MIT License
30 stars 6 forks source link

Affected matrix generation fail with: Cannot read properties of undefined (reading 'endsWith') #53

Closed tamascsaba closed 2 years ago

tamascsaba commented 2 years ago

[ ] Regression (a behavior that used to work and stopped working in a new release)
[x] Bug report  
[ ] Performance issue
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request
[ ] Other... Please describe:

Current behavior

Affected matrix generation fail with:

>  NX   Cannot read properties of undefined (reading 'endsWith')
Run nrwl/nx-set-shas@v2
Run node $GITHUB_ACTION_PATH/dist/index.js *** main false push . 

(node:2254) [DEP0005] DeprecationWarning: Buffer() is deprecated due to security and usability issues. Please use the Buffer.alloc(), Buffer.allocUnsafe(), or Buffer.from() methods instead.

(Use `node --trace-deprecation ...` to show where the warning was created)
Run echo "Base SHA"
Base SHA
e152b7b283726560a0f3bfe95c8c32fb4be4fda3

Head SHA
9c0d010a0cc9b9b22b4f66ecad983e8dc1b340fb

Run # Built-in Github action conditionals are not supported in composite steps so have to check manually in bash
NX_BASE and NX_HEAD environment variables have been set for the current Job
Run actions/github-script@v6
🐞 parsed args: {
  "skipNxCache": false
}
⚙️ Generating affected matrix for build
  🐞 Calculating affected for "test" target

   >  NX   Cannot read properties of undefined (reading 'endsWith')

Minimal reproduction of the problem with instructions

I had to add NX_WORKSPACE_ROOT_PATH, because workingDirectory is not working. My configuration looks like:

  setup:
    runs-on: ubuntu-latest
    name: Affected Matrix
    env:
      NX_VERBOSE_LOGGING: true
      NX_WORKSPACE_ROOT_PATH: ${{ github.workspace }}/nx-root/
    outputs:
      hasChanges: ${{ steps.affected.outputs.hasChanges }}
      matrix: ${{ steps.affected.outputs.matrix }}
    steps:
      - name: Calculate affected projects
        uses: e-square-io/nx-affected-matrix@v2
        id: affected
        with:
          debug: true
          targets: 'test,build'
          maxDistribution: 3
          args: ''

I am using nx 14.4.2 with version 2 projects format.

tamascsaba commented 2 years ago

@robinpellegrims and @ronnetzer thank you very much your response in advance 👍

ronnetzer commented 2 years ago

Hi @tamascsaba,

Thank you for reporting the issue,

  1. Please create a repo that reproduces the issue so we'll be able to debug the fix
  2. "I had to add NX_WORKSPACE_ROOT_PATH, because workingDirectory is not working." I didn't understand if it solved the issue? or without NX_WORKSPACE_ROOT_PATH you get a different error?
robinpellegrims commented 2 years ago

I'm having the same issue after converting all projects to use separate project.json files instead of the global workspace.json. Might be related to this library still using nx v13? Can we update the nx packages to v14?

https://nx.dev/configuration/projectjson#workspace-json

tamascsaba commented 2 years ago

Sorry for the late response, but I haven't had time to create an example repository, but maybe I can give you a general description of our project.

  1. We use "version": 2, format with lot of buildable libraries and several apps, the main project file is the angular.json
  2. Without NX_WORKSPACE_ROOT_PATH I got an error about missing nx.json file.
ronnetzer commented 2 years ago

@robinpellegrims Thanks for reporting, I have several projects with the new project.json files format that works just fine with NX 14 so I'm not sure this is the problem. In order to proceed I'll need some minimal reproduction of this issue

@tamascsaba Regarding your 2nd point, do you mind opening it in a separate issue? its unrelated to this one

robinpellegrims commented 2 years ago

I created a minimal reproduction repository here.

It's a fresh nx repository created using npx create-nx-workspace@latest with the angular-nest preset. Afterwards I copied the default e-square-io/nx-affected-matrix workflow configuration from the README.

I hope this helps, let me know if you need anything else.

tamascsaba commented 2 years ago

I opened a separate issue: https://github.com/e-square-io/nx-github-actions/issues/56 as well.

jason-edstrom commented 2 years ago

I am having this exact issue with a react-native monorepo that has 9 apps already in place. I have been trying to understand what I'm missing. What's the process that this action goes through to determine the affected matrix?

jason-edstrom commented 2 years ago

@robinpellegrims @ronnetzer Repro-Repo here: https://github.com/jason-edstrom/nx-affected-bug-repo

ronnetzer commented 2 years ago

Apparently this is something in NX, https://github.com/nrwl/nx/issues/8968 it was probably fixed in NX 14 but since the actions use 13 and the workspace was generated by 14 we get this error.

as a workaround, please add root property to each project's project.json (don't rely on the generators to create it for you)

you can check this fixed minimal reproduction https://github.com/ronnetzer/nx-github-actions-error (cloned from @robinpellegrims's repro)

Please let me know if this fixed is not working for you @jason-edstrom @tamascsaba @robinpellegrims

tamascsaba commented 2 years ago

I have more than 200 project.json in my project, so if it easier to update this action to version 14 please let me know.

ronnetzer commented 2 years ago

@tamascsaba This is something that can be managed with a simple search & replace, in any case updating to 14 will take time and I can't guarantee that it will be started anytime soon.

Also, there are some issues that block the update, the biggest one is migrating back from github-script action to standalone shell scripts, after that I'll need to do some cleanup of NX internal code I had to overwrite in order to use it in github-script.

I will probably have more time to get into this update after the holidays season in Israel (around November)

tamascsaba commented 2 years ago

@ronnetzer thank you very much your informations. I really appreciate your quick feedback 👍

ctjhoa commented 1 year ago

For those who don't want to deal with the root attribute, I've done a script which add it automatically so your repo can stay clean on latest NX versions.

  setup:
    runs-on: ubuntu-latest
    name: Affected Matrix
    outputs:
      hasChanges: ${{ steps.affected.outputs.hasChanges }}
      matrix: ${{ steps.affected.outputs.matrix }}
    steps:
      - name: ⬇️ Checkout
        uses: actions/checkout@v3
        with:
          fetch-depth: 0
      - name: fix https://github.com/e-square-io/nx-github-actions/issues/53
        run: >
          addRoot() {
            ROOT_PATH=$(dirname "$1")
            PROJECT_CONTENT=$(jq ". + {root: \"${ROOT_PATH}\"}" < "$1")
            echo "$PROJECT_CONTENT" > "$1"
          };
          find apps -name project.json | while read file; do addRoot "$file"; done;
          find libs -name project.json | while read file; do addRoot "$file"; done;
          find tools -name project.json | while read file; do addRoot "$file"; done;
        shell: bash
      - name: Calculate affected projects
        uses: e-square-io/nx-affected-matrix@v2
        id: affected
        with:
          targets: 'lint,test,build'
          maxDistribution: 3
          checkout: false