在 Gitlab CI 中运行语义发布时缺少插件
Posted
技术标签:
【中文标题】在 Gitlab CI 中运行语义发布时缺少插件【英文标题】:Missing plugins when running semantic-release in Gitlab CI 【发布时间】:2021-08-22 09:04:31 【问题描述】:我很想使用语义发布来管理我们的语义版本控制。为此,我尝试将其集成到我们的 Gitlab CI 中。我遵循了一些示例并提供了必要的环境变量来将代码推送到 repo。当语义释放开始运行时,它会抛出以下错误:
$ yarn semantic-release
yarn run v1.22.10
warning package.json: No license field
$ /Users/vision-ci/builds/dFCxNLEA/0/Christoph.Griehl/semantic-versioning/node_modules/.bin/semantic-release
[11:28:47 AM] [semantic-release] › ℹ Running semantic-release version 17.4.3
[11:28:47 AM] [semantic-release] › ✔ Loaded plugin "verifyConditions" from "@semantic-release/changelog"
[11:28:47 AM] [semantic-release] › ✔ Loaded plugin "verifyConditions" from "@semantic-release/git"
[11:28:48 AM] [semantic-release] › ✔ Loaded plugin "verifyConditions" from "@semantic-release/gitlab"
[11:28:48 AM] [semantic-release] › ✔ Loaded plugin "analyzeCommits" from "@semantic-release/commit-analyzer"
[11:28:48 AM] [semantic-release] › ✔ Loaded plugin "generateNotes" from "@semantic-release/release-notes-generator"
[11:28:48 AM] [semantic-release] › ✔ Loaded plugin "prepare" from "@semantic-release/changelog"
[11:28:48 AM] [semantic-release] › ✔ Loaded plugin "prepare" from "@semantic-release/git"
[11:28:48 AM] [semantic-release] › ✔ Loaded plugin "publish" from "@semantic-release/gitlab"
[11:28:48 AM] [semantic-release] › ✔ Loaded plugin "addChannel" from "@semantic-release/npm"
[11:28:48 AM] [semantic-release] › ✔ Loaded plugin "addChannel" from "@semantic-release/github"
[11:28:48 AM] [semantic-release] › ✔ Loaded plugin "success" from "@semantic-release/github"
[11:28:48 AM] [semantic-release] › ✔ Loaded plugin "fail" from "@semantic-release/github"
[11:28:50 AM] [semantic-release] › ✔ Run automated release from branch somebranch on repository https://gitlab-ci-token:[secure]@gitlab.wabo.run/Christoph.Griehl/semantic-versioning.git
[11:28:50 AM] [semantic-release] › ✔ Allowed to push to the Git repository
[11:28:50 AM] [semantic-release] › ℹ Start step "verifyConditions" of plugin "@semantic-release/changelog"
[11:28:50 AM] [semantic-release] › ✔ Completed step "verifyConditions" of plugin "@semantic-release/changelog"
[11:28:50 AM] [semantic-release] › ℹ Start step "verifyConditions" of plugin "@semantic-release/git"
[11:28:50 AM] [semantic-release] › ✔ Completed step "verifyConditions" of plugin "@semantic-release/git"
[11:28:50 AM] [semantic-release] › ℹ Start step "verifyConditions" of plugin "@semantic-release/gitlab"
[11:28:50 AM] [semantic-release] [@semantic-release/gitlab] › ℹ Verify GitLab authentication (https://gitlab.wabo.run/api/v4)
[11:28:51 AM] [semantic-release] › ✔ Completed step "verifyConditions" of plugin "@semantic-release/gitlab"
[11:28:51 AM] [semantic-release] › ℹ No git tag version found on branch somebranch
[11:28:51 AM] [semantic-release] › ℹ No previous release found, retrieving all commits
[11:28:51 AM] [semantic-release] › ℹ Found 59 commits since last release
[11:28:51 AM] [semantic-release] › ℹ Start step "analyzeCommits" of plugin "@semantic-release/commit-analyzer"
[11:28:51 AM] [semantic-release] › ✖ Failed step "analyzeCommits" of plugin "@semantic-release/commit-analyzer"
[11:28:51 AM] [semantic-release] › ✖ An error occurred while running semantic-release: Error: Cannot find module 'conventional-changelog-conventionalcommits'
Require stack:
- /Users/vision-ci/builds/[secure]/0/Christoph.Griehl/semantic-versioning/noop.js
at Function.Module._resolveFilename (node:internal/modules/cjs/loader:941:15)
at resolveFileName (/Users/vision-ci/builds/[secure]/0/Christoph.Griehl/semantic-versioning/node_modules/resolve-from/index.js:29:39)
at resolveFrom (/Users/vision-ci/builds/[secure]/0/Christoph.Griehl/semantic-versioning/node_modules/resolve-from/index.js:43:9)
at module.exports (/Users/vision-ci/builds/[secure]/0/Christoph.Griehl/semantic-versioning/node_modules/resolve-from/index.js:46:47)
at module.exports (/Users/vision-ci/builds/[secure]/0/Christoph.Griehl/semantic-versioning/node_modules/import-from/index.js:4:55)
at module.exports (/Users/vision-ci/builds/[secure]/0/Christoph.Griehl/semantic-versioning/node_modules/@semantic-release/commit-analyzer/lib/load-parser-config.js:22:67)
at analyzeCommits (/Users/vision-ci/builds/[secure]/0/Christoph.Griehl/semantic-versioning/node_modules/@semantic-release/commit-analyzer/index.js:29:24)
at validator (/Users/vision-ci/builds/[secure]/0/Christoph.Griehl/semantic-versioning/node_modules/semantic-release/lib/plugins/normalize.js:34:30)
at /Users/vision-ci/builds/[secure]/0/Christoph.Griehl/semantic-versioning/node_modules/semantic-release/lib/plugins/pipeline.js:37:40
at next (/Users/vision-ci/builds/[secure]/0/Christoph.Griehl/semantic-versioning/node_modules/p-reduce/index.js:17:9)
code: 'MODULE_NOT_FOUND',
requireStack: [
'/Users/vision-ci/builds/[secure]/0/Christoph.Griehl/semantic-versioning/noop.js'
],
pluginName: '@semantic-release/commit-analyzer'
Error: Cannot find module 'conventional-changelog-conventionalcommits'
如您所见,它似乎加载了一些插件,但在这一步总是失败。 我的 ci.yaml 看起来像这样:
release:
stage: release
tags:
- wandelbots-web
script:
- yarn
- env
- yarn semantic-release
except:
refs:
- tags
variables:
- $CI_COMMIT_TITLE =~ /^RELEASE:.+$/
我的 package.json:
"devDependencies":
"@semantic-release/changelog": "^5.0.1",
"@semantic-release/commit-analyzer": "^8.0.1",
"@semantic-release/git": "^9.0.0",
"@semantic-release/gitlab": "^6.1.0",
"@semantic-release/npm": "^7.1.3",
"@semantic-release/release-notes-generator": "^9.0.2",
"semantic-release": "^17.4.3",
"semantic-release-slack-bot": "^2.1.1"
还有我的语义发布配置:
branches: ['master', 'somebranch']
ci: true
debug: true
dryRun: false
tagFormat: '$version'
# Global plugin options (will be passed to all plugins)
preset: 'conventionalcommits'
gitlabUrl: 'https://gitlab.OURREPOURL/' # your gitlab url
slackWebhook: 'MYSLACKURL' # if you need slack notifies
# Responsible for verifying conditions necessary to proceed with the release:
# configuration is correct, authentication token are valid, etc...
verifyConditions:
- '@semantic-release/changelog'
- '@semantic-release/git'
- '@semantic-release/gitlab'
# - 'semantic-release-slack-bot'
# Responsible for determining the type of the next release (major, minor or patch).
# If multiple plugins with a analyzeCommits step are defined, the release type will be
# the highest one among plugins output.
# Look details at: https://github.com/semantic-release/commit-analyzer#configuration
analyzeCommits:
- path: '@semantic-release/commit-analyzer'
# Responsible for generating the content of the release note.
# If multiple plugins with a generateNotes step are defined,
# the release notes will be the result of the concatenation of each plugin output.
generateNotes:
- path: '@semantic-release/release-notes-generator'
writerOpts:
groupBy: 'type'
commitGroupsSort: 'title'
commitsSort: 'header'
linkCompare: true
linkReferences: true
# Responsible for preparing the release, for example creating or updating files
# such as package.json, CHANGELOG.md, documentation or compiled assets
# and pushing a commit.
prepare:
- path: '@semantic-release/changelog'
- path: '@semantic-release/git'
message: 'RELEASE: $nextRelease.version'
assets: ['CHANGELOG.md']
# Responsible for publishing the release.
publish:
- path: '@semantic-release/gitlab'
success:
# - path: 'semantic-release-slack-bot'
# notifyOnSuccess: true
# markdownReleaseNotes: false
fail:
# - path: 'semantic-release-slack-bot'
# notifyOnFail: true
如果有人能把我推向正确的方向,我将不胜感激。我现在尝试了 2 个不同的物理 gitlab-runners,MAC 和错误都是一样的。
【问题讨论】:
【参考方案1】:您将“conventionalcommits”定义为提交消息分析器的预设。为了使用此预设,您必须将其包含到您的(开发)依赖项中。这至少是根据 npm 错误消息的错误:“找不到模块 'conventional-changelog-conventionalcommits'。
只需将其添加到您的(开发)依赖项中:
yarn add -D conventional-changelog-conventionalcommits
或
npm i --save-dev conventional-changelog-conventionalcommits
应该可以解决你的问题。
这是包的回购链接。
https://github.com/conventional-changelog/conventional-changelog
我希望这将有助于解决您的问题!
【讨论】:
以上是关于在 Gitlab CI 中运行语义发布时缺少插件的主要内容,如果未能解决你的问题,请参考以下文章
如何使用彼此独立的不同运行器运行 Gitlab CI 作业?