Tag Release #10
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Tag Release | |
| # 一键发版入口(借鉴 byte-code tag.yml):无需本地查 tag/打 tag——版本号由 | |
| # git-cliff 按提交语义自动推导(有 feat → minor,仅 fix/chore → patch), | |
| # 也支持显式指定。tag 推送后自动触发 release.yml 完成构建与发布。 | |
| # 前置约定:提交遵循 conventional commits(feat/fix/chore/...)。 | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| version: | |
| description: '版本号:留空=自动推导;或填 patch/minor/major 强制档位;或直接给完整版本号如 1.2.0(不带 v)' | |
| required: false | |
| default: '' | |
| permissions: | |
| contents: write | |
| actions: write # gh workflow run dispatch Release 需要(仅 contents 不够) | |
| jobs: | |
| tag: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 # cliff 推导需要全历史与全部 tag | |
| fetch-tags: true | |
| persist-credentials: true | |
| - name: Install git-cliff | |
| uses: taiki-e/install-action@v2 | |
| with: | |
| tool: git-cliff | |
| - name: Resolve next version | |
| id: ver | |
| run: | | |
| INPUT="${{ github.event.inputs.version }}" | |
| if [ -z "$INPUT" ]; then | |
| # 按提交语义自动推导 | |
| V=$(git-cliff --bumped-version 2>/dev/null | tr -d '[:space:]') | |
| elif echo "$INPUT" | grep -qE '^(patch|minor|major)$'; then | |
| V=$(git-cliff --bump "$INPUT" --bumped-version | tr -d '[:space:]') | |
| else | |
| V="$INPUT" | |
| fi | |
| if [ -z "$V" ]; then | |
| echo "无法确定版本号(可能是首个 tag,请显式填写 version)" && exit 1 | |
| fi | |
| # git-cliff 部分版本输出带 v 前缀,统一剥掉防拼出 vv* | |
| V=${V#v} | |
| # 防 dedup:目标 tag 已存在则拒绝 | |
| if git rev-parse "v$V" >/dev/null 2>&1; then | |
| echo "tag v$V 已存在,拒绝重复发版" && exit 1 | |
| fi | |
| echo "VERSION=$V" >> $GITHUB_OUTPUT | |
| echo "下一版本:v$V" | |
| # Cargo.toml 的 version 必须与 tag 同步(binstall 从 git HEAD 的 | |
| # Cargo.toml 解析版本决定下载哪个 release——不 bump 会永远装旧版)。 | |
| # 先提交 bump 再打 tag,tag 指向 bump 提交。 | |
| - name: Bump Cargo.toml and tag | |
| run: | | |
| V="${{ steps.ver.outputs.VERSION }}" | |
| sed -i "s/^version = \".*\"/version = \"$V\"/" Cargo.toml | |
| git config user.name "release-bot" | |
| git config user.email "release-bot@users.noreply.github.com" | |
| git commit -am "chore(release): bump version to $V" | |
| git push origin HEAD:master | |
| git tag -a "v$V" -m "release v$V" | |
| git push origin "v$V" | |
| # GITHUB_TOKEN 推送的 tag 不会触发其他工作流(防递归限制,workflow_dispatch 除外) | |
| # ——必须在此显式 dispatch Release | |
| - name: Trigger Release workflow | |
| env: | |
| GH_TOKEN: ${{ github.token }} | |
| run: | | |
| sleep 5 # 等 tag 推送传播 | |
| gh workflow run Release --ref master \ | |
| -f tag="v${{ steps.ver.outputs.VERSION }}" \ | |
| -f version="${{ steps.ver.outputs.VERSION }}" | |
| echo "Release 工作流已触发(v${{ steps.ver.outputs.VERSION }})" |