2.0.2 • Published 9 months ago

@wx-sab/fe-devops-tools v2.0.2

Weekly downloads
-
License
ISC
Repository
-
Last release
9 months ago

@wx-sab/fe-devops-tools

前端项目发布插件

Features

  • 自动创建版本
  • 自动发布对应环境
  • 遵循 git 工作流
  • drone 版本号动态传递
  • 同一镜像多环境发布

TODOS:

  • 消息通知: 合并失败、构建失败、发布失败

使用

安装

pnpm add -D @wx-sab/fe-devops-tools

配置

自动读取 sab-deploy.config.ts 或者 sab-deploy.config.js 或者 sab-deploy.config.json 文件的配置

import { defineConfig } from '@wx-sab/fe-devops-tools'

export default defineConfig({
  // 开发平台对应的项目名
  projectName: string;
  // 开发平台对应的应用名
  appName: string;

  // 开发平台的账号密码
  // 默认 「前端发布专用」账号,14757609802
  accountId: string;
  password: string;

  // 发布的版本号,默认取 package.json的 version
  version: string;
  // 当前的分支
  branch: string;

  // 是否自动创建版本
  autoCreateVersion: boolean;

  // 需要自动发布的环境 Map, 分支 -> 环境
  /** 如下:
   * {
   * dev: "dp-dev",
   * qa: "dp-qa",
   * release: "dp-pre",}
   */
  autoReleaseEnvs: Record<string, string | string[]>;
  
  // 是否遵循 sab-fe 分支规范
  // http://10.101.7.31:10086/doc/23/
  // ../../source/git-flow.png
  enableSabGitFlow?: boolean;

  // 自动合并分支配置
  mergeBranch?: {
    // git 仓库的远程地址,请允许访问
    remote: string;
    // 允许操作远程仓库的 用户名和密码
    username: string;
    password: string;

    // 匹配分支
    matchBranch: {
      // 源分支
      sourceBranchs: string[];
      // 目标分支
      targetBranch: string;
    }
  };
  // 消息推送配置
  notify?: {
    // 暂时只支持钉钉机器人
    type: "dingtalk";
    // 钉钉机器人 token
    ddBotToken: string;
    // 钉钉机器人秘钥, 机器人安全设置页面,加签一栏下面显示的SEC开头的字符串
    ddBotSecret: string
  };
})

环境变量

变量名说明默认值
DEVOPS_PLATFORM_ACCOUNTID开发平台用户名
DEVOPS_PLATFOEM_PASSWORD开发平台密码
DEVOPS_GIT_USERNAMEgit用户名(如果需要自动合并功能的话)
DEVOPS_GIT_PASSWORDgit密码(如果需要自动合并功能的话)

指令

校验版本

  npx sab-deploy version-check --branch ${DRONE_BRANCH}

发布版本

  npx sab-deploy release --branch ${DRONE_BRANCH}

合并分支

npx sab-deploy merge-branch --branch ${DRONE_BRANCH}

通知推送

Git 工作流(试运行)

http://10.101.7.31:10086/doc/23/

./source/git-flow.png

约定

  • main/master分支: 主干分支,代码发布上线后需合并回该分支,并打上 tag
  • dev分支: 开发分支,所有当前正在开发的需求可以合到当前分支,会自动发布开发环境
  • qa分支: 测试分支,提供给测试同学进行功能测试的分支,会自动发布到测试环境
  • release分支,最新的可上生产环境的分支,该分支的代码都是经过测试的可靠代码,该分支需手动发布
  • feature/* 分支,需求分支,当有新需求的时候从 release(推荐) 或者 master 新建的分支,在需求结束后合并进release分支,并删除
  • hotfix分支,修复分支,用于解决线上问题的分支,从master分支新建的分支,当验证完毕后合并 release并删除

参考 drone 配置

# 参考配置
kind: pipeline
name: dp-web-next
platform:
  os: linux
  arch: amd64

steps:
  # 自动合并分支
  - name: merge_branch
    image: alpine/git:v2.26.2
    commands:
      - git clone --single-branch -b dev http://oauth2:ERGMy4Wvhh2K2AAESQC8@10.10.255.105/dp/dp-web-next.git
      - cd dp-web-next
      - git remote set-branches origin '*'
      - git fetch origin ${DRONE_COMMIT_BRANCH}
      - git merge --no-ff origin/${DRONE_COMMIT_BRANCH} -m '${DRONE_COMMIT_MESSAGE}'
      - git push origin dev
    volumes:
      - name: drone_home
        path: /root
    when:
      branch:
        - feature/*

  #自动校验版本
  - name: check_version
    image: node:16.18.1-alpine
    commands:
      # - npm config set registry https://registry.npmmirror.com
      - npm install -g pnpm@8
      - pnpm install
      - npx sab-deploy version-check --branch ${DRONE_BRANCH}
    volumes:
      - name: drone_cache
        path: /drone/src/.pnpm-store
    when:
      branch:
        - dev
        - qa
        - release

  # 校验版本
  - name: kmsp_validate
    image: kmsp/kmsp-plugin-drone:1.2.0
    settings:
      method: validate
      debug: true
      server: http://10.10.255.106:12330
    when:
      branch:
        - dev
        - qa
        - release

  # 前端构建
  - name: build
    image: node:16.18.1-alpine
    commands:
      # - npm config set registry https://registry.npmmirror.com
      - npm install -g pnpm@8
      - pnpm install
      - pnpm run build
    volumes:
      - name: drone_cache
        path: /drone/src/.pnpm-store # container path, must be an absolute path(pipeline default working directory is /drone/src https://docs.drone.io/pipeline/docker/syntax/workspace/)
    when:
      branch:
        - dev
        - qa
        - release

  # docker镜像构建
  - name: docker_build
    image: kmsp/docker:18.09
    settings:
      insecure: true
      password:
        from_secret: registry_password
      purge: true
      registry: 10.10.255.105:8000
      repo: 10.10.255.105:8000/kmsp-${DRONE_REPO_NAMESPACE}/${DRONE_REPO_NAME}
      username: admin
    when:
      branch:
        - dev
        - qa
        - release

  # feedback
  - name: kmsp_feedback
    image: kmsp/kmsp-plugin-drone:1.2.0
    settings:
      method: feedback
      server: http://10.10.255.106:12330
    failure: ignore
    when:
      status:
        - failure
        - success

  # 自动发布
  - name: auto-release
    image: node:16.18.1-alpine
    commands:
      # - npm config set registry https://registry.npmmirror.com
      - npm install -g pnpm@8
      - pnpm install
      - npx sab-deploy release --branch ${DRONE_BRANCH}
    volumes:
      - name: drone_cache
        path: /drone/src/.pnpm-store
    when:
      branch:
        - dev
        - qa
        - release

volumes:
  - name: drone_home
    host:
      path: /data/drone/home
  - name: drone_cache
    host:
      path: /data/drone/cache

trigger:
  branch:
    - dev
    - qa
    - release
    - feature/*
  event:
    - push
2.0.2

9 months ago

2.0.1

12 months ago

2.0.0-alpha.7

12 months ago

2.0.0-alpha.8

12 months ago

2.0.0-alpha.3

12 months ago

2.0.0-alpha.4

12 months ago

2.0.0-alpha.5

12 months ago

2.0.0-alpha.6

12 months ago

2.0.0-alpha.1

12 months ago

2.0.0-alpha.2

12 months ago

2.0.0

12 months ago

0.2.7

1 year ago

0.2.6

1 year ago

0.2.5

1 year ago

0.2.4

1 year ago

0.2.3

1 year ago

0.2.2

1 year ago

0.2.1

1 year ago

0.2.0-alpha.1

1 year ago

0.2.0

1 year ago