我正在尝试设置一个使用nx.dev开发的monorepo完整CI/CD管道,在这里我只构建和部署在提交过程中发生更改的应用程序和服务。
我的云构建链接到我的github存储库,当一个更改被推送时,它将启动一个构建。首先安装npm,然后构建更改后的应用程序。
根据nx https://nx.dev/guides/monorepo-affected#ci上的nrwls文档,他们说要使用
npm run affected:build -- --base=origin/master~1 --head=origin/master这将比较当前提交和之前的提交,以找出要构建的服务或应用程序。
我曾尝试使用它,但在云构建中运行时遇到此错误
Step #1: fatal: Not a valid object name master~1
Step #1: Command failed: git merge-base master~1 master
Step #1: fatal: Not a valid object name master~1当使用cloud- build -local在本地构建时,它工作得很好,并成功地确定了要构建的服务。
我认为它失败的原因是因为当cloud build检出git存储库时,它只检出提交,而不是以前的提交信息。因此,它不能引用上一次提交。
有什么办法解决这个问题吗?还是我漏掉了什么?
谢谢!
发布于 2021-03-04 17:20:14
我正面临着同样的问题,原因是受影响的需要深入检查,因为它与master不同。因此,GHA中的以下更改将解决此问题:
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0发布于 2020-03-02 01:54:31
您也许可以使用表达式来完成此操作。
npm run affected:build -- --base=$(git rev-parse HEAD~1) --head=origin/master这就是我如何使用github操作完成此操作
name: Test develop and feature branches
on:
push:
branches:
- develop
- "feature/*"
jobs:
test:
name: Test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- name: Use node.js 12
uses: actions/setup-node@v1
with:
node-version: 12
- name: Cache Yarn
uses: actions/cache@v1
with:
path: node_modules
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.OS }}-yarn-${{ env.cache-name }}-
${{ runner.os }}-yarn-
- name: Yarn install
run: yarn install --frozen-lockfile --non-interactive
- name: Retreive last test sha
id: last-test-sha
run: |
if [[ $GITHUB_BASE_REF ]]
then
echo "::set-output name=sha::remotes/origin/$GITHUB_BASE_REF"
else
echo "::set-output name=sha::$(git rev-parse HEAD~1)"
fi
- name: Run affected tests
run: yarn affected:test --ci --runInBand --base=${{ steps.last-test-sha.outputs.sha }} --head=${GITHUB_SHA}
env:
CI: "true"
TZ: "utc"发布于 2020-03-26 00:12:12
云构建既不获取分支,也不获取历史。
Including the repository history in a build
Cloud Build不检出任何其他分支或历史记录。这样做是为了提高效率,这样构建就不必等待获取整个存储库和历史记录,而只需构建一个提交。
因此,他们建议在构建期间获取历史记录。例如,这是一个老生常谈的例子,您如何将.git文件夹添加到您的构建工作区,以便NX可以计算受影响的项目。
- id: Get the .git directory
name: git
args:
- bash
- -c
- |-
# get the .git directory only
git clone --branch $BRANCH_NAME git@github.com:<USER_NAME>/$REPO_NAME /tmp/repo ;
# move it to the workspace
mv /tmp/repo/.git .如果您有私有存储库,请使用描述身份验证过程的there is an article。
https://stackoverflow.com/questions/56641571
复制相似问题