|
| 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 | + if: (github.event_name == 'schedule' && github.repository == 'swiftlang/swift-format') || (github.event_name != 'schedule') # Ensure that we don't run this on a schedule in a fork |
| 16 | + steps: |
| 17 | + - name: Set up variables |
| 18 | + id: variables |
| 19 | + run: | |
| 20 | + echo "release_branch=release/6.2" >> "$GITHUB_OUTPUT" |
| 21 | + echo "pr_branch=automerge/merge-main-$(date +%Y-%m-%d)" >> "$GITHUB_OUTPUT" |
| 22 | + - name: Checkout repository |
| 23 | + uses: actions/checkout@v4 |
| 24 | + with: |
| 25 | + fetch-depth: 0 |
| 26 | + - name: Create merge commit |
| 27 | + id: create_merge_commit |
| 28 | + run: | |
| 29 | + # Without this, we can't perform git operations in GitHub actions. |
| 30 | + git config --global --add safe.directory "$(realpath .)" |
| 31 | + git config --local user.name 'swift-ci' |
| 32 | + git config --local user.email '[email protected]' |
| 33 | +
|
| 34 | + git checkout ${{ steps.variables.outputs.release_branch }} |
| 35 | + git merge main |
| 36 | +
|
| 37 | + if [[ "$(git rev-parse HEAD)" = "$(git rev-parse main)" ]]; then |
| 38 | + echo "has_merged_commits=true" >> "$GITHUB_OUTPUT" |
| 39 | + else |
| 40 | + echo "has_merged_commits=false" >> "$GITHUB_OUTPUT" |
| 41 | + fi |
| 42 | + - name: Push branch and create PR |
| 43 | + id: push_branch |
| 44 | + if: ${{ steps.create_merge_commit.outputs.has_merged_commits }} |
| 45 | + env: |
| 46 | + GH_TOKEN: ${{ github.token }} |
| 47 | + run: | |
| 48 | + git checkout -b "${{ steps.variables.outputs.pr_branch }}" |
| 49 | + git push --set-upstream origin "${{ steps.variables.outputs.pr_branch }}" |
| 50 | +
|
| 51 | + gh pr create -B "${{ steps.variables.outputs.release_branch }}" -H "${{ steps.variables.outputs.pr_branch }}" \ |
| 52 | + --title 'Merge `main` into `${{ steps.variables.outputs.release_branch }}`' \ |
| 53 | + --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