mcpField
R
release-automation-builder

release-automation-builder

github.com/patricio0312rev云与 DevOps63252 次安装41 周前更新
代码仓库

关于 release-automation-builder

release-automation-builder 是用于配置软件自动发布的技能,涵盖版本管理、变更日志、发布说明和发布流程,可采用 Changesets 或 semantic-release。

主要功能

  1. 01配置 Changesets 或 semantic-release
  2. 02采用 SemVer 和 Conventional Commits
  3. 03自动生成变更日志和发布说明
  4. 04发布 NPM 包和 Docker 镜像
  5. 05自动创建 Git 标签和 GitHub Release

适用场景

  1. 01设置由 main 触发的发布流程
  2. 02测试通过后发布 NPM 包
  3. 03创建带版本号的 Docker 镜像发布

安装

复制下面的命令,在终端中运行。

$npx skills add https://github.com/patricio0312rev/skills --skill release-automation-builder

安装后在 Claude Code 中输入/release-automation-builder确认已加载。

详细介绍

发布自动化构建器

通过版本管理、变更日志和发布流程实现自动化。

使用 Changesets

设置
npm install -D @changesets/cli
npx changeset init
工作流
# .github/workflows/release.yml
name: Release

on:
  push:
    branches:
      - main

concurrency: ${{ github.workflow }}-${{ github.ref }}

jobs:
  release:
    name: Release
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
        with:
          fetch-depth: 0

      - uses: actions/setup-node@v4
        with:
          node-version: "20"
          cache: "npm"

      - run: npm ci

      - name: Create Release Pull Request or Publish
        uses: changesets/action@v1
        with:
          publish: npm run release
          commit: "chore: release packages"
          title: "chore: release packages"
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
包脚本
{
  "scripts": {
    "changeset": "changeset",
    "version": "changeset version",
    "release": "changeset publish"
  }
}

使用 Semantic Release

配置
// .releaserc.js
module.exports = {
  branches: ["main"],
  plugins: [
    "@semantic-release/commit-analyzer",
    "@semantic-release/release-notes-generator",
    "@semantic-release/changelog",
    "@semantic-release/npm",
    "@semantic-release/github",
    [
      "@semantic-release/git",
      {
        assets: ["CHANGELOG.md", "package.json"],
        message:
          "chore(release): ${nextRelease.version} [skip ci]\n\n${nextRelease.notes}",
      },
    ],
  ],
};
工作流
# .github/workflows/release.yml
name: Release

on:
  push:
    branches: [main]

jobs:
  release:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
        with:
          persist-credentials: false

      - uses: actions/setup-node@v4
        with:
          node-version: "20"

      - run: npm ci
      - run: npm run build

      - name: Release
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
        run: npx semantic-release

版本管理策略

语义化版本(SemVer)
MAJOR.MINOR.PATCH

1.0.0 → 1.0.1  (patch - bug fix)
1.0.1 → 1.1.0  (minor - new feature)
1.1.0 → 2.0.0  (major - breaking change)
约定式提交
feat: add new feature (minor bump)
fix: fix bug (patch bump)
perf: performance improvement (patch bump)
docs: update docs (no bump)
chore: maintenance (no bump)

feat!: breaking change (major bump)
fix!: breaking bug fix (major bump)

变更日志生成

# Changelog

## [2.1.0] - 2024-01-15

### Added

- New dashboard widget (#123)
- Export to PDF feature (#125)

### Fixed

- Memory leak in data processing (#124)
- Typo in error message (#126)

### Changed

- Updated dependencies

## [2.0.0] - 2024-01-01

### Breaking Changes

- Removed deprecated API endpoints
- Changed authentication method

### Migration Guide

See MIGRATION.md for upgrade instructions

Docker 镜像发布

docker-release:
  runs-on: ubuntu-latest
  needs: test
  if: github.ref == 'refs/heads/main'
  steps:
    - uses: actions/checkout@v4

    - name: Get version
      id: version
      run: echo "version=$(cat package.json | jq -r '.version')" >> $GITHUB_OUTPUT

    - name: Login to Docker Hub
      uses: docker/login-action@v3
      with:
        username: ${{ secrets.DOCKER_USERNAME }}
        password: ${{ secrets.DOCKER_PASSWORD }}

    - name: Build and push
      uses: docker/build-push-action@v5
      with:
        context: .
        push: true
        tags: |
          mycompany/myapp:latest
          mycompany/myapp:${{ steps.version.outputs.version }}

NPM 发布

publish:
  runs-on: ubuntu-latest
  needs: test
  if: github.event_name == 'release'
  steps:
    - uses: actions/checkout@v4
    - uses: actions/setup-node@v4
      with:
        node-version: "20"
        registry-url: "https://registry.npmjs.org"

    - run: npm ci
    - run: npm run build

    - name: Publish to npm
      run: npm publish
      env:
        NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

GitHub 发布说明

- name: Create GitHub Release
  uses: actions/create-release@v1
  env:
    GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
  with:
    tag_name: v${{ steps.version.outputs.version }}
    release_name: Release ${{ steps.version.outputs.version }}
    body: |
      ## What's Changed
      ${{ steps.changelog.outputs.content }}

      ## Installation
      ```bash
      npm install mypackage@${{ steps.version.outputs.version }}
      ```
    draft: false
    prerelease: false

最佳实践

  1. 约定式提交:统一提交格式
  2. 受保护的分支:阻止直接推送到 main
  3. 自动版本管理:让工具确定版本号
  4. 变更日志:根据提交自动生成
  5. Git 标签:为每次发布打标签
  6. 发布说明:包含迁移指南
  7. 试运行:在预发布环境中测试发布

输出检查清单

  • 已配置 Changesets 或 semantic-release
  • 已记录版本管理策略
  • 已实现变更日志自动生成
  • 已实现 Git 标签自动创建
  • 已准备发布说明模板
  • 已配置 NPM 发布(如果是包)
  • 已配置 Docker 发布(如适用)
  • 已设置受保护的分支规则

评论

支持 Markdown