-
Notifications
You must be signed in to change notification settings - Fork 814
Add backmerge release workflow to automate merging changes from release/13.2 to main #14453
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
+176
−0
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
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,152 @@ | ||
| name: Backmerge Release to Main | ||
|
|
||
| on: | ||
| schedule: | ||
| - cron: '0 0 * * *' # Runs daily at 00:00 UTC (16:00 PST / 17:00 PDT) | ||
| workflow_dispatch: # Allow manual trigger | ||
|
|
||
| permissions: | ||
| contents: write | ||
| pull-requests: write | ||
| issues: write | ||
|
|
||
| jobs: | ||
| backmerge: | ||
| runs-on: ubuntu-latest | ||
| timeout-minutes: 15 | ||
| if: ${{ github.repository_owner == 'dotnet' }} | ||
|
|
||
| steps: | ||
| - name: Checkout repository | ||
| uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 | ||
| with: | ||
| fetch-depth: 0 # Full history needed for merge | ||
|
|
||
| - name: Check for changes to backmerge | ||
| id: check | ||
| run: | | ||
| git fetch origin main release/13.2 | ||
| BEHIND_COUNT=$(git rev-list --count origin/main..origin/release/13.2) | ||
| echo "behind_count=$BEHIND_COUNT" >> $GITHUB_OUTPUT | ||
| if [ "$BEHIND_COUNT" -gt 0 ]; then | ||
| echo "changes=true" >> $GITHUB_OUTPUT | ||
| echo "Found $BEHIND_COUNT commits in release/13.2 not in main" | ||
| else | ||
| echo "changes=false" >> $GITHUB_OUTPUT | ||
| echo "No changes to backmerge - release/13.2 is up-to-date with main" | ||
| fi | ||
|
|
||
| - name: Attempt merge and create branch | ||
| if: steps.check.outputs.changes == 'true' | ||
| id: merge | ||
| run: | | ||
| git config user.name "github-actions[bot]" | ||
| git config user.email "github-actions[bot]@users.noreply.github.com" | ||
|
|
||
| git checkout origin/main | ||
| git checkout -b backmerge/release-13.2-to-main | ||
|
|
||
| # Attempt the merge | ||
| if git merge origin/release/13.2 --no-edit; then | ||
| echo "merge_success=true" >> $GITHUB_OUTPUT | ||
| git push origin backmerge/release-13.2-to-main --force | ||
| echo "Merge successful, branch pushed" | ||
| else | ||
| echo "merge_success=false" >> $GITHUB_OUTPUT | ||
| git merge --abort | ||
| echo "Merge conflicts detected" | ||
| fi | ||
|
|
||
| - name: Create Pull Request | ||
| if: steps.check.outputs.changes == 'true' && steps.merge.outputs.merge_success == 'true' | ||
| id: create-pr | ||
| uses: dotnet/actions-create-pull-request@e8d799aa1f8b17f324f9513832811b0a62f1e0b1 | ||
| with: | ||
| token: ${{ secrets.GITHUB_TOKEN }} | ||
| head: backmerge/release-13.2-to-main | ||
| base: main | ||
| title: "[Automated] Backmerge release/13.2 to main" | ||
| labels: area-engineering-systems | ||
| body: | | ||
| ## Automated Backmerge | ||
|
|
||
| This PR merges changes from `release/13.2` back into `main`. | ||
|
|
||
| **Commits to merge:** ${{ steps.check.outputs.behind_count }} | ||
|
|
||
| This PR was created automatically to keep `main` up-to-date with release branch changes. | ||
| Once approved, it will auto-merge. | ||
|
|
||
| --- | ||
| *This PR was generated by the [backmerge-release](${{ github.server_url }}/${{ github.repository }}/actions/workflows/backmerge-release.yml) workflow.* | ||
|
|
||
| - name: Add assignees and enable auto-merge | ||
| if: steps.create-pr.outputs.pull-request-number | ||
| env: | ||
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
| run: | | ||
| gh pr edit ${{ steps.create-pr.outputs.pull-request-number }} --add-assignee joperezr,radical | ||
| gh pr merge ${{ steps.create-pr.outputs.pull-request-number }} --auto --merge | ||
|
|
||
| - name: Create issue for merge conflicts | ||
| if: steps.check.outputs.changes == 'true' && steps.merge.outputs.merge_success == 'false' | ||
| uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1 | ||
| with: | ||
| script: | | ||
| const workflowRunUrl = `${context.serverUrl}/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}`; | ||
|
|
||
| // Check if there's already an open issue for this | ||
| const existingIssues = await github.rest.issues.listForRepo({ | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| state: 'open', | ||
| labels: 'backmerge-conflict', | ||
| creator: 'github-actions[bot]' | ||
| }); | ||
|
|
||
| if (existingIssues.data.length > 0) { | ||
| console.log(`Existing backmerge conflict issue found: #${existingIssues.data[0].number}`); | ||
| // Add a comment to the existing issue | ||
| await github.rest.issues.createComment({ | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| issue_number: existingIssues.data[0].number, | ||
| body: `⚠️ Merge conflicts still exist.\n\n**Workflow run:** ${workflowRunUrl}\n\nPlease resolve the conflicts manually.` | ||
| }); | ||
| return; | ||
| } | ||
|
|
||
| // Create a new issue | ||
| const issueBody = [ | ||
| '## Backmerge Conflict', | ||
| '', | ||
| 'The automated backmerge from `release/13.2` to `main` failed due to merge conflicts.', | ||
| '', | ||
| '### What to do', | ||
| '', | ||
| '1. Checkout main and attempt the merge locally:', | ||
| ' ```bash', | ||
| ' git checkout main', | ||
| ' git pull origin main', | ||
| ' git merge origin/release/13.2', | ||
| ' ```', | ||
| '2. Resolve the conflicts', | ||
| '3. Push the merge commit or create a PR manually', | ||
| '', | ||
| '### Details', | ||
| '', | ||
| `**Workflow run:** ${workflowRunUrl}`, | ||
| '**Commits to merge:** ${{ steps.check.outputs.behind_count }}', | ||
| '', | ||
| '---', | ||
| `*This issue was created automatically by the [backmerge-release](${context.serverUrl}/${context.repo.owner}/${context.repo.repo}/actions/workflows/backmerge-release.yml) workflow.*` | ||
| ].join('\n'); | ||
|
|
||
| await github.rest.issues.create({ | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| title: '[Backmerge] Merge conflicts between release/13.2 and main', | ||
| body: issueBody, | ||
| assignees: ['joperezr', 'radical'], | ||
| labels: ['area-engineering-systems', 'backmerge-conflict'] | ||
| }); | ||
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
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.