Skip to content

Release

Release #15

Workflow file for this run

name: Release
on:
workflow_dispatch:
inputs:
version:
type: choice
description: 'Release Version'
required: true
default: 'latest'
options:
- next
- beta
- alpha
- latest
branch:
description: 'Release Branch'
required: true
default: 'main'
issue_comment:
types: [created]
permissions:
contents: write
pull-requests: write
id-token: write
concurrency: ${{ github.workflow }}-${{ github.ref }}
jobs:
release:
name: Release
if: github.event_name == 'workflow_dispatch' || github.event.comment.body == '/release'
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 25
ref: ${{ github.event.inputs.branch || github.ref }}
- name: Setup Rust
uses: dtolnay/rust-toolchain@stable
- name: Install wasm-pack
run: curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh
- name: Install pnpm
run: corepack enable
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 24 # npm OIDC requires CLI 11.5.1+
cache: 'pnpm'
registry-url: 'https://registry.npmjs.org'
- name: Install Dependencies
run: pnpm install
- name: Build @veaba/qrcode-js-shared
run: pnpm --filter @veaba/qrcode-js-shared build
- name: Build @veaba/qrcode-wasm
run: pnpm --filter @veaba/qrcode-wasm build
- name: Build @veaba/qrcode-js
run: pnpm --filter @veaba/qrcode-js build
- name: Build @veaba/qrcode-node
run: pnpm --filter @veaba/qrcode-node build
- name: Build @veaba/qrcode-bun
run: pnpm --filter @veaba/qrcode-bun build
# ========================================
# Publish Rust Crates to crates.io
# ========================================
# 注意:需要在 GitHub Secrets 中配置 CARGO_REGISTRY_TOKEN
# 从 https://crates.io/settings/tokens 获取并添加到仓库 Secrets
#
# 发布顺序(依赖关系):
# 1. qrcode-rust-shared (基础库,无依赖)
# 2. qrcode-rust, qrcode-fast (都依赖 qrcode-rust-shared)
#
# 本地测试 --dry-run 命令:
# cargo publish -p qrcode-rust-shared --dry-run --registry crates-io
# cargo publish -p qrcode-rust --dry-run --registry crates-io
# cargo publish -p qrcode-fast --dry-run --registry crates-io
#
# 注意:首次发布时,qrcode-rust 和 qrcode-fast 的 --dry-run 会失败,
# 因为 qrcode-rust-shared 还没发布到 crates.io。这是正常的。
# Step 1: 发布基础库 qrcode-rust-shared
- name: Publish qrcode-rust-shared to crates.io
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
run: |
echo "📦 Publishing qrcode-rust-shared..."
cargo publish -p qrcode-rust-shared --token "$CARGO_REGISTRY_TOKEN"
echo "✅ qrcode-rust-shared published successfully"
# Step 2: 等待 crates.io 索引更新(通常需要 30-60 秒)
- name: Wait for crates.io index update
run: |
echo "⏳ Waiting for crates.io index to update..."
sleep 60
echo "✅ Proceeding with dependent crates"
# Step 3: 发布依赖库(并行但带重试)
- name: Publish qrcode-rust to crates.io
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
run: |
echo "📦 Publishing qrcode-rust..."
# 如果失败,等待后重试(处理索引延迟)
for i in 1 2 3; do
if cargo publish -p qrcode-rust --token "$CARGO_REGISTRY_TOKEN"; then
echo "✅ qrcode-rust published successfully"
exit 0
fi
echo "⚠️ Attempt $i failed, waiting 30s for index update..."
sleep 30
done
echo "❌ Failed to publish qrcode-rust after 3 attempts"
exit 1
continue-on-error: true
- name: Publish qrcode-fast to crates.io
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
run: |
echo "📦 Publishing qrcode-fast..."
# 如果失败,等待后重试(处理索引延迟)
for i in 1 2 3; do
if cargo publish -p qrcode-fast --token "$CARGO_REGISTRY_TOKEN"; then
echo "✅ qrcode-fast published successfully"
exit 0
fi
echo "⚠️ Attempt $i failed, waiting 30s for index update..."
sleep 30
done
echo "❌ Failed to publish qrcode-fast after 3 attempts"
exit 1
continue-on-error: true
- name: Create Release Pull Request or Publish
uses: changesets/action@v1
with:
version: pnpm ci:version
publish: pnpm ci:publish
commit: "chore: version packages"
title: "chore: version packages"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# 注意:使用 OIDC 认证,不需要 NODE_AUTH_TOKEN
# 确保在 npmjs.com 上为每个包配置了 Trusted Publisher:
# https://www.npmjs.com/package/@veaba/xxx/access
# Publisher 配置: org=veaba, repo=qrcodes, workflow=release.yml