From efcdf5026be3f06c4556a87942a009fbd4189296 Mon Sep 17 00:00:00 2001 From: Zerui Yang Date: Thu, 2 Oct 2025 15:09:17 +0800 Subject: [PATCH 1/8] feat: add GitHub Actions workflow for automatic upstream sync add GitHub Actions workflow for automatic upstream sync --- .github/workflows/sync-to-upstream.yml | 231 +++++++++++++++++++++++++ 1 file changed, 231 insertions(+) create mode 100644 .github/workflows/sync-to-upstream.yml diff --git a/.github/workflows/sync-to-upstream.yml b/.github/workflows/sync-to-upstream.yml new file mode 100644 index 000000000..634f750d9 --- /dev/null +++ b/.github/workflows/sync-to-upstream.yml @@ -0,0 +1,231 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# + +name: Sync to Apache Upstream + +# This workflow automatically creates a PR to apache/dubbo-go-pixiu +# when a PR is merged into the develop branch of this repository. +# +# Prerequisites: +# - Configure the UPSTREAM_GITHUB_TOKEN secret in repository settings +# - Token should have 'public_repo' permission +# - Recommended: use a dedicated bot account for the token + +on: + pull_request: + types: [closed] + branches: + - develop + +# Explicit permissions required for gh pr comment and gh issue create +permissions: + contents: read + pull-requests: write + issues: write + +# Prevent concurrent syncs to avoid conflicts +concurrency: + group: sync-to-upstream + cancel-in-progress: false + +jobs: + sync-to-apache: + name: Sync to Apache Repository + runs-on: ubuntu-latest + + # Only run when PR is actually merged (not just closed) + if: github.event.pull_request.merged == true + + steps: + # Step 1: Checkout code with full history + - name: Checkout repository + uses: actions/checkout@v5 + with: + fetch-depth: 0 + ref: develop + token: ${{ secrets.UPSTREAM_GITHUB_TOKEN }} + + # Step 2: Configure Git user + - name: Configure Git user + run: | + git config user.name "Pixiu Bot" + git config user.email "bot@dubbo-go-pixiu.github.io" + + # Step 3: Add upstream remote and fetch + - name: Add upstream remote + run: | + git remote add upstream https://github.com/apache/dubbo-go-pixiu.git + git fetch upstream develop + + # Step 4: Create sync branch with timestamp + - name: Create sync branch + id: create_branch + run: | + SYNC_BRANCH="auto-sync-$(date +%Y%m%d-%H%M%S)" + echo "SYNC_BRANCH=${SYNC_BRANCH}" >> $GITHUB_ENV + git checkout -b ${SYNC_BRANCH} + echo "branch=${SYNC_BRANCH}" >> $GITHUB_OUTPUT + + # Step 5: Rebase onto upstream develop + - name: Rebase onto upstream + id: rebase + run: | + git rebase upstream/develop + + # Step 5.5: Remove B-repo specific files + - name: Remove fork-specific workflow files + run: | + # Remove sync workflow files that are specific to B-repo + # These should not be synced to Apache upstream + git rm -f .github/workflows/sync-to-upstream.yml || true + git rm -f .github/workflows/SYNC_WORKFLOW_GUIDE.md || true + + # Commit the removal if there are changes + if ! git diff --cached --quiet; then + git commit -m "chore: remove fork-specific workflow files + + These files are specific to dubbo-go-pixiu/dubbo-go-pixiu organization fork + and are not needed in the upstream Apache repository. + + Files removed: + - .github/workflows/sync-to-upstream.yml + - .github/workflows/SYNC_WORKFLOW_GUIDE.md" + fi + + # Step 6: Push sync branch to origin + - name: Push sync branch + run: | + git push origin ${SYNC_BRANCH} --force-with-lease + + # Step 7: Generate PR body with attribution + - name: Generate PR description + id: pr_body + env: + ORIGINAL_BODY: ${{ github.event.pull_request.body }} + run: | + ORIGINAL_AUTHOR="${{ github.event.pull_request.user.login }}" + ORIGINAL_PR="${{ github.event.pull_request.number }}" + ORIGINAL_URL="${{ github.event.pull_request.html_url }}" + MERGED_AT="$(date -u +"%Y-%m-%d %H:%M:%S UTC")" + + { + echo "## 🔄 Upstream Sync from Community Fork" + echo "" + echo "This PR automatically syncs changes from the community fork to the Apache upstream repository." + echo "" + echo "### Original Contribution" + echo "" + echo "- **Author**: @${ORIGINAL_AUTHOR}" + echo "- **Original PR**: ${ORIGINAL_URL}" + echo "- **Merged at**: ${MERGED_AT}" + echo "" + echo "### Original PR Description" + echo "" + echo "---" + echo "" + echo "${ORIGINAL_BODY}" + echo "" + echo "---" + echo "" + echo "### Commit Details" + echo "" + echo "All commits in this PR preserve the original authorship. You can verify this by checking the commit history." + echo "" + echo "**Note**: This PR was automatically created by GitHub Actions when PR #${ORIGINAL_PR} was merged into \`dubbo-go-pixiu/dubbo-go-pixiu:develop\`." + echo "" + echo "cc @${ORIGINAL_AUTHOR}" + } > pr_body.md + + echo "Generated PR body" + + # Step 8: Create PR to Apache upstream + - name: Create PR to apache/dubbo-go-pixiu + id: create_pr + env: + GH_TOKEN: ${{ secrets.UPSTREAM_GITHUB_TOKEN }} + SYNC_PR_TITLE: ${{ github.event.pull_request.title }} + run: | + PR_URL=$(gh pr create \ + --repo apache/dubbo-go-pixiu \ + --base develop \ + --head dubbo-go-pixiu:${SYNC_BRANCH} \ + --title "$SYNC_PR_TITLE" \ + --body-file pr_body.md) + + echo "pr_url=${PR_URL}" >> $GITHUB_OUTPUT + echo "✅ Successfully created PR: ${PR_URL}" + + # Step 9: Comment on original PR with upstream PR link + - name: Notify original PR + if: success() + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + PR_NUMBER: ${{ github.event.pull_request.number }} + UPSTREAM_PR_URL: ${{ steps.create_pr.outputs.pr_url }} + run: | + # Generate comment body and post to original PR + { + echo "🤖 **Automated Upstream Sync**" + echo "" + echo "Your PR has been automatically synced to Apache upstream:" + echo "$UPSTREAM_PR_URL" + echo "" + echo "Thank you for your contribution! 🎉" + } > comment_body.md + + gh pr comment "$PR_NUMBER" --body-file comment_body.md + + # Step 10-11: Error handling for rebase conflicts + - name: Handle rebase failure + if: failure() && steps.rebase.outcome == 'failure' + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + PR_NUMBER: ${{ github.event.pull_request.number }} + PR_AUTHOR: ${{ github.event.pull_request.user.login }} + run: | + git rebase --abort || true + + gh issue create \ + --repo dubbo-go-pixiu/dubbo-go-pixiu \ + --title "âš ī¸ Failed to auto-sync PR #${PR_NUMBER} to upstream" \ + --body "## Sync Failure Report + + **Original PR**: #${PR_NUMBER} + **Author**: @${PR_AUTHOR} + **Error**: Rebase conflicts detected when syncing to apache/dubbo-go-pixiu + + ### Action Required + + Manual intervention is needed to resolve conflicts and create the upstream PR. + + ### Steps to resolve: + + 1. Checkout the develop branch + 2. Create a new branch: \`git checkout -b manual-sync-${PR_NUMBER}\` + 3. Add upstream: \`git remote add upstream https://github.com/apache/dubbo-go-pixiu.git\` + 4. Fetch upstream: \`git fetch upstream develop\` + 5. Rebase: \`git rebase upstream/develop\` + 6. Resolve conflicts manually + 7. Push and create PR to apache/dubbo-go-pixiu + + cc @${PR_AUTHOR}" \ + --label "sync-failure,needs-attention" + + echo "❌ Rebase failed. Issue created for manual resolution." + From 05ab18e6ea7308ed1fd0bdbcfce531cc1ad92c4d Mon Sep 17 00:00:00 2001 From: Zerui Yang Date: Thu, 2 Oct 2025 15:27:28 +0800 Subject: [PATCH 2/8] test: verify upstream sync workflow This is a test PR to verify the automatic sync workflow functionality. Expected behavior after merging to dubbo-go-pixiu/dubbo-go-pixiu:develop: 1. Workflow should trigger automatically 2. Create sync branch (auto-sync-YYYYMMDD-HHMMSS) 3. Rebase onto apache/dubbo-go-pixiu:develop 4. Remove fork-specific workflow files automatically 5. Create PR in apache/dubbo-go-pixiu 6. Comment on this PR with upstream link Success criteria: - Workflow runs without errors - Upstream PR created with this commit - Workflow files NOT present in upstream PR - Original commit author preserved Test Date: 2025-10-02 07:14:07 UTC --- .github/WORKFLOW_SYNC_TEST.md | 58 +++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 .github/WORKFLOW_SYNC_TEST.md diff --git a/.github/WORKFLOW_SYNC_TEST.md b/.github/WORKFLOW_SYNC_TEST.md new file mode 100644 index 000000000..60b1206d0 --- /dev/null +++ b/.github/WORKFLOW_SYNC_TEST.md @@ -0,0 +1,58 @@ +# Workflow Sync Test + +**Created**: $(date -u +"%Y-%m-%d %H:%M:%S UTC") +**Purpose**: Test automatic upstream sync workflow + +## Test Information + +- **Test Date**: 2025-10-02 +- **Test Branch**: test/workflow-sync-20251002-1513 +- **C Repository**: Similarityoung/dubbo-go-pixiu +- **B Repository**: dubbo-go-pixiu/dubbo-go-pixiu +- **A Repository**: apache/dubbo-go-pixiu + +## Test Checklist + +When this PR is merged into B repository, the workflow should: + +- [ ] Automatically trigger on PR merge +- [ ] Rebase onto apache/dubbo-go-pixiu:develop +- [ ] Remove fork-specific workflow files: + - [ ] .github/workflows/sync-to-upstream.yml + - [ ] .github/workflows/SYNC_WORKFLOW_GUIDE.md +- [ ] Create PR in apache/dubbo-go-pixiu +- [ ] Comment on original PR with upstream link +- [ ] Preserve original commit authorship + +## Expected Behavior + +1. **Trigger**: On merge to dubbo-go-pixiu/dubbo-go-pixiu:develop +2. **Sync**: Create timestamped branch (auto-sync-YYYYMMDD-HHMMSS) +3. **Clean**: Remove workflow files automatically +4. **Create PR**: To apache/dubbo-go-pixiu:develop +5. **Notify**: Post comment with upstream PR link + +## Files to Verify + +After upstream PR creation, verify: + +✅ **Should be present**: +- This test file (.github/WORKFLOW_SYNC_TEST.md) +- All normal code changes + +❌ **Should NOT be present**: +- .github/workflows/sync-to-upstream.yml +- .github/workflows/SYNC_WORKFLOW_GUIDE.md +- .github/workflows/TESTING_GUIDE.md + +## Success Criteria + +- [ ] Workflow runs without errors +- [ ] Upstream PR created successfully +- [ ] Workflow files removed from upstream PR +- [ ] Original PR receives bot comment +- [ ] Commit author is preserved (not bot) + +--- + +**Note**: This is a test file. After successful verification, it should be removed from both repositories. From bc2fdb4d5390a7dbb5433d65b821611f3dd7a4e9 Mon Sep 17 00:00:00 2001 From: Zerui Yang Date: Thu, 2 Oct 2025 15:45:11 +0800 Subject: [PATCH 3/8] Test/workflow sync 20251002 1513 (#3) * test: verify upstream sync workflow This is a test PR to verify the automatic sync workflow functionality. Expected behavior after merging to dubbo-go-pixiu/dubbo-go-pixiu:develop: 1. Workflow should trigger automatically 2. Create sync branch (auto-sync-YYYYMMDD-HHMMSS) 3. Rebase onto apache/dubbo-go-pixiu:develop 4. Remove fork-specific workflow files automatically 5. Create PR in apache/dubbo-go-pixiu 6. Comment on this PR with upstream link Success criteria: - Workflow runs without errors - Upstream PR created with this commit - Workflow files NOT present in upstream PR - Original commit author preserved Test Date: 2025-10-02 07:14:07 UTC * fix: use pull_request_target to access secrets from fork PRs The pull_request event does not provide access to secrets when triggered by PRs from forks (security measure). Using pull_request_target instead, which runs in the context of the base repository and has access to secrets. This fixes the 'Input required and not supplied: token' error. --- .github/workflows/sync-to-upstream.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/sync-to-upstream.yml b/.github/workflows/sync-to-upstream.yml index 634f750d9..0bd60cea5 100644 --- a/.github/workflows/sync-to-upstream.yml +++ b/.github/workflows/sync-to-upstream.yml @@ -28,7 +28,7 @@ name: Sync to Apache Upstream # - Recommended: use a dedicated bot account for the token on: - pull_request: + pull_request_target: types: [closed] branches: - develop From 2a632bad998a96c0e3d24a1e332904fa310b9fa8 Mon Sep 17 00:00:00 2001 From: Zerui Yang Date: Thu, 2 Oct 2025 16:09:54 +0800 Subject: [PATCH 4/8] Test/workflow sync 20251002 1513 (#4) * test: verify upstream sync workflo * fix: use pull_request_target to access secrets from fork PRs The pull_request event does not provide access to secrets when triggered by PRs from forks (security measure). Using pull_request_target instead, which runs in the context of the base repository and has access to secrets. This fixes the 'Input required and not supplied: token' error. * fix: specify repository for PR comment in Step 9 When using pull_request_target, the workflow runs in the base repository context. We need to explicitly specify --repo parameter for gh pr comment to ensure it comments on the correct PR. Also added error handling to prevent workflow failure if commenting fails, since the main task (creating upstream PR) is already done. * fix: delete doc --- .github/workflows/sync-to-upstream.yml | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/.github/workflows/sync-to-upstream.yml b/.github/workflows/sync-to-upstream.yml index 0bd60cea5..271aaba76 100644 --- a/.github/workflows/sync-to-upstream.yml +++ b/.github/workflows/sync-to-upstream.yml @@ -189,7 +189,12 @@ jobs: echo "Thank you for your contribution! 🎉" } > comment_body.md - gh pr comment "$PR_NUMBER" --body-file comment_body.md + # Post comment to the PR in the base repository + gh pr comment "$PR_NUMBER" --repo dubbo-go-pixiu/dubbo-go-pixiu --body-file comment_body.md || { + echo "âš ī¸ Failed to comment on PR #${PR_NUMBER}, but upstream sync succeeded" + echo "Upstream PR: $UPSTREAM_PR_URL" + exit 0 + } # Step 10-11: Error handling for rebase conflicts - name: Handle rebase failure From 6c6d5eecc1fab3fb268cd74b0515bac3ca9396b2 Mon Sep 17 00:00:00 2001 From: Zerui Yang Date: Thu, 2 Oct 2025 16:42:27 +0800 Subject: [PATCH 5/8] fix: delete doc --- .github/WORKFLOW_SYNC_TEST.md | 58 ----------------------------------- 1 file changed, 58 deletions(-) delete mode 100644 .github/WORKFLOW_SYNC_TEST.md diff --git a/.github/WORKFLOW_SYNC_TEST.md b/.github/WORKFLOW_SYNC_TEST.md deleted file mode 100644 index 60b1206d0..000000000 --- a/.github/WORKFLOW_SYNC_TEST.md +++ /dev/null @@ -1,58 +0,0 @@ -# Workflow Sync Test - -**Created**: $(date -u +"%Y-%m-%d %H:%M:%S UTC") -**Purpose**: Test automatic upstream sync workflow - -## Test Information - -- **Test Date**: 2025-10-02 -- **Test Branch**: test/workflow-sync-20251002-1513 -- **C Repository**: Similarityoung/dubbo-go-pixiu -- **B Repository**: dubbo-go-pixiu/dubbo-go-pixiu -- **A Repository**: apache/dubbo-go-pixiu - -## Test Checklist - -When this PR is merged into B repository, the workflow should: - -- [ ] Automatically trigger on PR merge -- [ ] Rebase onto apache/dubbo-go-pixiu:develop -- [ ] Remove fork-specific workflow files: - - [ ] .github/workflows/sync-to-upstream.yml - - [ ] .github/workflows/SYNC_WORKFLOW_GUIDE.md -- [ ] Create PR in apache/dubbo-go-pixiu -- [ ] Comment on original PR with upstream link -- [ ] Preserve original commit authorship - -## Expected Behavior - -1. **Trigger**: On merge to dubbo-go-pixiu/dubbo-go-pixiu:develop -2. **Sync**: Create timestamped branch (auto-sync-YYYYMMDD-HHMMSS) -3. **Clean**: Remove workflow files automatically -4. **Create PR**: To apache/dubbo-go-pixiu:develop -5. **Notify**: Post comment with upstream PR link - -## Files to Verify - -After upstream PR creation, verify: - -✅ **Should be present**: -- This test file (.github/WORKFLOW_SYNC_TEST.md) -- All normal code changes - -❌ **Should NOT be present**: -- .github/workflows/sync-to-upstream.yml -- .github/workflows/SYNC_WORKFLOW_GUIDE.md -- .github/workflows/TESTING_GUIDE.md - -## Success Criteria - -- [ ] Workflow runs without errors -- [ ] Upstream PR created successfully -- [ ] Workflow files removed from upstream PR -- [ ] Original PR receives bot comment -- [ ] Commit author is preserved (not bot) - ---- - -**Note**: This is a test file. After successful verification, it should be removed from both repositories. From b742835a6414d57cde81051b85dc8e311f0c8d6d Mon Sep 17 00:00:00 2001 From: Zerui Yang Date: Sat, 4 Oct 2025 17:56:19 +0800 Subject: [PATCH 6/8] feat: enhance upstream sync workflow configuration * feat: enhance upstream sync workflow configuration * feat: refine upstream sync workflow conditions and cleanup steps * feat: add branch target check to upstream sync workflow --- .github/workflows/sync-to-upstream.yml | 122 +++++++++++++++++-------- 1 file changed, 85 insertions(+), 37 deletions(-) diff --git a/.github/workflows/sync-to-upstream.yml b/.github/workflows/sync-to-upstream.yml index 271aaba76..1bd752f2c 100644 --- a/.github/workflows/sync-to-upstream.yml +++ b/.github/workflows/sync-to-upstream.yml @@ -19,19 +19,47 @@ name: Sync to Apache Upstream -# This workflow automatically creates a PR to apache/dubbo-go-pixiu -# when a PR is merged into the develop branch of this repository. +# This workflow automatically creates a PR to the upstream repository +# when a PR is merged into the base branch of this repository. # # Prerequisites: # - Configure the UPSTREAM_GITHUB_TOKEN secret in repository settings # - Token should have 'public_repo' permission # - Recommended: use a dedicated bot account for the token +# +# Configuration: +# - Modify the env section below to match your project's repository structure + +# ============================================================================ +# Configuration Section - Modify these values for your project +# ============================================================================ +env: + # Upstream repository (A repository - the original/official repo) + UPSTREAM_ORG: apache + UPSTREAM_REPO: dubbo-go-pixiu + + # Fork repository (B repository - the organization/team fork) + FORK_ORG: dubbo-go-pixiu + FORK_REPO: dubbo-go-pixiu + + # Branch name (main/master/develop) + BASE_BRANCH: develop + + # Git bot configuration (for commits) + BOT_NAME: "Pixiu Bot" + BOT_EMAIL: "bot@dubbo-go-pixiu.github.io" + + # Workflow files to exclude when syncing to upstream + # Add any fork-specific files that should not be synced + EXCLUDE_FILES: | + .github/workflows/sync-to-upstream.yml + +# ============================================================================ on: pull_request_target: types: [closed] - branches: - - develop + # No branches filter here - we check the branch in the job condition below # Explicit permissions required for gh pr comment and gh issue create permissions: @@ -45,36 +73,54 @@ concurrency: cancel-in-progress: false jobs: - sync-to-apache: - name: Sync to Apache Repository + sync-to-upstream: + name: Sync to Upstream Repository runs-on: ubuntu-latest # Only run when PR is actually merged (not just closed) + # Branch check is done at step level where env is available if: github.event.pull_request.merged == true steps: + # Step 0: Check if PR targets the correct base branch + - name: Check target branch + id: check_branch + run: | + if [ "${{ github.event.pull_request.base.ref }}" != "${{ env.BASE_BRANCH }}" ]; then + echo "âš ī¸ PR targets branch '${{ github.event.pull_request.base.ref }}', but BASE_BRANCH is configured as '${{ env.BASE_BRANCH }}'" + echo "Skipping sync as this PR does not target the configured base branch." + echo "skip=true" >> $GITHUB_OUTPUT + else + echo "✅ PR targets the correct base branch: ${{ env.BASE_BRANCH }}" + echo "skip=false" >> $GITHUB_OUTPUT + fi + # Step 1: Checkout code with full history - name: Checkout repository + if: steps.check_branch.outputs.skip != 'true' uses: actions/checkout@v5 with: fetch-depth: 0 - ref: develop + ref: ${{ env.BASE_BRANCH }} token: ${{ secrets.UPSTREAM_GITHUB_TOKEN }} # Step 2: Configure Git user - name: Configure Git user + if: steps.check_branch.outputs.skip != 'true' run: | - git config user.name "Pixiu Bot" - git config user.email "bot@dubbo-go-pixiu.github.io" + git config user.name "${{ env.BOT_NAME }}" + git config user.email "${{ env.BOT_EMAIL }}" # Step 3: Add upstream remote and fetch - name: Add upstream remote + if: steps.check_branch.outputs.skip != 'true' run: | - git remote add upstream https://github.com/apache/dubbo-go-pixiu.git - git fetch upstream develop + git remote add upstream https://github.com/${{ env.UPSTREAM_ORG }}/${{ env.UPSTREAM_REPO }}.git + git fetch upstream ${{ env.BASE_BRANCH }} # Step 4: Create sync branch with timestamp - name: Create sync branch + if: steps.check_branch.outputs.skip != 'true' id: create_branch run: | SYNC_BRANCH="auto-sync-$(date +%Y%m%d-%H%M%S)" @@ -82,39 +128,40 @@ jobs: git checkout -b ${SYNC_BRANCH} echo "branch=${SYNC_BRANCH}" >> $GITHUB_OUTPUT - # Step 5: Rebase onto upstream develop + # Step 5: Rebase onto upstream base branch - name: Rebase onto upstream + if: steps.check_branch.outputs.skip != 'true' id: rebase run: | - git rebase upstream/develop + git rebase upstream/${{ env.BASE_BRANCH }} - # Step 5.5: Remove B-repo specific files + # Step 5.5: Remove fork-specific files - name: Remove fork-specific workflow files + if: steps.check_branch.outputs.skip != 'true' run: | - # Remove sync workflow files that are specific to B-repo - # These should not be synced to Apache upstream - git rm -f .github/workflows/sync-to-upstream.yml || true - git rm -f .github/workflows/SYNC_WORKFLOW_GUIDE.md || true + # Remove files that are specific to the fork and should not be synced to upstream + echo "${{ env.EXCLUDE_FILES }}" | xargs git rm -f --ignore-unmatch # Commit the removal if there are changes if ! git diff --cached --quiet; then git commit -m "chore: remove fork-specific workflow files - These files are specific to dubbo-go-pixiu/dubbo-go-pixiu organization fork - and are not needed in the upstream Apache repository. + These files are specific to ${{ env.FORK_ORG }}/${{ env.FORK_REPO }} organization fork + and are not needed in the upstream repository. Files removed: - - .github/workflows/sync-to-upstream.yml - - .github/workflows/SYNC_WORKFLOW_GUIDE.md" + ${{ env.EXCLUDE_FILES }}" fi # Step 6: Push sync branch to origin - name: Push sync branch + if: steps.check_branch.outputs.skip != 'true' run: | git push origin ${SYNC_BRANCH} --force-with-lease # Step 7: Generate PR body with attribution - name: Generate PR description + if: steps.check_branch.outputs.skip != 'true' id: pr_body env: ORIGINAL_BODY: ${{ github.event.pull_request.body }} @@ -147,24 +194,25 @@ jobs: echo "" echo "All commits in this PR preserve the original authorship. You can verify this by checking the commit history." echo "" - echo "**Note**: This PR was automatically created by GitHub Actions when PR #${ORIGINAL_PR} was merged into \`dubbo-go-pixiu/dubbo-go-pixiu:develop\`." + echo "**Note**: This PR was automatically created by GitHub Actions when PR #${ORIGINAL_PR} was merged into \`${{ env.FORK_ORG }}/${{ env.FORK_REPO }}:${{ env.BASE_BRANCH }}\`." echo "" echo "cc @${ORIGINAL_AUTHOR}" } > pr_body.md echo "Generated PR body" - # Step 8: Create PR to Apache upstream - - name: Create PR to apache/dubbo-go-pixiu + # Step 8: Create PR to upstream repository + - name: Create PR to ${{ env.UPSTREAM_ORG }}/${{ env.UPSTREAM_REPO }} + if: steps.check_branch.outputs.skip != 'true' id: create_pr env: GH_TOKEN: ${{ secrets.UPSTREAM_GITHUB_TOKEN }} SYNC_PR_TITLE: ${{ github.event.pull_request.title }} run: | PR_URL=$(gh pr create \ - --repo apache/dubbo-go-pixiu \ - --base develop \ - --head dubbo-go-pixiu:${SYNC_BRANCH} \ + --repo ${{ env.UPSTREAM_ORG }}/${{ env.UPSTREAM_REPO }} \ + --base ${{ env.BASE_BRANCH }} \ + --head ${{ env.FORK_ORG }}:${SYNC_BRANCH} \ --title "$SYNC_PR_TITLE" \ --body-file pr_body.md) @@ -173,7 +221,7 @@ jobs: # Step 9: Comment on original PR with upstream PR link - name: Notify original PR - if: success() + if: success() && steps.check_branch.outputs.skip != 'true' env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} PR_NUMBER: ${{ github.event.pull_request.number }} @@ -190,7 +238,7 @@ jobs: } > comment_body.md # Post comment to the PR in the base repository - gh pr comment "$PR_NUMBER" --repo dubbo-go-pixiu/dubbo-go-pixiu --body-file comment_body.md || { + gh pr comment "$PR_NUMBER" --repo ${{ env.FORK_ORG }}/${{ env.FORK_REPO }} --body-file comment_body.md || { echo "âš ī¸ Failed to comment on PR #${PR_NUMBER}, but upstream sync succeeded" echo "Upstream PR: $UPSTREAM_PR_URL" exit 0 @@ -207,13 +255,13 @@ jobs: git rebase --abort || true gh issue create \ - --repo dubbo-go-pixiu/dubbo-go-pixiu \ + --repo ${{ env.FORK_ORG }}/${{ env.FORK_REPO }} \ --title "âš ī¸ Failed to auto-sync PR #${PR_NUMBER} to upstream" \ --body "## Sync Failure Report **Original PR**: #${PR_NUMBER} **Author**: @${PR_AUTHOR} - **Error**: Rebase conflicts detected when syncing to apache/dubbo-go-pixiu + **Error**: Rebase conflicts detected when syncing to ${{ env.UPSTREAM_ORG }}/${{ env.UPSTREAM_REPO }} ### Action Required @@ -221,13 +269,13 @@ jobs: ### Steps to resolve: - 1. Checkout the develop branch + 1. Checkout the ${{ env.BASE_BRANCH }} branch 2. Create a new branch: \`git checkout -b manual-sync-${PR_NUMBER}\` - 3. Add upstream: \`git remote add upstream https://github.com/apache/dubbo-go-pixiu.git\` - 4. Fetch upstream: \`git fetch upstream develop\` - 5. Rebase: \`git rebase upstream/develop\` + 3. Add upstream: \`git remote add upstream https://github.com/${{ env.UPSTREAM_ORG }}/${{ env.UPSTREAM_REPO }}.git\` + 4. Fetch upstream: \`git fetch upstream ${{ env.BASE_BRANCH }}\` + 5. Rebase: \`git rebase upstream/${{ env.BASE_BRANCH }}\` 6. Resolve conflicts manually - 7. Push and create PR to apache/dubbo-go-pixiu + 7. Push and create PR to ${{ env.UPSTREAM_ORG }}/${{ env.UPSTREAM_REPO }} cc @${PR_AUTHOR}" \ --label "sync-failure,needs-attention" From 363d903181e428c4a385cbf75fdf29e6f795ec52 Mon Sep 17 00:00:00 2001 From: Zerui Yang Date: Fri, 10 Oct 2025 22:38:50 +0800 Subject: [PATCH 7/8] feat: Update action sync --- .github/pull.yml | 33 ++++++++++++++++++++++++++ .github/workflows/sync-to-upstream.yml | 16 +++++++------ 2 files changed, 42 insertions(+), 7 deletions(-) create mode 100644 .github/pull.yml diff --git a/.github/pull.yml b/.github/pull.yml new file mode 100644 index 000000000..aeaffa977 --- /dev/null +++ b/.github/pull.yml @@ -0,0 +1,33 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# + +version: "1" +rules: + - base: develop + upstream: apache:develop + mergeMethod: rebase + mergeUnstable: false + assignees: + - AlexStocks + conflictReviewers: + - AlexStocks + +label: "upstream-sync" +conflictLabel: "sync-conflict" + diff --git a/.github/workflows/sync-to-upstream.yml b/.github/workflows/sync-to-upstream.yml index 1bd752f2c..fb2178c35 100644 --- a/.github/workflows/sync-to-upstream.yml +++ b/.github/workflows/sync-to-upstream.yml @@ -26,7 +26,7 @@ name: Sync to Apache Upstream # - Configure the UPSTREAM_GITHUB_TOKEN secret in repository settings # - Token should have 'public_repo' permission # - Recommended: use a dedicated bot account for the token -# +# # Configuration: # - Modify the env section below to match your project's repository structure @@ -37,22 +37,23 @@ env: # Upstream repository (A repository - the original/official repo) UPSTREAM_ORG: apache UPSTREAM_REPO: dubbo-go-pixiu - + # Fork repository (B repository - the organization/team fork) FORK_ORG: dubbo-go-pixiu FORK_REPO: dubbo-go-pixiu - + # Branch name (main/master/develop) BASE_BRANCH: develop - + # Git bot configuration (for commits) BOT_NAME: "Pixiu Bot" BOT_EMAIL: "bot@dubbo-go-pixiu.github.io" - + # Workflow files to exclude when syncing to upstream # Add any fork-specific files that should not be synced EXCLUDE_FILES: | .github/workflows/sync-to-upstream.yml + .github/pull.yml # ============================================================================ @@ -94,7 +95,7 @@ jobs: echo "✅ PR targets the correct base branch: ${{ env.BASE_BRANCH }}" echo "skip=false" >> $GITHUB_OUTPUT fi - + # Step 1: Checkout code with full history - name: Checkout repository if: steps.check_branch.outputs.skip != 'true' @@ -140,7 +141,8 @@ jobs: if: steps.check_branch.outputs.skip != 'true' run: | # Remove files that are specific to the fork and should not be synced to upstream - echo "${{ env.EXCLUDE_FILES }}" | xargs git rm -f --ignore-unmatch + # Filter out empty lines to prevent xargs errors + echo "${{ env.EXCLUDE_FILES }}" | grep -v '^\s*$' | xargs git rm -f --ignore-unmatch # Commit the removal if there are changes if ! git diff --cached --quiet; then From 40e41e88b234545cee3dcf9a85fce9eb2471ff05 Mon Sep 17 00:00:00 2001 From: Zerui Yang Date: Sat, 18 Oct 2025 19:04:04 +0800 Subject: [PATCH 8/8] refactor: streamline sync-to-upstream workflow and improve comments --- .github/pull.yml | 33 ------ .github/workflows/sync-to-upstream.yml | 133 ++++++++++--------------- 2 files changed, 50 insertions(+), 116 deletions(-) delete mode 100644 .github/pull.yml diff --git a/.github/pull.yml b/.github/pull.yml deleted file mode 100644 index aeaffa977..000000000 --- a/.github/pull.yml +++ /dev/null @@ -1,33 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one -# or more contributor license agreements. See the NOTICE file -# distributed with this work for additional information -# regarding copyright ownership. The ASF licenses this file -# to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance -# with the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, -# software distributed under the License is distributed on an -# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -# KIND, either express or implied. See the License for the -# specific language governing permissions and limitations -# under the License. -# - -version: "1" -rules: - - base: develop - upstream: apache:develop - mergeMethod: rebase - mergeUnstable: false - assignees: - - AlexStocks - conflictReviewers: - - AlexStocks - -label: "upstream-sync" -conflictLabel: "sync-conflict" - diff --git a/.github/workflows/sync-to-upstream.yml b/.github/workflows/sync-to-upstream.yml index fb2178c35..3b1fe8d1d 100644 --- a/.github/workflows/sync-to-upstream.yml +++ b/.github/workflows/sync-to-upstream.yml @@ -17,58 +17,47 @@ # under the License. # -name: Sync to Apache Upstream +name: Sync to Upstream -# This workflow automatically creates a PR to the upstream repository -# when a PR is merged into the base branch of this repository. +# Automatically creates a PR to upstream when a PR is merged to fork. +# Only executes in fork repositories (checked by github.repository). # # Prerequisites: -# - Configure the UPSTREAM_GITHUB_TOKEN secret in repository settings -# - Token should have 'public_repo' permission -# - Recommended: use a dedicated bot account for the token -# -# Configuration: -# - Modify the env section below to match your project's repository structure +# - UPSTREAM_GITHUB_TOKEN secret with 'public_repo' permission +# - Bot account with Write access to fork repository +# +# Configuration: Modify the env section below for your project # ============================================================================ -# Configuration Section - Modify these values for your project +# Configuration # ============================================================================ env: - # Upstream repository (A repository - the original/official repo) + # Upstream repository UPSTREAM_ORG: apache UPSTREAM_REPO: dubbo-go-pixiu - - # Fork repository (B repository - the organization/team fork) + + # Fork repository FORK_ORG: dubbo-go-pixiu FORK_REPO: dubbo-go-pixiu - - # Branch name (main/master/develop) + + # Branch name BASE_BRANCH: develop - - # Git bot configuration (for commits) + + # Git bot info BOT_NAME: "Pixiu Bot" BOT_EMAIL: "bot@dubbo-go-pixiu.github.io" - # Workflow files to exclude when syncing to upstream - # Add any fork-specific files that should not be synced - EXCLUDE_FILES: | - .github/workflows/sync-to-upstream.yml - .github/pull.yml - # ============================================================================ on: pull_request_target: types: [closed] - # No branches filter here - we check the branch in the job condition below -# Explicit permissions required for gh pr comment and gh issue create permissions: contents: read pull-requests: write issues: write -# Prevent concurrent syncs to avoid conflicts concurrency: group: sync-to-upstream cancel-in-progress: false @@ -78,24 +67,32 @@ jobs: name: Sync to Upstream Repository runs-on: ubuntu-latest - # Only run when PR is actually merged (not just closed) - # Branch check is done at step level where env is available + # Only run when PR is merged; repository check happens inside steps where env is available if: github.event.pull_request.merged == true steps: - # Step 0: Check if PR targets the correct base branch - - name: Check target branch + - name: Check repository and target branch id: check_branch run: | - if [ "${{ github.event.pull_request.base.ref }}" != "${{ env.BASE_BRANCH }}" ]; then - echo "âš ī¸ PR targets branch '${{ github.event.pull_request.base.ref }}', but BASE_BRANCH is configured as '${{ env.BASE_BRANCH }}'" - echo "Skipping sync as this PR does not target the configured base branch." + EXPECTED_REPO="${{ env.FORK_ORG }}/${{ env.FORK_REPO }}" + CURRENT_REPO="${GITHUB_REPOSITORY}" + + if [ "${CURRENT_REPO}" != "${EXPECTED_REPO}" ]; then + echo "â„šī¸ Running in '${CURRENT_REPO}', expected '${EXPECTED_REPO}'. Skipping." + echo "skip=true" >> $GITHUB_OUTPUT + exit 0 + fi + + TARGET_BRANCH="${{ github.event.pull_request.base.ref }}" + if [ "${TARGET_BRANCH}" != "${{ env.BASE_BRANCH }}" ]; then + echo "âš ī¸ PR targets '${TARGET_BRANCH}', expected '${{ env.BASE_BRANCH }}'. Skipping." echo "skip=true" >> $GITHUB_OUTPUT - else - echo "✅ PR targets the correct base branch: ${{ env.BASE_BRANCH }}" - echo "skip=false" >> $GITHUB_OUTPUT + exit 0 fi + echo "✅ Repo and base branch verified: ${EXPECTED_REPO}@${{ env.BASE_BRANCH }}" + echo "skip=false" >> $GITHUB_OUTPUT + # Step 1: Checkout code with full history - name: Checkout repository if: steps.check_branch.outputs.skip != 'true' @@ -136,25 +133,6 @@ jobs: run: | git rebase upstream/${{ env.BASE_BRANCH }} - # Step 5.5: Remove fork-specific files - - name: Remove fork-specific workflow files - if: steps.check_branch.outputs.skip != 'true' - run: | - # Remove files that are specific to the fork and should not be synced to upstream - # Filter out empty lines to prevent xargs errors - echo "${{ env.EXCLUDE_FILES }}" | grep -v '^\s*$' | xargs git rm -f --ignore-unmatch - - # Commit the removal if there are changes - if ! git diff --cached --quiet; then - git commit -m "chore: remove fork-specific workflow files - - These files are specific to ${{ env.FORK_ORG }}/${{ env.FORK_REPO }} organization fork - and are not needed in the upstream repository. - - Files removed: - ${{ env.EXCLUDE_FILES }}" - fi - # Step 6: Push sync branch to origin - name: Push sync branch if: steps.check_branch.outputs.skip != 'true' @@ -176,7 +154,7 @@ jobs: { echo "## 🔄 Upstream Sync from Community Fork" echo "" - echo "This PR automatically syncs changes from the community fork to the Apache upstream repository." + echo "This PR automatically syncs changes from the community fork to the upstream repository." echo "" echo "### Original Contribution" echo "" @@ -192,18 +170,13 @@ jobs: echo "" echo "---" echo "" - echo "### Commit Details" - echo "" - echo "All commits in this PR preserve the original authorship. You can verify this by checking the commit history." + echo "All commits preserve original authorship." echo "" - echo "**Note**: This PR was automatically created by GitHub Actions when PR #${ORIGINAL_PR} was merged into \`${{ env.FORK_ORG }}/${{ env.FORK_REPO }}:${{ env.BASE_BRANCH }}\`." + echo "**Note**: Auto-created when PR #${ORIGINAL_PR} was merged into \`${{ env.FORK_ORG }}/${{ env.FORK_REPO }}:${{ env.BASE_BRANCH }}\`." echo "" echo "cc @${ORIGINAL_AUTHOR}" } > pr_body.md - - echo "Generated PR body" - # Step 8: Create PR to upstream repository - name: Create PR to ${{ env.UPSTREAM_ORG }}/${{ env.UPSTREAM_REPO }} if: steps.check_branch.outputs.skip != 'true' id: create_pr @@ -221,7 +194,6 @@ jobs: echo "pr_url=${PR_URL}" >> $GITHUB_OUTPUT echo "✅ Successfully created PR: ${PR_URL}" - # Step 9: Comment on original PR with upstream PR link - name: Notify original PR if: success() && steps.check_branch.outputs.skip != 'true' env: @@ -229,24 +201,20 @@ jobs: PR_NUMBER: ${{ github.event.pull_request.number }} UPSTREAM_PR_URL: ${{ steps.create_pr.outputs.pr_url }} run: | - # Generate comment body and post to original PR { echo "🤖 **Automated Upstream Sync**" echo "" - echo "Your PR has been automatically synced to Apache upstream:" + echo "Your PR has been synced to upstream:" echo "$UPSTREAM_PR_URL" echo "" echo "Thank you for your contribution! 🎉" } > comment_body.md - # Post comment to the PR in the base repository gh pr comment "$PR_NUMBER" --repo ${{ env.FORK_ORG }}/${{ env.FORK_REPO }} --body-file comment_body.md || { - echo "âš ī¸ Failed to comment on PR #${PR_NUMBER}, but upstream sync succeeded" - echo "Upstream PR: $UPSTREAM_PR_URL" + echo "âš ī¸ Comment failed but sync succeeded: $UPSTREAM_PR_URL" exit 0 } - # Step 10-11: Error handling for rebase conflicts - name: Handle rebase failure if: failure() && steps.rebase.outcome == 'failure' env: @@ -263,21 +231,20 @@ jobs: **Original PR**: #${PR_NUMBER} **Author**: @${PR_AUTHOR} - **Error**: Rebase conflicts detected when syncing to ${{ env.UPSTREAM_ORG }}/${{ env.UPSTREAM_REPO }} - - ### Action Required - - Manual intervention is needed to resolve conflicts and create the upstream PR. + **Error**: Rebase conflicts detected - ### Steps to resolve: + ### Manual Resolution Required - 1. Checkout the ${{ env.BASE_BRANCH }} branch - 2. Create a new branch: \`git checkout -b manual-sync-${PR_NUMBER}\` - 3. Add upstream: \`git remote add upstream https://github.com/${{ env.UPSTREAM_ORG }}/${{ env.UPSTREAM_REPO }}.git\` - 4. Fetch upstream: \`git fetch upstream ${{ env.BASE_BRANCH }}\` - 5. Rebase: \`git rebase upstream/${{ env.BASE_BRANCH }}\` - 6. Resolve conflicts manually - 7. Push and create PR to ${{ env.UPSTREAM_ORG }}/${{ env.UPSTREAM_REPO }} + \`\`\`bash + git checkout ${{ env.BASE_BRANCH }} + git checkout -b manual-sync-${PR_NUMBER} + git remote add upstream https://github.com/${{ env.UPSTREAM_ORG }}/${{ env.UPSTREAM_REPO }}.git + git fetch upstream ${{ env.BASE_BRANCH }} + git rebase upstream/${{ env.BASE_BRANCH }} + # Resolve conflicts + git push origin manual-sync-${PR_NUMBER} + # Create PR to ${{ env.UPSTREAM_ORG }}/${{ env.UPSTREAM_REPO }} + \`\`\` cc @${PR_AUTHOR}" \ --label "sync-failure,needs-attention"