GitHub 身份验证时语义发布失败:插件“@semantic-release/github”的步骤 "fail" 失败

Semantic-Release fails on GitHub authentication: Failed step "fail" of plugin "@semantic-release/github"

我正在尝试将 semantic-release 集成到我的节点 CI/CD 工作流程中。我尝试按照文档和教程进行操作,但显然遗漏了一些东西。测试步骤通过,但发布步骤在“运行 npx 语义发布”处失败。

这是我正在使用的 YML 脚本:

name: Test and Release CI/CD

on:
  push:
    branches: [ main ]
  pull_request:
    branches: [ main ]

jobs:
  test:

    runs-on: ${{ matrix.os }}

    strategy:
      matrix:
        node-version: [16.x]
        os: [ubuntu-latest]

    steps:
    - uses: actions/checkout@v3
    - name: Use Node.js ${{ matrix.node-version }}
      uses: actions/setup-node@v3
      with:
        node-version: ${{ matrix.node-version }}
        cache: 'npm'
    - run: npm ci
    - run: npm test

  publish:
    runs-on: ubuntu-latest
    needs: [test]
    steps:
    - uses: actions/checkout@v3
    - name: Use Node.js 16.x
      uses: actions/setup-node@v3
      with:
        node-version: "16.x"
    - run: npm ci
    - run: npx semantic-release
      env:
        GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        NPM_TOKEN: ${{ secrets.NPM_TOKEN }}

这是 Github 操作的错误:

Run npx semantic-release
[5:46:35 PM] [semantic-release] › ℹ  Running semantic-release version 19.0.2
[5:46:35 PM] [semantic-release] › ✔  Loaded plugin "verifyConditions" from "@semantic-release/npm"
[5:46:35 PM] [semantic-release] › ✔  Loaded plugin "verifyConditions" from "@semantic-release/github"
[5:46:35 PM] [semantic-release] › ✔  Loaded plugin "analyzeCommits" from "@semantic-release/commit-analyzer"
[5:46:35 PM] [semantic-release] › ✔  Loaded plugin "generateNotes" from "@semantic-release/release-notes-generator"
[5:46:35 PM] [semantic-release] › ✔  Loaded plugin "prepare" from "@semantic-release/npm"
[5:46:35 PM] [semantic-release] › ✔  Loaded plugin "publish" from "@semantic-release/npm"
[5:46:35 PM] [semantic-release] › ✔  Loaded plugin "publish" from "@semantic-release/github"
[5:46:35 PM] [semantic-release] › ✔  Loaded plugin "addChannel" from "@semantic-release/npm"
[5:46:35 PM] [semantic-release] › ✔  Loaded plugin "addChannel" from "@semantic-release/github"
[5:46:35 PM] [semantic-release] › ✔  Loaded plugin "success" from "@semantic-release/github"
[5:46:35 PM] [semantic-release] › ✔  Loaded plugin "fail" from "@semantic-release/github"
[5:46:36 PM] [semantic-release] › ℹ  Start step "fail" of plugin "@semantic-release/github"
[5:46:36 PM] [semantic-release] [@semantic-release/github] › ℹ  Verify GitHub authentication (https://api.github.com)
[5:46:36 PM] [semantic-release] › ✖  Failed step "fail" of plugin "@semantic-release/github"
[5:46:36 PM] [semantic-release] › ✖  An error occurred while running semantic-release: TypeError: Cannot read properties of undefined (reading 'name')
    at module.exports (/home/runner/work/Alphanumeric-Encoder/Alphanumeric-Encoder/node_modules/@semantic-release/github/lib/get-fail-comment.js:19:10)
    at module.exports (/home/runner/work/Alphanumeric-Encoder/Alphanumeric-Encoder/node_modules/@semantic-release/github/lib/fail.js:28:74)
    at async fail (/home/runner/work/Alphanumeric-Encoder/Alphanumeric-Encoder/node_modules/@semantic-release/github/index.js:64:3)
    at async validator (/home/runner/work/Alphanumeric-Encoder/Alphanumeric-Encoder/node_modules/semantic-release/lib/plugins/normalize.js:34:24)
    at async /home/runner/work/Alphanumeric-Encoder/Alphanumeric-Encoder/node_modules/semantic-release/lib/plugins/pipeline.js:37:34
    at async /home/runner/work/Alphanumeric-Encoder/Alphanumeric-Encoder/node_modules/semantic-release/lib/plugins/pipeline.js:31:3
    at async Object.pluginsConf.<computed> [as fail] (/home/runner/work/Alphanumeric-Encoder/Alphanumeric-Encoder/node_modules/semantic-release/lib/plugins/index.js:80:11)
    at async callFail (/home/runner/work/Alphanumeric-Encoder/Alphanumeric-Encoder/node_modules/semantic-release/index.js:243:7)
    at async module.exports (/home/runner/work/Alphanumeric-Encoder/Alphanumeric-Encoder/node_modules/semantic-release/index.js:272:7)
    at async module.exports (/home/runner/work/Alphanumeric-Encoder/Alphanumeric-Encoder/node_modules/semantic-release/cli.js:55:5) {
  pluginName: '@semantic-release/github'
}
[5:46:36 PM] [semantic-release] › ✖  ERELEASEBRANCHES The release branches are invalid in the `branches` configuration.
A minimum of 1 and a maximum of 3 release branches are required in the branches configuration (https://github.com/semantic-release/semantic-release/blob/master/docs/usage/configuration.md#branches).

This may occur if your repository does not have a release branch, such as master.

Your configuration for the problematic branches is [].

AggregateError: 
    SemanticReleaseError: The release branches are invalid in the `branches` configuration.
        at module.exports (/home/runner/work/Alphanumeric-Encoder/Alphanumeric-Encoder/node_modules/semantic-release/lib/get-error.js:6:10)
        at /home/runner/work/Alphanumeric-Encoder/Alphanumeric-Encoder/node_modules/semantic-release/lib/branches/index.js:44:19
        at Array.reduce (<anonymous>)
        at module.exports (/home/runner/work/Alphanumeric-Encoder/Alphanumeric-Encoder/node_modules/semantic-release/lib/branches/index.js:34:46)
        at processTicksAndRejections (node:internal/process/task_queues:96:5)
        at async run (/home/runner/work/Alphanumeric-Encoder/Alphanumeric-Encoder/node_modules/semantic-release/index.js:65:22)
        at async module.exports (/home/runner/work/Alphanumeric-Encoder/Alphanumeric-Encoder/node_modules/semantic-release/index.js:268:22)
        at async module.exports (/home/runner/work/Alphanumeric-Encoder/Alphanumeric-Encoder/node_modules/semantic-release/cli.js:55:5)
    at module.exports (/home/runner/work/Alphanumeric-Encoder/Alphanumeric-Encoder/node_modules/semantic-release/lib/branches/index.js:66:11)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async run (/home/runner/work/Alphanumeric-Encoder/Alphanumeric-Encoder/node_modules/semantic-release/index.js:65:22)
    at async module.exports (/home/runner/work/Alphanumeric-Encoder/Alphanumeric-Encoder/node_modules/semantic-release/index.js:268:22)
    at async module.exports (/home/runner/work/Alphanumeric-Encoder/Alphanumeric-Encoder/node_modules/semantic-release/cli.js:55:5)
Error: Process completed with exit code 1.

在其他故障排除期间,我已使用此项目的 NPM_TOKEN 成功发布,所以我知道这不是问题所在。我相信问题可能出在 GitHub 身份验证令牌上,但对于我来说,我很难过。我不知道我做错了什么。我该如何纠正这个错误?

编辑 - 相关:semantic release - TypeError: Cannot read property 'name' of undefined

默认配置假定分支 master,因此如果您使用 main,您将得到 ERELEASEBRANCHES 错误。

您可以尝试使用该分支设置 .releaserc.js 文件(或 package.json 中的 release 属性)。

"branches": ["main", "next"]

配置文档位于 https://semantic-release.gitbook.io/semantic-release/usage/configuration

有一个 PR 将 main 添加为后备默认分支,但尚未合并。