Skip to content

Commit

Permalink
Retry merge commit retrieval on failure
Browse files Browse the repository at this point in the history
Sometimes when merge commit retrieval fails (because of race condition
most likely as pull request event is no ready yet) build-images builds
all images because selective check does not know the merge commit (in
pull request target vuild image failure). That was the only side effect.
because otherwise build image had a fallback to
github.event.pull_request.head.sha in this case.

With this PR, we will retry it and fallback explicitly to
github.event.pull_request.head.sha if it does not work.
  • Loading branch information
potiuk committed Apr 24, 2024
1 parent c434c6b commit cd7861f
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion .github/workflows/build-images.yml
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,25 @@ jobs:
- name: Discover PR merge commit
id: discover-pr-merge-commit
run: |
# Sometimes target-commit-sha cannot be
TARGET_COMMIT_SHA="$(gh api '${{ github.event.pull_request.url }}' --jq .merge_commit_sha)"
echo "TARGET_COMMIT_SHA=$TARGET_COMMIT_SHA" >> ${GITHUB_ENV}
if [[ ${TARGET_COMMIT_SHA} == "" ]]; then
# Sometimes retrieving the merge commit SHA from PR fails. We retry it once. Otherwise we
# fall-back to github.event.pull_request.head.sha
echo
echo "Could not retrieve merge commit SHA from PR, waiting for 3 seconds and retrying."
echo
sleep 3
TARGET_COMMIT_SHA="$(gh api '${{ github.event.pull_request.url }}' --jq .merge_commit_sha)"
if [[ ${TARGET_COMMIT_SHA} == "" ]]; then
echo
echo "Could not retrieve merge commit SHA from PR, falling back to PR head SHA."
echo
TARGET_COMMIT_SHA="${{ github.event.pull_request.head.sha }}"
fi
fi
echo "TARGET_COMMIT_SHA=${TARGET_COMMIT_SHA}"
echo "TARGET_COMMIT_SHA=${TARGET_COMMIT_SHA}" >> ${GITHUB_ENV}
echo "target-commit-sha=${TARGET_COMMIT_SHA}" >> ${GITHUB_OUTPUT}
if: github.event_name == 'pull_request_target'
# The labels in the event aren't updated when re-triggering the job, So lets hit the API to get
Expand Down

0 comments on commit cd7861f

Please sign in to comment.