release-automation-builder

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Release Automation Builder

版本发布自动化构建工具

Automate releases with versioning, changelogs, and publishing.
实现版本发布全流程自动化,涵盖版本管理、变更日志生成及包发布。

Using Changesets

使用Changesets

Setup

配置步骤

bash
npm install -D @changesets/cli
npx changeset init
bash
npm install -D @changesets/cli
npx changeset init

Workflow

工作流

yaml
undefined
yaml
undefined

.github/workflows/release.yml

.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 }}
undefined
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 }}
undefined

Package Scripts

包脚本配置

json
{
  "scripts": {
    "changeset": "changeset",
    "version": "changeset version",
    "release": "changeset publish"
  }
}
json
{
  "scripts": {
    "changeset": "changeset",
    "version": "changeset version",
    "release": "changeset publish"
  }
}

Using Semantic Release

使用Semantic Release

Configuration

配置

javascript
// .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}",
      },
    ],
  ],
};
javascript
// .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}",
      },
    ],
  ],
};

Workflow

工作流

yaml
undefined
yaml
undefined

.github/workflows/release.yml

.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
undefined
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
undefined

Versioning Strategy

版本管理策略

Semantic Versioning (SemVer)

语义化版本控制(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)
MAJOR.MINOR.PATCH

1.0.0 → 1.0.1  (补丁版本 - 修复bug)
1.0.1 → 1.1.0  (小版本 - 新增功能)
1.1.0 → 2.0.0  (主版本 - 破坏性变更)

Conventional Commits

规范化提交格式

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)
feat: 新增功能(小版本升级)
fix: 修复bug(补丁版本升级)
perf: 性能优化(补丁版本升级)
docs: 更新文档(不升级版本)
chore: 日常维护(不升级版本)

feat!: 破坏性变更(主版本升级)
fix!: 涉及破坏性变更的bug修复(主版本升级)

Changelog Generation

变更日志生成

markdown
undefined
markdown
undefined

Changelog

Changelog

[2.1.0] - 2024-01-15

[2.1.0] - 2024-01-15

Added

Added

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

Fixed

Fixed

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

Changed

Changed

  • Updated dependencies
  • Updated dependencies

[2.0.0] - 2024-01-01

[2.0.0] - 2024-01-01

Breaking Changes

Breaking Changes

  • Removed deprecated API endpoints
  • Changed authentication method
  • Removed deprecated API endpoints
  • Changed authentication method

Migration Guide

Migration Guide

See MIGRATION.md for upgrade instructions
undefined
See MIGRATION.md for upgrade instructions
undefined

Docker Image Publishing

Docker镜像发布

yaml
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 }}
yaml
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 Publishing

NPM包发布

yaml
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 }}
yaml
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 Release Notes

GitHub发布说明

yaml
- 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
yaml
- 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

Best Practices

最佳实践

  1. Conventional commits: Standardize commit format
  2. Protected branches: Prevent direct pushes to main
  3. Automated versioning: Let tools determine versions
  4. Changelogs: Auto-generate from commits
  5. Git tags: Tag every release
  6. Release notes: Include migration guides
  7. Dry run: Test releases in staging
  1. 规范化提交格式:统一提交信息格式
  2. 分支保护:禁止直接向主分支推送代码
  3. 自动化版本管理:由工具自动判定版本号
  4. 变更日志:从提交信息自动生成
  5. Git标签:为每个版本打标签
  6. 发布说明:包含迁移指南
  7. 预演运行:在 staging 环境测试发布流程

Output Checklist

交付检查清单

  • Changesets or semantic-release configured
  • Versioning strategy documented
  • Changelog generation automated
  • Git tagging automated
  • Release notes template
  • NPM publishing (if package)
  • Docker publishing (if applicable)
  • Protected branch rules
  • 已配置Changesets或semantic-release
  • 已记录版本管理策略
  • 已实现变更日志自动化生成
  • 已实现Git标签自动化创建
  • 已准备发布说明模板
  • 已配置NPM包发布(若涉及包)
  • 已配置Docker镜像发布(若适用)
  • 已设置分支保护规则