This is an automated email from the ASF dual-hosted git repository.

potiuk pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/airflow.git


The following commit(s) were added to refs/heads/main by this push:
     new 12ce2dcd46 Retry merge commit retrieval on failure (#39231)
12ce2dcd46 is described below

commit 12ce2dcd46f6ad59e0a03925654a92126c2e5164
Author: Jarek Potiuk <ja...@potiuk.com>
AuthorDate: Wed Apr 24 19:49:22 2024 +0200

    Retry merge commit retrieval on failure (#39231)
    
    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.
---
 .github/workflows/build-images.yml | 19 ++++++++++++++++++-
 1 file changed, 18 insertions(+), 1 deletion(-)

diff --git a/.github/workflows/build-images.yml 
b/.github/workflows/build-images.yml
index 9c732d1166..bd10e73aac 100644
--- a/.github/workflows/build-images.yml
+++ b/.github/workflows/build-images.yml
@@ -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

Reply via email to