chore: prepare v2.2.0 release
测试构建 / 代码检查 (push) Has been cancelled
测试构建 / 单元测试和构建 (push) Has been cancelled
测试构建 / 构建验证 (push) Has been cancelled

This commit is contained in:
ZacharyZcR
2026-07-09 20:41:10 +08:00
parent 075bf646dc
commit fdf836f003
9 changed files with 236 additions and 29 deletions
+79 -2
View File
@@ -2,6 +2,8 @@ name: 发布
on:
push:
branches:
- main
tags:
- 'v*'
workflow_dispatch:
@@ -22,7 +24,60 @@ env:
FORCE_JAVASCRIPT_ACTIONS_TO_NODE24: true
jobs:
auto-tag:
if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }}
runs-on: ubuntu-latest
timeout-minutes: 5
outputs:
tag: ${{ steps.version.outputs.tag }}
steps:
- name: 检出代码
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: 读取版本号
id: version
shell: bash
run: |
VERSION=$(sed -n 's/^[[:space:]]*version = "\(.*\)"/\1/p' common/globals.go)
if [ -z "$VERSION" ]; then
echo "❌ 无法从 common/globals.go 读取版本号"
exit 1
fi
TAG="v${VERSION}"
echo "version=${VERSION}" >> "$GITHUB_OUTPUT"
echo "tag=${TAG}" >> "$GITHUB_OUTPUT"
echo "准备发布 ${TAG}"
- name: 创建发布标签
shell: bash
run: |
TAG="${{ steps.version.outputs.tag }}"
if git ls-remote --exit-code --tags origin "refs/tags/${TAG}" >/tmp/tag-ref 2>/dev/null; then
git fetch --force origin "refs/tags/${TAG}:refs/tags/${TAG}"
TAG_COMMIT=$(git rev-list -n 1 "${TAG}")
HEAD_COMMIT=$(git rev-parse HEAD)
if [ "$TAG_COMMIT" = "$HEAD_COMMIT" ]; then
echo "✅ ${TAG} 已指向当前提交,跳过创建"
exit 0
fi
echo "❌ ${TAG} 已存在,但不指向当前提交"
echo "tag: ${TAG_COMMIT}"
echo "head: ${HEAD_COMMIT}"
exit 1
fi
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git tag -a "${TAG}" -m "Release ${TAG}"
git push origin "${TAG}"
release:
needs: [auto-tag]
if: ${{ always() && (startsWith(github.ref, 'refs/tags/') || github.event_name == 'workflow_dispatch' || (github.event_name == 'push' && github.ref == 'refs/heads/main' && needs.auto-tag.result == 'success')) }}
runs-on: ubuntu-latest
timeout-minutes: 90
@@ -32,10 +87,32 @@ jobs:
with:
fetch-depth: 0
- name: 解析发布标签
id: release_tag
shell: bash
env:
AUTO_TAG: ${{ needs.auto-tag.outputs.tag }}
SNAPSHOT: ${{ inputs.snapshot }}
run: |
if [[ "${GITHUB_REF}" == refs/tags/* ]]; then
TAG="${GITHUB_REF_NAME}"
elif [ "${GITHUB_EVENT_NAME}" = "push" ] && [ "${GITHUB_REF}" = "refs/heads/main" ]; then
TAG="${AUTO_TAG}"
git fetch --force origin "refs/tags/${TAG}:refs/tags/${TAG}"
elif [ "${GITHUB_EVENT_NAME}" = "workflow_dispatch" ] && [ "${SNAPSHOT}" = "true" ]; then
TAG="${GITHUB_REF_NAME}"
else
echo "❌ 非 snapshot 手动发布必须从 tag 触发"
exit 1
fi
echo "tag=${TAG}" >> "$GITHUB_OUTPUT"
echo "RELEASE_TAG=${TAG}" >> "$GITHUB_ENV"
- name: 准备 Release Notes
if: ${{ !inputs.snapshot }}
run: |
TAG="${GITHUB_REF_NAME}"
TAG="${RELEASE_TAG}"
NOTES_FILE=".github/release-notes/${TAG}.md"
if [ -f "$NOTES_FILE" ]; then
@@ -61,7 +138,7 @@ jobs:
env:
GH_TOKEN: ${{ github.token }}
run: |
TAG="${GITHUB_REF_NAME}"
TAG="${RELEASE_TAG}"
NOTES_FILE="${RELEASE_NOTES_FILE}"
if [ -s "$NOTES_FILE" ]; then