[英]NX monorepo fatal: No such ref: 'main~1'
I'm trying to build my nx application in github actions with nx cloud enabled.我正在尝试在启用 nx 云的 github 操作中构建我的 nx 应用程序。 I always get the
fatal: No such ref: 'main~1'
error.我总是得到
fatal: No such ref: 'main~1'
错误。
The command nx affected --target=build --base=main~1 --head=HEAD --parallel --with-deps
works before I commit, but after I commit, the command no longer works locally or in ci.命令
nx affected --target=build --base=main~1 --head=HEAD --parallel --with-deps
在我提交之前工作,但在我提交之后,该命令不再在本地或在 ci 中工作。
Based on the docs, setting the base to main~1
should just compare it to the previous commit of the main branch.根据文档,将 base 设置为
main~1
应该将其与主分支的先前提交进行比较。
Full error in Github Actions: Github 操作中的完全错误:
yarn run v1.22.10
$ nx affected --target=build --base=main~1 --head=HEAD --parallel --with-deps
fatal: Not a valid object name main~1
fatal: No such ref: 'main~1'
nx affected
Run task for affected projects
Run command using --base=[SHA1] (affected by the committed, uncommitted and
untracked changes):
--base Base of the current branch (usually master) [string]
or using --base=[SHA1] --head=[SHA2] (affected by the committed changes):
--base Base of the current branch (usually master) [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]
--target Task to run for affected projects [string] [required]
--parallel Parallelize the command (default: false) [boolean]
--maxParallel Max number of parallel processes. This flag is ignored if the
parallel option is set to `false`. (default: 3) [number]
--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
[boolean] [default: false]
--verbose Print additional error stack trace on failure
Error: Command failed: git merge-base --fork-point "main~1" "HEAD"
fatal: No such ref: 'main~1'
at checkExecSyncError (child_process.js:616:11)
at Object.execSync (child_process.js:652:15)
at getFilesUsingBaseAndHead (/home/runner/work/clemento/app/node_modules/@nrwl/workspace/src/command-line/shared.js:55:37)
at Object.parseFiles (/home/runner/work/clemento/app/node_modules/@nrwl/workspace/src/command-line/shared.js:25:20)
at Object.<anonymous> (/home/runner/work/clemento/app/node_modules/@nrwl/workspace/src/command-line/affected.js:26:112)
at Generator.next (<anonymous>)
at fulfilled (/home/runner/work/clemento/app/node_modules/tslib/tslib.js:114:62) ***
status: 128,
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 6f 72 69 67 69 6e 2f 6d 61 69 6e 7e 31 27 0a>
],
pid: 1713,
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 6f 72 69 67 69 6e 2f 6d 61 69 6e 7e 31 27 0a>
***
error Command failed with exit code 1.
Workflow File工作流文件
name: Deploy Updated Apps
on:
push:
branches:
- main
- feature/*
- bugfix/*
- hotfix/*
- refactor/*
- test/*
paths:
- "apps/**"
- "libs/**"
- .github/**
- scripts/**
- package.json
- workspace.json
- nx.json
jobs:
deploy-updated-apps:
name: Deploy Updated Apps
runs-on: ubuntu-latest
env:
NX_BRANCH: ${{ github.event.number }}
NX_RUN_GROUP: ${{ github.run_id }}
steps:
- uses: actions/checkout@v2
- name: Get Service Account Key
run: ./scripts/get-service-account.sh
- name: Login to Google Cloud
run: ./scripts/login-to-google-cloud.sh
- name: Install dependencies
run: yarn install
- name: Build affected apps
run: yarn affected:build
nx.json nx.json
{
"implicitDependencies": {
"package.json": {
"dependencies": "*",
"devDependencies": "*"
},
".eslintrc.json": "*"
},
"affected": {
"defaultBase": "main"
},
"npmScope": "someorg",
"tasksRunnerOptions": {
"default": {
"runner": "@nrwl/nx-cloud",
"options": {
"cacheableOperations": ["build", "lint", "test", "e2e"],
"accessToken": "<ACCESS_TOKEN>",
"canTrackAnalytics": false,
"showUsageWarnings": true
}
}
},
"projects": {
"frontend": {
"tags": []
},
"frontend-e2e": {
"tags": [],
"implicitDependencies": ["frontend"]
}
}
}
Okay... so I finally figured out what's going on.好吧...所以我终于弄清楚发生了什么。 After logging
git show-ref
in github actions, I found that the actions/checkout
action by default only checks out one commit.在 github 操作中记录
git show-ref
后,我发现默认情况下actions/checkout
出操作仅签出一个提交。
Only a single commit is fetched by default, for the ref/SHA that triggered the workflow.
对于触发工作流的 ref/SHA,默认情况下只获取一个提交。
After specifying the fetch-depth: 0
to fetch all the refs for all the branches, it worked.在指定
fetch-depth: 0
以获取所有分支的所有 refs 后,它起作用了。 Nx is able to properly compare the difference between the different branches and previous commits in the same branch. Nx 能够正确比较不同分支和同一分支中先前提交之间的差异。
jobs:
deploy-updated-apps:
name: Deploy Updated Apps
runs-on: ubuntu-latest
env:
NX_BRANCH: ${{ github.event.number }}
NX_RUN_GROUP: ${{ github.run_id }}
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Install dependencies
run: yarn install
- name: Build affected apps
run: yarn affected:build:branch
{
"scripts": {
"affected:build:branch": "nx affected:build --base=origin/main --head=HEAD --with-deps",
"affected:build:main": "nx affected:build --base=origin/main~1 --head=HEAD --with-deps",
},
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.