8

嗨,我在我的仓库中使用语义发布进行版本控制。在我的 Gitlab 中,当我将分支与 master 合并时,我的标签会根据提交而增加,并且工作正常。有什么方法可以让我获得合并之前的“下一个标签版本”。我想在合并之前将下一个版本写入文件

尝试使用 exec 但它似乎没有运行

我尝试使用 exec 但 exec 没有为我运行(我对语义发布很陌生,我一定在某处做错了什么)

你能把我推向正确的方向吗:)

我的 gitlab Ci 脚本:

semantic_release:
stage: Tag
image: node:12.16
variables:
GITLAB_TOKEN: $TOKEN_ACCESS
before_script:
- npm install -g semantic-release/exec
- npm install -g semantic-release @semantic-release/gitlab-config
script:
- semantic-release -e @semantic-release/gitlab-config @semantic-release/exec
only:
- master

这是我的 package.json:

{
  "name": "@semantic-release/npm",
  "description": "semantic-release",
  "version": "0.0.0-development",
  "author": "",
  "release": {
    "analyzeCommits": "@semantic-release/commit-analyzer",
    "generateNotes": "@semantic-release/release-notes-generator",
    "publish": "@semantic-release/gitlab",
    "success": false,
    "fail": false,
    "branches": [
      "master"
    ],
    "npmPublish": false
  },
  "plugins": [
    "@semantic-release/commit-analyzer",
    "@semantic-release/release-notes-generator",
    ["@semantic-release/exec", {
      "prepareCmd": "./my-build-script.sh ${nextRelease.version}"
    }]
  ]
}
1:30pm
[7:55:10 AM] [semantic-release] › ✔  Completed step "analyzeCommits" of plugin "@semantic-release/commit-analyzer"
[7:55:10 AM] [semantic-release] › ℹ  The next release version is 0.2.0
[7:55:10 AM] [semantic-release] › ℹ  Start step "verifyRelease" of plugin "[Function: verifyRelease]"
[7:55:10 AM] [semantic-release] › ✔  Completed step "verifyRelease" of plugin "[Function: verifyRelease]"
[7:55:10 AM] [semantic-release] › ℹ  Start step "generateNotes" of plugin "@semantic-release/release-notes-generator"
[7:55:10 AM] [semantic-release] › ✔  Completed step "generateNotes" of plugin "@semantic-release/release-notes-generator"
[7:55:10 AM] [semantic-release] › ℹ  Start step "prepare" of plugin "[Function: prepare]"
[7:55:10 AM] [semantic-release] › ✔  Completed step "prepare" of plugin "[Function: prepare]"
[7:55:12 AM] [semantic-release] › ✔  Created tag v0.2.0
[7:55:12 AM] [semantic-release] › ℹ  Start step "publish" of plugin "@semantic-release/gitlab"
[7:55:12 AM] [semantic-release] [@semantic-release/gitlab] › ℹ  Verify GitLab authentication

Exec 似乎没有运行

4

3 回答 3

6

下一个版本标签将在发布期间传递给任何插件。为了使用下一个版本更新文件,您可以在准备步骤中使用@semantic-release/exec :

{
  "plugins": [
    "@semantic-release/commit-analyzer",
    "@semantic-release/release-notes-generator",
    "@semantic-release/npm",
    ["@semantic-release/exec", {
      "prepareCmd": "./update-version.sh ${nextRelease.version}",
    }],
  ]
}

在此示例中,./update-version.sh将在发布之前使用下一个版本作为其第一个参数调用脚本。

另请参阅常见问题解答-如何使用需要 package.json 版本的 npm 构建脚本?

于 2020-03-08T18:22:39.650 回答
4

另一个解决方案(我在我的 shell 脚本中使用)是在“试运行”上使用 grep(实际上不发布新版本)npx semantic-release --dryRun | grep -oP 'Published release \K.*? '

于 2020-04-12T19:54:22.260 回答
1

对我有用的解决方案如下:

  1. 仍然将语义发布插件的输出通过管道传输到标准输出。
  2. 将版本拉入一个 env var ( $LATEST_VERSION) 中,您可以随心所欲地进行操作。
npx semantic-release --ci false --dryRun | tee /dev/tty | grep -i "Published release" > .semver-output

export LATEST_VERSION=$([[ $(cat .semver-output) =~ .*([[:digit:]]+\.[[:digit:]]+\.[[:digit:]]+) ]] && echo ${BASH_REMATCH[1]})
于 2021-01-21T15:46:12.447 回答