使用私有gitlab发布自动生成版本号和标签(version和tag)(骚)
设置 semantic ,自动生成版本号和标签
FROM node:14-buster-slim LABEL maintainer="wangyunpeng" COPY sources.list /etc/apt/sources.list RUN apt-get update && \ apt-get install -y --no-install-recommends git-core ca-certificates && \ npm install --global \ semantic-release@17.1.1 \ @semantic-release/exec@5.0.0 \ @semantic-release/gitlab@6.0.4 && \ apt-get clean
sources.list
1 # 默认注释了源码镜像以提高 apt update 速度,如有需要可自行取消注释 2 deb http://mirrors.tuna.tsinghua.edu.cn/debian/ buster main contrib non-free 3 # deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ buster main contrib non-free 4 deb http://mirrors.tuna.tsinghua.edu.cn/debian/ buster-updates main contrib non-free 5 # deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ buster-updates main contrib non-free 6 deb http://mirrors.tuna.tsinghua.edu.cn/debian/ buster-backports main contrib non-free 7 # deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ buster-backports main contrib non-free 8 deb http://mirrors.tuna.tsinghua.edu.cn/debian-security buster/updates main contrib non-free 9 # deb-src https://mirrors.tuna.tsinghua.edu.cn/debian-security buster/updates main contrib non-free
创建docker镜像
docker build -f ./Dockerfile -t wangyp/semantic-release:17.1.1 .
Windows 推送景象
docker tag wangyp/semantic-release:17.1.1 localhost:8088/semantic-release:17.1.1 docker login -u docker-push -p 123456 localhost:8088 docker push localhost:8088/semantic-release:17.1.1
docker pull localhost:8089/semantic-release:17.1.1
私有仓库
使用gitlab搭建生成版本号和标签
.releaserc.json
{ "plugins": [ [ "@semantic-release/commit-analyzer", { "preset": "angular", "releaseRules": [ { "type": "refactor", "release": "patch" }, { "type": "style", "release": "patch" }, { "type": "chore", "release": "patch" } ], "parserOpts": { "noteKeywords": [ "BREAKING CHANGE", "BREAKING CHANGES" ] } } ], "@semantic-release/release-notes-generator", "@semantic-release/gitlab", [ "@semantic-release/exec", { "successCmd": "echo \"VERSION=${nextRelease.version}\" >> .version" } ] ] }
.gitlab-ci.yml
variables: # BUILD_VERSION: "test" stages: - publish - version - build publish: stage: publish script: - if [ ! -d ./publish ]; then mkdir ./publish; fi artifacts: name: "${CI_JOB_NAME}-${CI_COMMIT_REF_NAME}" paths: - publish/ expire_in: 1 days only: refs: - branches - merge_requests version: stage: version image: localhost:8089/wangyp/semantic-release:17.1.1 script: - if [ $CI_COMMIT_REF_NAME == 'alpha' -o $CI_COMMIT_REF_NAME == 'master' ]; then semantic-release; fi - if [ ! -f ./.version ]; then echo "VERSION=${BUILD_VERSION:-$(date +%Y%m%d%H%M%S)}">.version; fi - cat .version artifacts: paths: - .version expire_in: 1 days needs: - job: publish artifacts: false rules: - if: "$CI_PIPELINE_SOURCE == 'merge_request_event'" when: never - if: "$CI_COMMIT_REF_NAME == 'dev'" when: on_success - if: "$CI_COMMIT_REF_NAME == 'alpha'" when: on_success - if: "$CI_COMMIT_REF_NAME == 'master'" when: on_success - if: "$CI_COMMIT_REF_NAME =~ /.*-bug-fix/" when: on_success build: stage: build image: "docker:stable" services: - docker:stable-dind variables: DOCKER_TLS_CERTDIR: "" script: - source ./.version - cat .version - if [ ! -d ./build ]; then mkdir ./build; fi - exit needs: - job: version artifacts: true - job: publish artifacts: true artifacts: name: "${CI_JOB_NAME}-${CI_COMMIT_REF_NAME}" paths: - build/ expire_in: 1 days rules: - if: "$CI_PIPELINE_SOURCE == 'merge_request_event'" when: never - if: "$CI_COMMIT_REF_NAME == 'dev'" when: on_success - if: "$CI_COMMIT_REF_NAME == 'alpha'" when: on_success - if: "$CI_COMMIT_REF_NAME == 'master'" when: on_success - if: "$CI_COMMIT_REF_NAME =~ /.*-bug-fix/" when: on_success
查看版本号
自动打标签生成文档:
代码仓没有相关信息的更改,因此没有生成新的版本号和标签。报错内容:
There are no relevant changes, so no new version is released.
所谓相关信息说的是,提交分析器只有存在feat或fix类型的提交信息时才会考虑生成新版本。所以,git提交时需要写上feat或fix的注释信息才能生成版本号和标签信息。
无法生成语音文档报错:
解决方法:
管理面板->设置->CI/CD:
GITLAB_TOKEN