admin管理员组文章数量:1122832
I want to automate the CHANGELOG.md update using nodejs conventional-changelog/standard-version.
I followed this article and from my cli it work as expected, now I want to automate it using GItlab CI pipeline and run the necessary commands when a feature branch is succesfully merged onto the master branch.
Is it possible? If yes, how do I do that? How do I prevent the triggering of an infinite loop of pipelines (since the required commands commit/push onto the master branch)?
I want to automate the CHANGELOG.md update using nodejs conventional-changelog/standard-version.
I followed this article and from my cli it work as expected, now I want to automate it using GItlab CI pipeline and run the necessary commands when a feature branch is succesfully merged onto the master branch.
Is it possible? If yes, how do I do that? How do I prevent the triggering of an infinite loop of pipelines (since the required commands commit/push onto the master branch)?
Share Improve this question edited Nov 21, 2024 at 21:33 fudo asked Nov 21, 2024 at 21:26 fudofudo 2,8727 gold badges27 silver badges67 bronze badges 1- Sounds possible. You should be able to prevent infinity loops using specific rules – Michael Kotzjan Commented Nov 22, 2024 at 18:53
2 Answers
Reset to default 0To prevent pipeline from running on the commits/push use skip ci
eg: chore(release): 1.1.2 [skip ci]
I would suggest you to check out semantic release. This package helps with versioning according to conventional commits, creating/updating changelog and handles the skipping pipeline part as well.
You need to update your packages.json
- My working
packages.json
:
{
"name": "{{ project_key }}",
"version": "{{ project_version }}",
"scripts": {
"release:dry": "semantic-release --dry-run",
"release": "semantic-release"
},
"devDependencies": {
"@commitlint/config-conventional": "^19.5.0",
"@commitlint/prompt-cli": "^19.5.0",
"@semantic-release/changelog": "^6.0.3",
"@semantic-release/commit-analyzer": "^13.0.0",
"@semantic-release/git": "^10.0.1",
"@semantic-release/gitlab": "^13.2.1",
"@semantic-release/npm": "^12.0.1",
"@semantic-release/release-notes-generator": "^14.0.1",
"semantic-release": "^24.1.1"
},
"overrides": {
"conventional-changelog-conventionalcommits": ">= 8.0.0"
},
"private": true,
"release": {
"plugins": [
"@semantic-release/changelog",
"@semantic-release/gitlab",
"@semantic-release/npm",
[
"@semantic-release/commit-analyzer",
{
"releaseRules": [
{
"type": "refactor",
"release": "patch"
},
{
"type": "docs",
"release": "patch"
},
{
"type": "test",
"release": "patch"
},
{
"type": "style",
"release": "patch"
},
{
"type": "ci",
"release": "patch"
},
{
"type": "build",
"release": "patch"
},
{
"type": "revert",
"release": "patch"
},
{
"type": "chore",
"release": "patch"
},
{
"type": "sonar",
"release": "patch"
}
]
}
],
[
"@semantic-release/release-notes-generator",
{
"presetConfig": {
"types": [
{
"type": "sonar",
"section": ":mortar_board: Fixed SonarQube issues",
"hidden": false
},
{
"type": "feat",
"section": ":sparkles: Features",
"hidden": false
},
{
"type": "fix",
"section": ":fire: Bug Fixing",
"hidden": false
},
{
"type": "refactor",
"section": ":zap: Refactoring of code",
"hidden": false
},
{
"type": "perf",
"section": ":gift: Performance Improvements",
"hidden": false
},
{
"type": "revert",
"section": ":cyclone: Reverting of code",
"hidden": false
},
{
"type": "ci",
"section": ":tada: CI/CD",
"hidden": false
},
{
"type": "style",
"section": ":rocket: Style",
"hidden": false
},
{
"type": "test",
"section": ":computer: Tests",
"hidden": false
},
{
"type": "docs",
"section": ":book: Documentation",
"hidden": false
},
{
"type": "chore",
"hidden": true
}
]
}
}
],
[
"@semantic-release/git",
{
"assets": [
"package.json",
"CHANGELOG.md"
],
"message": "chore(Release): ${nextRelease.version} \n\n${nextRelease.notes}"
}
]
],
"branches": [
"main",
{
"name": "dev",
"prerelease": true
}
],
"preset": "conventionalcommits"
}
}
And CI Job
.base_release:
image: node:${NODE_VERSION}
before_script:
- git config --global user.email "${GITLAB_TOKEN_USER}@git.example.com"
- git config --global user.name "${GITLAB_TOKEN_USER}"
- |
{
echo "@${CI_PROJECT_ROOT_NAMESPACE}:registry=${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/npm/"
echo "${CI_API_V4_URL#https?}/projects/${CI_PROJECT_ID}/packages/npm/:_authToken=\${CI_JOB_TOKEN}"
} | tee -a .npmrc
- npm i
release:
extends: .base_release
stage: release
needs:
- job: npm build
optional: true
script:
- git tag -l | xargs git tag -d && git fetch --tags
- npm run release
rules:
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH && $GITLAB_USER_LOGIN != $GITLAB_TOKEN_USER
- if: $CI_COMMIT_BRANCH == 'dev' && $GITLAB_USER_LOGIN != $GITLAB_TOKEN_USER
本文标签:
版权声明:本文标题:Gitlab CI pipeline - update CHANGELOG when feature branch get merged on master and commitpush it - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736307079a1933187.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论