使用私有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
Dockerfile
复制代码

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
sources.list
复制代码

创建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"
        }
      ]
    ]
  }
  
.releaserc.json
复制代码

.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
.gitlab-ci.yml
复制代码

查看版本号

 

自动打标签生成文档:


代码仓没有相关信息的更改,因此没有生成新的版本号和标签。报错内容:

There are no relevant changes, so no new version is released.

所谓相关信息说的是,提交分析器只有存在featfix类型的提交信息时才会考虑生成新版本。所以,git提交时需要写上feat或fix的注释信息才能生成版本号和标签信息。

无法生成语音文档报错:

解决方法:

https://github.com/semantic-release/semantic-release/blob/master/docs/usage/ci-configuration.md#authentication

 

 

 

 

管理面板->设置->CI/CD:

 

GITLAB_TOKEN

 

 

posted @   —八戒—  阅读(6404)  评论(0编辑  收藏  举报
编辑推荐:
· AI与.NET技术实操系列:基于图像分类模型对图像进行分类
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
阅读排行:
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 25岁的心里话
· 按钮权限的设计及实现
历史上的今天:
2015-09-18 Python的包管理工具Pip
点击右上角即可分享
微信分享提示