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

Does not work when there is single commit on `push` target branch (e.g default `main` branch) #84

Closed duki994 closed 1 year ago

duki994 commented 1 year ago

Description

nx-set-shas is not working in scenarios where there is single commit on main (or any other) branch.

It's not really connected to main branch itself, but to any combination of git rev-parse ${remoteName}/${branchName}~1 where branch ${remoteName}/${branchName} has single commit

Steps to reproduce (one way)

  1. Have a main (or any other name) branch with single commit (e.g Init with README.md)
  2. Have a second branch (e.g development) with several commits.
  3. Set up nx-set-shas via GH actions to run any affected command on push on main branch (e.g after PR merge)
  4. Bug happens

Logs

Run nrwl/nx-set-shas@v3
  with:
    main-branch-name: main
    set-environment-variables-for-job: true
    error-on-no-successful-workflow: false
    last-successful-event: push
    working-directory: .
Run node $GITHUB_ACTION_PATH/dist/index.js *** main false push . 
  node $GITHUB_ACTION_PATH/dist/index.js *** main false push . 
  shell: /usr/bin/bash --noprofile --norc -e -o pipefail {0}

Workflow Id not provided. Using workflow '**REDACTED**'

WARNING: Unable to find a successful workflow run on 'origin/main'
We are therefore defaulting to use HEAD~1 on 'origin/main'

NOTE: You can instead make this a hard error by setting 'error-on-no-successful-workflow' on the action in your workflow.
fatal: ambiguous argument 'origin/main~1': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions, like this:
'git <command> [<revision>...] -- [<file>...]'
node:internal/errors:857
  const err = new Error(message);
              ^

Error: Command failed: git rev-parse origin/main~1
fatal: ambiguous argument 'origin/main~1': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions, like this:
'git <command> [<revision>...] -- [<file>...]'

**REDACTED**

Error: Process completed with exit code 1.

Additional context

meeroslav commented 1 year ago

Thank you for reporting this.

The nx-set-shas makes no sense when there is only a single commit, but the tool should not break regardless.

duki994 commented 1 year ago

It makes sense when there are branch protection rules on main and dev branches

Example scenario is: 30 commits for initial dev branch and dev deployment 1 commit on main (README.md)

If nx-set-shas uses main branch by default it'll fail. Makes no sense from usefulness standpoint, but it happens (and can be cumbersome) when you need to push at least empty commit on main branch which is protected and you also cannot change workflow files on that branch because it's protected.

I'll see to open PR which fixes this issue (PR #85 )

TicTak21 commented 1 year ago

Any updates?

NovaMachina commented 1 year ago

I am also running into this issue. Any update on getting it fixed?

vibaiher-qatium commented 1 year ago

Not related with the described scenario above, but I got the same error when running this action without specifying the fetch-depth 0 parameter in the checkout action:

       - uses: actions/checkout@v3
+        with:
+          fetch-depth: 0
meeroslav commented 1 year ago

Thank you @duki994 for the PR and sorry for waiting so long