如何授予语义发布权限以将代码推送到 master

How to grant permission for semantic-release to push code to master

我正在使用 semantic-release 自动定义下一个版本,更新 package.json 并推送到 git。但是,我遇到了一个问题,它阻止我直接推送到 master.

我正在使用 GitLab

我的release.config.js

module.exports = {
    "plugins": [
        "@semantic-release/commit-analyzer",
        "@semantic-release/release-notes-generator",
        "@semantic-release/changelog",
        "@semantic-release/npm",
        ["@semantic-release/git", {
            "assets": ["dist/**/*.{js,css}", "docs", "package.json"],
            "message": "chore(release): ${nextRelease.version} [skip ci]\n\n${nextRelease.notes}"
        }]
    ]
}

我的gitlab-ci.yml

package-versioning:
  stage: package-versioning
  tags:
    - fe
    - xdev
  artifacts:
    expire_in: 1 day
  only:
    refs:
      - master
  dependencies:
    - install
    - build
    - test
  script:
    - npx semantic-release --tag-format 'app/v${version}'

错误:

The command "git push --dry-run --no-verify https://gitlab-ci-token:[secure]@***/**.git HEAD:master" failed with the error message remote: You are not allowed to upload code.

fatal: unable to access 'https://gitlab-ci-token:[secure]@***/**.git/': The requested URL returned error: 403.

[6:02:23 PM] [semantic-release] › ✖  EGITNOPERMISSION Cannot push to the Git repository.
semantic-release cannot push the version tag to the branch next on the remote Git repository with URL https://gitlab-ci-token:[secure]@***/**.git.

但我实际上是 repo 的所有者,并且已经将 master 的推送权限设置为仅所有者。我是否需要为脚本配置任何其他身份验证以代表我 运行?

所以我的问题是:

1/ semantic-release如何设置鉴权,直接代你push到master

2/ 将 master 直接推送到 master 是否是一个好习惯(尽管它仅用于版本更新)。有没有人遇到过这种情况,更新版本的解决方案是什么。非常感谢您的意见和想法。

1.In Git实验你必须解释citly 设置脚本推送到 Git。为此,您需要创建一个令牌并将其通过环境变量传递给您的 CI。

例如,通过设置 GIT_PUSH_TOKEN 查看我们如何在集成项目中执行此操作 - 此处:https://gitlab.com/taleodor/sample-helm-cd

和此处的实际 ci yaml 代码:https://gitlab.com/taleodor/sample-helm-cd/-/blob/master/.gitlab-ci.yml(第 25-30 行)。

2.Yes,直接推送版本bump很常见。