Skip to content

Commit 56f67e0

Browse files
committed
Add GitHub action that automatically creates a PR to merge main into a release branch
In the first period after branching the release branch, we typically want to include all changes from `main` also in the release branch. This workflow automatically creates a PR every Monday to merge main into the release branch. Later in the release cycle we should stop this practice to avoid landing risky changes by disabling this workflow.
1 parent 661aa9e commit 56f67e0

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed

.github/workflows/automerge.yml

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
name: Create PR to merge main into release branch
2+
3+
# In the first period after branching the release branch, we typically want to include all changes from `main` also in the release branch. This workflow automatically creates a PR every Monday to merge main into the release branch.
4+
# Later in the release cycle we should stop this practice to avoid landing risky changes by disabling this workflow. To do so, disable the workflow as described in https://docs.github.com/en/actions/managing-workflow-runs-and-deployments/managing-workflow-runs/disabling-and-enabling-a-workflow
5+
6+
on:
7+
schedule:
8+
- cron: '0 0 * * MON'
9+
workflow_dispatch:
10+
11+
jobs:
12+
create_merge_pr:
13+
name: Create PR to merge main into release branch
14+
runs-on: ubuntu-latest
15+
steps:
16+
- name: Set up variables
17+
id: variables
18+
run: |
19+
echo "release_branch=release/6.2" >> "$GITHUB_OUTPUT"
20+
echo "pr_branch=automerge/merge-main-$(date +%Y-%m-%d)" >> "$GITHUB_OUTPUT"
21+
- name: Checkout repository
22+
uses: actions/checkout@v4
23+
with:
24+
fetch-depth: 0
25+
- name: Create merge commit
26+
id: create_merge_commit
27+
run: |
28+
# Without this, we can't perform git operations in GitHub actions.
29+
git config --global --add safe.directory "$(realpath .)"
30+
git config --local user.name 'swift-ci'
31+
git config --local user.email '[email protected]'
32+
33+
git checkout ${{ steps.variables.outputs.release_branch }}
34+
git merge main
35+
36+
if [[ "$(git rev-parse HEAD)" = "$(git rev-parse main)" ]]; then
37+
echo "has_merged_commits=true" >> "$GITHUB_OUTPUT"
38+
else
39+
echo "has_merged_commits=false" >> "$GITHUB_OUTPUT"
40+
fi
41+
- name: Push branch and create PR
42+
id: push_branch
43+
if: ${{ steps.create_merge_commit.outputs.has_merged_commits }}
44+
env:
45+
GH_TOKEN: ${{ github.token }}
46+
run: |
47+
git checkout -b "${{ steps.variables.outputs.pr_branch }}"
48+
git push --set-upstream origin "${{ steps.variables.outputs.pr_branch }}"
49+
50+
gh pr create -B "${{ steps.variables.outputs.release_branch }}" -H "${{ steps.variables.outputs.pr_branch }}" \
51+
--title 'Merge `main` into `${{ steps.variables.outputs.release_branch }}`' \
52+
--body 'This PR was automatically opened by a GitHub action. Review the changes included in this PR and determine if they should be included in the release branch. If yes, merge the PR. Otherwise revert changes that should not be included on this branch.'

0 commit comments

Comments
 (0)