diff --git a/.gitea/workflows/release.yml b/.gitea/workflows/release.yml index 822db09..51d970b 100644 --- a/.gitea/workflows/release.yml +++ b/.gitea/workflows/release.yml @@ -15,8 +15,6 @@ jobs: - name: Auto-tag from merged PR id: autotag run: | - set -e - # 已有标签 → 跳过 EXISTING=$(git tag --points-at HEAD | grep '^v' | head -n1) if [ -n "$EXISTING" ]; then @@ -25,7 +23,7 @@ jobs: exit 0 fi - # 非 merge commit → 跳过(直接 push 不处理) + # 非 merge commit → 跳过 PARENTS=$(git log --format="%P" -1 | wc -w) if [ "$PARENTS" -lt 2 ]; then echo "Not a merge commit, skip auto-tag" @@ -34,7 +32,7 @@ jobs: # 从 merge commit message 提取 PR 号 COMMIT_MSG=$(git log --format="%B" -1) - PR_NUM=$(echo "$COMMIT_MSG" | grep -oP '#\K\d+' | head -1) + PR_NUM=$(echo "$COMMIT_MSG" | grep -oP '#\K\d+' | head -1) || true if [ -z "$PR_NUM" ]; then echo "No PR number found in merge message" exit 0 @@ -55,16 +53,22 @@ jobs: VERSION="$PR_BODY" echo "Found version: $VERSION" - # 创建本地标签 + # 检查远端是否已有此标签 + if git ls-remote --tags origin "$VERSION" 2>/dev/null | grep -q .; then + echo "Tag $VERSION already exists on remote, skipping push" + git tag "$VERSION" 2>/dev/null || true + echo "tag=$VERSION" >> "$GITHUB_OUTPUT" + exit 0 + fi + + # 创建并推送标签 git config user.email "ci@datarouter" git config user.name "DataRouter CI" git tag -a "$VERSION" -m "Release $VERSION" echo "Created local tag: $VERSION" - # 推送到远端(不会触发本 workflow — 仅匹配 branches: [main]) - ORIGIN=$(git config --get remote.origin.url) - PUSH_URL="https://oauth2:${TOKEN}@${ORIGIN#https://}" - git push "$PUSH_URL" "$VERSION" + # 使用 origin remote(actions/checkout 已配置好认证) + git push origin "$VERSION" 2>&1 echo "Pushed tag: $VERSION" echo "tag=$VERSION" >> "$GITHUB_OUTPUT"