Tag Release #1
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 | |
| 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 | |
| # 防 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" | |
| - name: Create and push tag | |
| run: | | |
| git config user.name "release-bot" | |
| git config user.email "release-bot@users.noreply.github.com" | |
| git tag -a "v${{ steps.ver.outputs.VERSION }}" -m "release v${{ steps.ver.outputs.VERSION }}" | |
| git push origin "v${{ steps.ver.outputs.VERSION }}" |