nx affected:build failing with 'fatal: Not a valid object name main' error on github action pipeline
See original GitHub issueCurrent Behavior
nx affected:build command failing on github action pipeline process
Resolving deltas: 100% (4378/4378), done.
From https://github.com/asleep-ai/Root-web
* [new branch] bugfix/APP-364 -> origin/bugfix/APP-364
* [new branch] bugfix/actions -> origin/bugfix/actions
* [new branch] dependabot/npm_and_yarn/cypress-10.3.0 -> origin/dependabot/npm_and_yarn/cypress-10.3.0
* [new branch] dependabot/npm_and_yarn/metro-0.71.3 -> origin/dependabot/npm_and_yarn/metro-0.71.3
* [new branch] dependabot/npm_and_yarn/metro-babel-register-0.71.3 -> origin/dependabot/npm_and_yarn/metro-babel-register-0.71.3
* [new branch] dependabot/npm_and_yarn/react-native-community/cli-8.0.3 -> origin/dependabot/npm_and_yarn/react-native-community/cli-8.0.3
* [new branch] dependabot/npm_and_yarn/react-native-community/cli-platform-android-8.0.2 -> origin/dependabot/npm_and_yarn/react-native-community/cli-platform-android-8.0.2
* [new branch] develop -> origin/develop
* [new branch] main -> origin/main
* [new branch] release -> origin/release
* [new branch] with-graphql-codegen -> origin/with-graphql-codegen
* [new ref] 07c1295939e85a855d75ab39859f8eac04c7a4ed -> pull/183/merge
Checking out the ref
/usr/bin/git checkout --progress --force refs/remotes/pull/183/merge
Note: switching to 'refs/remotes/pull/183/merge'.
You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by switching back to a branch.
If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -c with the switch command. Example:
git switch -c <new-branch-name>
Or undo this operation with:
git switch -
Turn off this advice by setting config variable advice.detachedHead to false
HEAD is now at 07c1295 Merge 895027c6922cc908e7c6acf6c708caec70e08644 into 68160541c47a3fe10eaf986092c839428e0c0ae7
/usr/bin/git log -1 --format='%H'
'07c[1](https://github.com/Root-web/runs/7406060356?check_suite_focus=true#step:3:1)295939e85a855d[75](https://github.com/Root-web/runs/7406060356?check_suite_focus=true#step:3:77)ab39[85](https://github.com/Root-web/runs/7406060356?check_suite_focus=true#step:3:87)9f8eac04c7a4ed'
Building using yarn run affected:build
/usr/local/bin/yarn run affected:build
yarn run v1.22.19
$ nx affected:build
> NX Affected criteria defaulted to --base=main --head=HEAD
fatal: Not a valid object name main
fatal: No such ref: 'main'
nx affected:build
Run command using --base=[SHA1] (affected by the committed, uncommitted and untracked changes):
--base Base of the current branch (usually main) [string]
or using --base=[SHA1] --head=[SHA2] (affected by the committed changes):
--base Base of the current branch (usually main) [string]
--head Latest commit of the current branch (usually HEAD) [string]
or using:
--files Change the way Nx is calculating the affected command by providing directly changed files, list of files delimited by commas [array]
--uncommitted Uncommitted changes [boolean]
--untracked Untracked changes [boolean]
Options:
--help Show help [boolean]
--version Show version number [boolean]
--parallel Max number of parallel processes [default is 3] [string]
--output-style Defines how Nx emits outputs tasks logs [string] [choices: "dynamic", "static", "stream", "stream-without-prefixes"]
--all All projects [boolean]
--exclude Exclude certain projects from being processed [array] [default: []]
--runner This is the name of the tasks runner configured in nx.json [string]
--skip-nx-cache Rerun the tasks even when the results are available in the cache [boolean] [default: false]
--configuration This is the configuration to use when performing tasks on projects [string]
--only-failed Isolate projects which previously failed [deprecated: The command to rerun failed projects will appear if projects fail. This now does nothing and will be removed in v15.] [boolean] [default: false]
--verbose Print additional error stack trace on failure
--nx-bail Stop command execution after the first failed task [boolean] [default: false]
--nx-ignore-cycles Ignore cycles in the task graph [boolean] [default: false]
Examples:
affected --target=custom-target Run custom target for all affected projects
affected --target=test --parallel=5 Run tests in parallel
affected --target=test --all Run the test target for all projects
affected --target=test --files=libs/mylib/src/index.ts Run tests for all the projects affected by changing the index.ts file
affected --target=test --base=main --head=HEAD Run tests for all the projects affected by the changes between main and HEAD (e.g., PR)
affected --target=test --base=main~1 --head=main Run tests for all the projects affected by the last commit on main
Find more information and examples at https://nx.dev/cli/affected
Error: Command failed: git merge-base --fork-point "main" "HEAD"
fatal: No such ref: 'main'
at checkExecSyncError (node:child_process:[82](https://github.com/Root-web/runs/7406060356?check_suite_focus=true#step:3:84)8:11)
at execSync (node:child_process:[89](https://github.com/Root-web/runs/7406060356?check_suite_focus=true#step:3:91)9:15)
at getFilesUsingBaseAndHead (/home/runner/work/Root-web/Root-web/node_modules/nx/src/utils/command-line-utils.js:282:50)
at parseFiles (/home/runner/work/Root-web/Root-web/node_modules/nx/src/utils/command-line-utils.js:257:20)
at projectsToRun (/home/runner/work/Root-web/Root-web/node_modules/nx/src/command-line/affected.js:97:145)
at Object.<anonymous> (/home/runner/work/Root-web/Root-web/node_modules/nx/src/command-line/affected.js:26:26)
at Generator.next (<anonymous>)
at fulfilled (/home/runner/work/Root-web/Root-web/node_modules/tslib/tslib.js:115:62)
at processTicksAndRejections (node:internal/process/task_queues:[96](https://github.com/Root-web/runs/7406060356?check_suite_focus=true#step:3:98):5) {
status: [128](https://github.com/Root-web/runs/7406060356?check_suite_focus=true#step:3:130),
signal: null,
output: [
null,
<Buffer >,
<Buffer 66 61 74 61 6c 3a 20 4e 6f 20 73 75 63 68 20 72 65 66 3a 20 27 6d 61 69 6e 27 0a>
],
pid: 2537,
stdout: <Buffer >,
stderr: <Buffer 66 61 74 61 6c 3a 20 4e 6f 20 73 75 63 68 20 72 65 66 3a 20 27 6d 61 69 6e 27 0a>
}
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
Error: The process '/usr/local/bin/yarn' failed with exit code 1
nx seems to not know the existence of main branch. before running the building process actions/checkout@v3 is being executed to checkout the latest HEAD (and also fetches all branches with fetch-depth 0)
Expected Behavior
nx affected:build to succeed.
Environment
on: [pull_request]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- uses: preactjs/compressed-size-action@v2
with:
repo-token: '${{ secrets.GITHUB_TOKEN }}'
build-script: 'nx affected:build'
clean-script: 'clean:by-bot'
pattern: './dist/**/*.{js,css,html,json}'
exclude: '{./dist/manifest.json,**/*.map,**/node_modules/**,**/next.config.js,**/public/**}```
this is the script that runs for the action and it gets error on the build-script process
Issue Analytics
- State:
- Created a year ago
- Comments:5
Top Results From Across the Web
nx affected:apps fails with error fatal: Not a valid object name ...
I have the same problem on CI using Github Actions and it only happens when running on a branch other than master. When...
Read more >affected:build failing in the pipeline #5960 - nrwl/nx - GitHub
The affected:build is failing with the message: fatal: Not a valid object name master fatal: No such ref: 'master'.
Read more >Runnung nx affected:libs on pipeline returns with ERROR ...
nx affected:libs --base=master fatal: Not a valid object name master Command failed: git merge-base master HEAD fatal: Not a valid object ...
Read more >Not a valid object name origin/main - nrwl/nx-set-shas - GitHub
Hello everyone I'm trying to setup the CI environment to use Nx Cloud but I'm getting stuck on changing the target branch from...
Read more >nx affected:build failing with error: "fatal: No such ref ... - GitHub
nx affected:build failing with error: "fatal: No such ref" when running in GitHub actions #12203. Open. Maoragai12 opened this issue on Sep ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@jcqvisser Thanks to you it solved my problem! thank you
@DannyPark1
In that case you’d set the
defaultBase
to"main"
.That’ll work locally, since you’d presumably have a
main
branch that tracksorigin/main
.To get it to work on github-actions, you’ll have to create a local branch that tracks
origin/main
. I guess you could try creatingmain
that tracksorigin/main
manually, though I haven’t tried this. 🤷