Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 11 additions & 9 deletions .github/workflows/create_automerge_pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,29 +52,31 @@ jobs:
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Create merge commit
- name: Check if there are commits to merge
id: create_merge_commit
run: |
# Without this, we can't perform git operations in GitHub actions.
git config --global --add safe.directory "$(realpath .)"
git config --local user.name 'swift-ci'
git config --local user.email '[email protected]'

git checkout ${{ inputs.base_branch }}
git merge ${{ inputs.head_branch }}

if [[ "$(git rev-parse HEAD)" = "$(git rev-parse ${{ inputs.head_branch }})" ]]; then
echo "has_merged_commits=true" >> "$GITHUB_OUTPUT"
else
echo "has_merged_commits=false" >> "$GITHUB_OUTPUT"
if [[ "$(git rev-list --left-only --count origin/${{ inputs.head_branch }}...origin/${{ inputs.base_branch }})" == 0 ]]; then
echo "Nothing to merge"
echo "has_commits_to_merge=false" >> "$GITHUB_OUTPUT"
exit
fi

echo "has_commits_to_merge=true" >> "$GITHUB_OUTPUT"
- name: Push branch and create PR
id: push_branch
if: ${{ steps.create_merge_commit.outputs.has_merged_commits == 'true' }}
if: ${{ steps.create_merge_commit.outputs.has_commits_to_merge == 'true' }}
env:
GH_TOKEN: ${{ github.token }}
run: |
# Create a branch for the PR instead of opening a PR that merges head_branch directly so that we have a fixed
# target in the PR and don't modify the PR as new commits are put on the head branch.
PR_BRANCH="automerge/merge-main-$(date +%Y-%m-%d_%H-%M)"
git checkout ${{ inputs.head_branch }}
git checkout -b "$PR_BRANCH"
git push --set-upstream origin "$PR_BRANCH"

Expand Down
Loading