From 0806b4e69f4e1b143be6b8e93ce64751987d7ec7 Mon Sep 17 00:00:00 2001 From: MCNeteaseDevs Date: Wed, 25 Mar 2026 18:48:27 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E8=87=AA=E5=8A=A8=E5=90=8C?= =?UTF-8?q?=E6=AD=A5=20GitHub=20Actions=20=E5=B7=A5=E4=BD=9C=E6=B5=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/sync.yml | 59 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 .github/workflows/sync.yml diff --git a/.github/workflows/sync.yml b/.github/workflows/sync.yml new file mode 100644 index 0000000..c2eca77 --- /dev/null +++ b/.github/workflows/sync.yml @@ -0,0 +1,59 @@ +# GitHub Actions 工作流 +# 检测到 sync-* 标签时自动推送代码到 main 分支 + +name: Auto Push on Tag + +on: + push: + tags: + - 'sync-*' + +jobs: + push-code: + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + with: + fetch-depth: 0 + token: ${{ secrets.GITHUB_TOKEN }} + + - name: Get tag info + id: tag_info + run: | + TAG_NAME=${GITHUB_REF#refs/tags/} + COMMIT_SHA=$(git rev-list -n 1 $TAG_NAME) + echo "tag_name=$TAG_NAME" >> $GITHUB_OUTPUT + echo "commit_sha=$COMMIT_SHA" >> $GITHUB_OUTPUT + echo "🏷️ Tag: $TAG_NAME" + echo "📝 Commit: $COMMIT_SHA" + + - name: Push commit to main + run: | + git config user.name "github-actions[bot]" + git config user.email "github-actions[bot]@users.noreply.github.com" + + # 获取标签指向的 commit + TAG_COMMIT=${{ steps.tag_info.outputs.commit_sha }} + + # 切换到 main 分支 + git checkout main + + # 检查 main 是否已经包含这个 commit + if git merge-base --is-ancestor $TAG_COMMIT HEAD; then + echo "✓ main 分支已包含此 commit,无需推送" + else + # 将 commit 合并到 main + git merge $TAG_COMMIT --no-edit + git push origin main + echo "✓ 已推送到 main 分支" + fi + + - name: Summary + run: | + echo "## 同步完成 ✅" >> $GITHUB_STEP_SUMMARY + echo "" >> $GITHUB_STEP_SUMMARY + echo "- **标签**: ${{ steps.tag_info.outputs.tag_name }}" >> $GITHUB_STEP_SUMMARY + echo "- **Commit**: ${{ steps.tag_info.outputs.commit_sha }}" >> $GITHUB_STEP_SUMMARY + echo "- **时间**: $(date)" >> $GITHUB_STEP_SUMMARY