Skip to content

Commit d18745f

Browse files
authored
ci(release): merge a release pull request only while main is unchanged (#901)
1 parent 37500d6 commit d18745f

1 file changed

Lines changed: 13 additions & 1 deletion

File tree

‎.github/workflows/release-please.yml‎

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,4 +215,16 @@ jobs:
215215
# The delivery app merges, so the resulting push to main starts the tag and publish runs.
216216
GH_TOKEN: ${{ steps.delivery-token.outputs.token }}
217217
RELEASE_PR: ${{ needs.release-please.outputs.release_pr }}
218-
run: gh pr merge "${RELEASE_PR}" --repo "${GITHUB_REPOSITORY}" --auto --squash
218+
PROCESSED_SHA: ${{ github.sha }}
219+
run: |
220+
# A commit merged to main while these checks ran is not in this release pull request yet.
221+
# Its own Release Please run is queued behind this one and refreshes and re-checks the
222+
# pull request, so merging now would tag a release whose changelog omits that commit.
223+
main_sha="$(gh api "repos/${GITHUB_REPOSITORY}/commits/main" --jq .sha)"
224+
if [[ "${main_sha}" != "${PROCESSED_SHA}" ]]; then
225+
gh pr merge "${RELEASE_PR}" --repo "${GITHUB_REPOSITORY}" --disable-auto 2>/dev/null || true
226+
echo "main moved from ${PROCESSED_SHA} to ${main_sha}; leaving the merge to the queued run" \
227+
>> "${GITHUB_STEP_SUMMARY}"
228+
exit 0
229+
fi
230+
gh pr merge "${RELEASE_PR}" --repo "${GITHUB_REPOSITORY}" --auto --squash

0 commit comments

Comments
 (0)