github - 语义发布在 GitHub 身份验证上失败 : Failed step "fail" of plugin "@semantic-release/github"

标签 github continuous-integration github-actions cicd semantic-release

我正在尝试将semantic-release集成到我的Node 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 身份验证 token 上,但我一生都被难住了。我不知道我做错了什么。我该如何纠正这个错误?

编辑 - 相关: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 添加为后备默认分支,但尚未合并。

关于github - 语义发布在 GitHub 身份验证上失败 : Failed step "fail" of plugin "@semantic-release/github",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71896623/

相关文章:

ruby - 我可以在 gemfile 中强制 gem 的依赖项吗?

在任何分支上搜索 Github 代码

msbuild - 将多个解决方案/项目转换为单个 msdeploy 包的建议?

github-actions - 我如何创建一个作业以在 Github Actions 中的所有作业之后运行

docker - Github Actions,自托管运行器 : Possible to add options to 'docker create' ?

git - 为什么我需要 SSH 授权才能克隆公开可用的 Git 存储库?

git - 如何撤消主分支的 merge ?

node.js - 在用于系统测试的开源项目中保护 travis ci 环境变量

python - 如何从 python 脚本运行 python 文件中的所有测试?

github - 如何根据分支设置工作流环境变量