-
Notifications
You must be signed in to change notification settings - Fork 53
ci: add workflow to auto-sync feature branch with main #1302
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
LalatenduMohanty
merged 1 commit into
python-wheel-build:main
from
LalatenduMohanty:auto-update-new-resolver-config
Aug 11, 2026
+126
−0
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,126 @@ | ||
| name: Sync feature branch with main | ||
|
|
||
| on: | ||
| push: | ||
| branches: [main] | ||
| workflow_dispatch: | ||
| inputs: | ||
| target_branch: | ||
| description: "Feature branch to sync with main" | ||
| required: true | ||
| default: "new-resolver-config" | ||
|
|
||
| permissions: | ||
| contents: read | ||
|
|
||
| jobs: | ||
| sync-branch: | ||
| runs-on: ubuntu-latest | ||
| if: ${{ github.repository_owner == 'python-wheel-build' }} | ||
| concurrency: | ||
| group: sync-${{ inputs.target_branch || 'new-resolver-config' }} | ||
| cancel-in-progress: false | ||
| permissions: | ||
| contents: write | ||
| issues: write | ||
| env: | ||
| TARGET_BRANCH: ${{ inputs.target_branch || 'new-resolver-config' }} | ||
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
| steps: | ||
| - name: Checkout target branch | ||
| uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 | ||
| with: | ||
| ref: ${{ env.TARGET_BRANCH }} | ||
| fetch-depth: 0 | ||
| persist-credentials: false | ||
|
|
||
| - name: Configure git | ||
| run: | | ||
| git config user.name "github-actions[bot]" | ||
| git config user.email "github-actions[bot]@users.noreply.github.com" | ||
| gh auth setup-git | ||
|
|
||
| - name: Merge main into feature branch | ||
| id: merge | ||
| run: | | ||
| git fetch origin main | ||
| BEFORE=$(git rev-parse HEAD) | ||
| if git merge origin/main --no-edit; then | ||
| AFTER=$(git rev-parse HEAD) | ||
| if [ "$BEFORE" = "$AFTER" ]; then | ||
| echo "result=up-to-date" >> "$GITHUB_OUTPUT" | ||
| else | ||
| echo "result=merged" >> "$GITHUB_OUTPUT" | ||
| fi | ||
| else | ||
| CONFLICTS=$(git diff --name-only --diff-filter=U) | ||
| git merge --abort | ||
| echo "result=conflict" >> "$GITHUB_OUTPUT" | ||
| echo "conflicts<<DELIM" >> "$GITHUB_OUTPUT" | ||
| echo "$CONFLICTS" >> "$GITHUB_OUTPUT" | ||
| echo "DELIM" >> "$GITHUB_OUTPUT" | ||
| fi | ||
|
|
||
| - name: Push merged changes | ||
| if: steps.merge.outputs.result == 'merged' | ||
| run: git push origin "HEAD:${TARGET_BRANCH}" | ||
|
|
||
| - name: Close resolved sync-conflict issues | ||
| if: steps.merge.outputs.result == 'merged' || steps.merge.outputs.result == 'up-to-date' | ||
| run: | | ||
| EXPECTED_TITLE="Sync conflict: ${TARGET_BRANCH} cannot merge main" | ||
| gh issue list --label "sync-conflict" --state open --json number,title \ | ||
| | jq -r --arg t "$EXPECTED_TITLE" '.[] | select(.title == $t) | .number' \ | ||
| | xargs -rI{} gh issue close {} --comment "Resolved by automated sync." | ||
|
|
||
| - name: Report up-to-date | ||
| if: steps.merge.outputs.result == 'up-to-date' | ||
| run: echo "Branch ${TARGET_BRANCH} is already up to date with main." | ||
|
|
||
| - name: Open issue on conflict | ||
| if: steps.merge.outputs.result == 'conflict' | ||
| run: | | ||
| EXPECTED_TITLE="Sync conflict: ${TARGET_BRANCH} cannot merge main" | ||
|
|
||
| EXISTING=$(gh issue list \ | ||
| --label "sync-conflict" \ | ||
| --state open \ | ||
| --json title \ | ||
| | jq --arg expected "$EXPECTED_TITLE" \ | ||
| '[.[] | select(.title == $expected)] | length') | ||
|
|
||
| if [ "$EXISTING" -gt 0 ]; then | ||
| echo "An open sync-conflict issue for ${TARGET_BRANCH} already exists, skipping." | ||
| exit 0 | ||
| fi | ||
|
|
||
| gh label create "sync-conflict" \ | ||
| --description "Automated sync with main hit merge conflicts" \ | ||
| --color "D93F0B" \ | ||
| --force | ||
|
|
||
| gh issue create \ | ||
| --title "$EXPECTED_TITLE" \ | ||
| --label "sync-conflict" \ | ||
| --body "$(cat <<EOF | ||
| The automated sync workflow failed to merge \`main\` into \`${TARGET_BRANCH}\` due to merge conflicts. | ||
|
|
||
| **Conflicting files:** | ||
| \`\`\` | ||
| ${{ steps.merge.outputs.conflicts }} | ||
| \`\`\` | ||
|
|
||
| **Manual resolution required.** To fix: | ||
|
|
||
| \`\`\`bash | ||
| git checkout ${TARGET_BRANCH} | ||
| git fetch origin | ||
| git merge origin/main | ||
| # resolve conflicts | ||
| git commit | ||
| git push | ||
| \`\`\` | ||
|
|
||
| **Workflow run:** ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }} | ||
| EOF | ||
| )" | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.