nx: nx affected:apps fails with error fatal: Not a valid object name master
Prerequisites
Please answer the following questions for yourself before submitting an issue. YOU MAY DELETE THE PREREQUISITES SECTION.
- [ x ] I am running the latest version
- [ x ] I checked the documentation (nx.dev) and found no answer
- [ x ] I checked to make sure that this issue has not already been filed
- [ x ] I’m reporting the issue to the correct repository (not related to React, Angular or any dependency)
Expected Behavior
nx affected:apps --plain should display list of affected apps.
we use this comma separated list of affected apps to determine what apps to deploy
What is the current behavior? No
Failure Information (for bugs)
Please help provide information about the failure if this is a bug. If it is not a bug, please remove the rest of this template.
Steps to Reproduce
Please provide detailed steps for reproducing the issue.
- upgrade to latest nrwl
- init workspace
- npm run affected:apps – --plain
Context
Please provide any relevant information about your setup:
- Interesting thing to note, I do not see any error when running from my local machine but from ci.
A minimal reproduction scenario allows us to quickly confirm a bug (or point out coding problem) as well as confirm that we are fixing the right problem.
Failure Logs
Please include any relevant log snippets or files here. Above command fails with
> xxx@0.0.0 affected:apps /home/runner/work/xxxx/xxxx
> nx affected:apps
fatal: Not a valid object name master
/home/runner/work/xxxx/xxxx/node_modules/@nrwl/workspace/node_modules/yargs/yargs.js:1109
else throw err
^
Error: Command failed: git merge-base master HEAD
fatal: Not a valid object name master
at checkExecSyncError (child_process.js:629:11)
at Object.execSync (child_process.js:666:13)
...
...
...
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! thetopper@0.0.0 affected:apps: `nx affected:apps`
npm ERR! Exit status 1
npm ERR!
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 4
- Comments: 18 (3 by maintainers)
Links to this issue
Commits related to this issue
- Fix https://github.com/nrwl/nx/issues/2170#issuecomment-607986124 — committed to andrebraghini/nx-affected-test by andrebraghini 4 years ago
- ci(travis): fetch branch before running tests This should fix issue with NX CLI (see https://github.com/nrwl/nx/issues/2170) — committed to orchestratora/orchestrator by gund 4 years ago
- ci(travis): fetch branch before running tests This should fix issue with NX CLI (see https://github.com/nrwl/nx/issues/2170) — committed to orchestratora/orchestrator by gund 4 years ago
- ci(travis): fetch branch before running tests This should fix issue with NX CLI (see https://github.com/nrwl/nx/issues/2170) — committed to orchestratora/orchestrator by gund 4 years ago
- ci(travis): fetch branch before running tests This should fix issue with NX CLI (see https://github.com/nrwl/nx/issues/2170) — committed to orchestratora/orchestrator by gund 4 years ago
- ci(travis): fetch branch before running tests This should fix issue with NX CLI (see https://github.com/nrwl/nx/issues/2170) — committed to orchestratora/orchestrator by gund 4 years ago
- ci(travis): fetch branch before running tests This should fix issue with NX CLI (see https://github.com/nrwl/nx/issues/2170) — committed to orchestratora/orchestrator by gund 4 years ago
- ci(travis): fetch branch before running tests This should fix issue with NX CLI (see https://github.com/nrwl/nx/issues/2170) — committed to orchestratora/orchestrator by gund 4 years ago
- ci(travis): fetch branch before running tests This should fix issue with NX CLI (see https://github.com/nrwl/nx/issues/2170) — committed to orchestratora/orchestrator by gund 4 years ago
- ci(travis): fetch branch before running tests This should fix issue with NX CLI (see https://github.com/nrwl/nx/issues/2170) — committed to orchestratora/orchestrator by gund 4 years ago
- ci(travis): fetch branch before running tests This should fix issue with NX CLI (see https://github.com/nrwl/nx/issues/2170) — committed to orchestratora/orchestrator by gund 4 years ago
- ci(travis): fetch branch before running tests This should fix issue with NX CLI (see https://github.com/nrwl/nx/issues/2170) — committed to orchestratora/orchestrator by gund 4 years ago
- ci(travis): fetch branch before running tests This should fix issue with NX CLI (see https://github.com/nrwl/nx/issues/2170) — committed to orchestratora/orchestrator by gund 4 years ago
- ci(travis): fetch branch before running tests This should fix issue with NX CLI (see https://github.com/nrwl/nx/issues/2170) — committed to orchestratora/orchestrator by gund 4 years ago
- ci(travis): fetch branch before running tests This should fix issue with NX CLI (see https://github.com/nrwl/nx/issues/2170) — committed to orchestratora/orchestrator by gund 4 years ago
- ci(travis): fetch branch before running tests This should fix issue with NX CLI (see https://github.com/nrwl/nx/issues/2170) — committed to orchestratora/orchestrator by gund 4 years ago
- ci(travis): fetch branch before running tests This should fix issue with NX CLI (see https://github.com/nrwl/nx/issues/2170) — committed to orchestratora/orchestrator by gund 4 years ago
- ci(travis): fetch branch before running tests This should fix issue with NX CLI (see https://github.com/nrwl/nx/issues/2170) — committed to orchestratora/orchestrator by gund 4 years ago
- ci(travis): fetch branch before running tests This should fix issue with NX CLI (see https://github.com/nrwl/nx/issues/2170) — committed to orchestratora/orchestrator by gund 4 years ago
- ci(travis): fetch branch before running tests This should fix issue with NX CLI (see https://github.com/nrwl/nx/issues/2170) — committed to orchestratora/orchestrator by gund 4 years ago
@Plysepter ah, thank you! That definitely helped. Here’s my current best working config:
I think this issue can be closed now.
I run affected:build like this:
npm run affected:build -- --base=$NX_BASEwhere NX_BASE is different depending on whether a push event or a pull request triggers the workflow.
In case of a push, we want to look at the commit id of the second newest commit, which translates to
export NX_BASE=$(git rev-parse HEAD~1)Keep in mind that you need to use the checkout action earlier with a fetch depth of at least 2 for this to work.
- uses: actions/checkout@v2 with: fetch-depth: 2In case of a pull request, it could look like something like this
export NX_BASE_TEMP=$(git log --format=%H -n 1 origin/${{ github.base_ref }})This is the newest commit id of the target branch. I needed to use git fetch origin beforehand for this to work.
Hope this helps a bit!
So I encountered this issue in Github Actions and after some debugging I have found the following:
By default Github Actions checkout action only pulls the latest commit in a detached head state. I have found this causes any git operation for comparison to break.
I resolved the issue in Github Actions with these steps:
The key here is changing the default ref so that it pulls the branch instead of just the single commit. I am comparing for a PR so I am only fetching master and the depth flag could be adjusted/removed for different use cases and you could fetch as many branches as your use case needs.
To make this work I had to ensure I had
origin/masterinstead of justmasterfor the base flag even though the master branch was pulled. I don’t have an exact explanation as to why but this did allow my lint, format and testing jobs to succeed.I hope this can be of use to others experiencing this issue
Also link to github checkout action thread regarding this use case: https://github.com/actions/checkout/pull/155 (edit: improved formatting, added link to thread)
same situation, nothing works
@DedoxBR I resolved this by replacing above command with
nx affected:apps --base=origin/master --head=origin/master --plainRef:are you sure you aren’t forgetting the double dash?
WORKS
npm run affected:apps -- --base developvsDOESN’T WORK
npm run affected:apps --base develop@whimzyLive it didn’t work for me.
If it helps, I created a clean repository simulating the problem here: https://github.com/andrebraghini/nx-affected-test
I have the same problem on CI using Github Actions and it only happens when running on a branch other than master.
When running on the master it works without problems.
Tnx. works for me, so locally I had branch accessible with
branch=xbut on CI it should bebranch=origin/xHi, do you have a
masterbranch checked out locally?If
masteris not your default branch, you should set--baseto your default branch:For Example: