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

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

Closed
duki994 opened this issue Jan 4, 2023 · 6 comments
Assignees
Labels
bug Something isn't working good first issue Good for newcomers

Comments

@duki994
Copy link
Contributor

duki994 commented Jan 4, 2023

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

  • Version nx-set-shas@v3
  • Reproducible on any other branch that has a single commit
  • Fails because git rev-parse ${remoteName}/${branchName}~1 doesn't exist but actual ${remoteName}/${branchName} exists
@duki994 duki994 changed the title Does not work when there is single commit on main branch Does not work when there is single commit on push target branch (e.g default main branch) Jan 4, 2023
@meeroslav meeroslav added bug Something isn't working good first issue Good for newcomers labels Jan 4, 2023
@meeroslav
Copy link
Collaborator

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
Copy link
Contributor Author

duki994 commented Jan 4, 2023

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
Copy link

Any updates?

@NovaMachina
Copy link

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

@vibaiher-qatium
Copy link

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
Copy link
Collaborator

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

5 participants