@@ -52,29 +52,31 @@ jobs:
52
52
uses : actions/checkout@v4
53
53
with :
54
54
fetch-depth : 0
55
- - name : Create merge commit
55
+ - name : Check if there are commits to merge
56
56
id : create_merge_commit
57
57
run : |
58
58
# Without this, we can't perform git operations in GitHub actions.
59
59
git config --global --add safe.directory "$(realpath .)"
60
60
git config --local user.name 'swift-ci'
61
61
git config --local user.email '[email protected] '
62
62
63
- git checkout ${{ inputs.base_branch }}
64
- git merge ${{ inputs.head_branch }}
65
-
66
- if [[ "$(git rev-parse HEAD)" = "$(git rev-parse ${{ inputs.head_branch }})" ]]; then
67
- echo "has_merged_commits=true" >> "$GITHUB_OUTPUT"
68
- else
69
- echo "has_merged_commits=false" >> "$GITHUB_OUTPUT"
63
+ if [[ "$(git rev-list --left-only --count origin/${{ inputs.head_branch }}...origin/${{ inputs.base_branch }})" == 0 ]]; then
64
+ echo "Nothing to merge"
65
+ echo "has_commits_to_merge=false" >> "$GITHUB_OUTPUT"
66
+ exit
70
67
fi
68
+
69
+ echo "has_commits_to_merge=true" >> "$GITHUB_OUTPUT"
71
70
- name : Push branch and create PR
72
71
id : push_branch
73
- if : ${{ steps.create_merge_commit.outputs.has_merged_commits == 'true' }}
72
+ if : ${{ steps.create_merge_commit.outputs.has_commits_to_merge == 'true' }}
74
73
env :
75
74
GH_TOKEN : ${{ github.token }}
76
75
run : |
76
+ # Create a branch for the PR instead of opening a PR that merges head_branch directly so that we have a fixed
77
+ # target in the PR and don't modify the PR as new commits are put on the head branch.
77
78
PR_BRANCH="automerge/merge-main-$(date +%Y-%m-%d_%H-%M)"
79
+ git checkout ${{ inputs.head_branch }}
78
80
git checkout -b "$PR_BRANCH"
79
81
git push --set-upstream origin "$PR_BRANCH"
80
82
0 commit comments