繁体   English   中英

NX monorepo 致命:没有这样的参考:'main~1'

[英]NX monorepo fatal: No such ref: 'main~1'

我正在尝试在启用 nx 云的 github 操作中构建我的 nx 应用程序。 我总是得到fatal: No such ref: 'main~1'错误。

命令nx affected --target=build --base=main~1 --head=HEAD --parallel --with-deps在我提交之前工作,但在我提交之后,该命令不再在本地或在 ci 中工作。

根据文档,将 base 设置为main~1应该将其与主分支的先前提交进行比较。

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.

工作流文件

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

{
    "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"]
        }
    }
}

好吧...所以我终于弄清楚发生了什么。 在 github 操作中记录git show-ref后,我发现默认情况下actions/checkout出操作仅签出一个提交。

对于触发工作流的 ref/SHA,默认情况下只获取一个提交。

在指定fetch-depth: 0以获取所有分支的所有 refs 后,它起作用了。 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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM