diff --git a/projects/github-actions/pr-is-up-to-date/changelog/fix-pr-up-to-date-workflow-timeout b/projects/github-actions/pr-is-up-to-date/changelog/fix-pr-up-to-date-workflow-timeout new file mode 100644 index 000000000000..af85680d22fd --- /dev/null +++ b/projects/github-actions/pr-is-up-to-date/changelog/fix-pr-up-to-date-workflow-timeout @@ -0,0 +1,4 @@ +Significance: patch +Type: fixed + +Speed up processing of tag push with paths. diff --git a/projects/github-actions/pr-is-up-to-date/funcs.sh b/projects/github-actions/pr-is-up-to-date/funcs.sh index 33db1fa1e907..03095fc30cd1 100644 --- a/projects/github-actions/pr-is-up-to-date/funcs.sh +++ b/projects/github-actions/pr-is-up-to-date/funcs.sh @@ -132,6 +132,7 @@ function fetch_prs { # Inputs: # $1: PR number to test. # $BRANCH: Base branch, e.g. master. +# $DEEPENBY: How much to deepen by if we're having to deepen $BRANCH. If empty, it'll deepen by just enough to find the merge base. # ${PATHS[@]}: Paths that must be touched. # Returns: 0 if the PR should be processed, non-zero otherwise. function should_process_pr { @@ -141,11 +142,24 @@ function should_process_pr { MB="$(git merge-base "pulls/$PR" "origin/$BRANCH")" # We need to find the merge base in order to diff. If there wasn't one, fetch the needed revs and try again. if [[ -z "$MB" ]]; then - # We need to fetch $BRANCH down to the PR, and then deepen the PR by 1 to get the actual merge base. - gitfetch --shallow-exclude="refs/pull/$PR/head" origin "$BRANCH" || die "should_process_pr: Failed to fetch $BRANCH to PR #$PR" - gitfetch --deepen=1 origin "+refs/pull/$PR/head:refs/remotes/pulls/$PR" || die "should_process_pr: Failed to fetch next revision for PR #$PR" - MB="$(git merge-base "pulls/$PR" "origin/$BRANCH")" - [[ -z "$MB" ]] && die "Failed to determine merge base for pulls/$PR and origin/$BRANCH" + if [[ -z "$DEEPENBY" || $DEEPENBY -lt 1 ]]; then + echo "::group::Fetching $BRANCH to PR #$PR" + # We need to fetch $BRANCH down to the PR, and then deepen the PR by 1 to get the actual merge base. + gitfetch --shallow-exclude="refs/pull/$PR/head" origin "$BRANCH" || die "should_process_pr: Failed to fetch $BRANCH to PR #$PR" + gitfetch --deepen=1 origin "+refs/pull/$PR/head:refs/remotes/pulls/$PR" || die "should_process_pr: Failed to fetch next revision for PR #$PR" + echo "::endgroup::" + MB="$(git merge-base "pulls/$PR" "origin/$BRANCH")" + [[ -z "$MB" ]] && die "Failed to determine merge base for pulls/$PR and origin/$BRANCH" + else + # Keep deepening until we find the merge base. Double the DEEPENBY each time to try to adapt to busier repos. + while [[ -z "$MB" ]]; do + echo "::group::Fetching next $DEEPENBY revisions for $BRANCH" + gitfetch --deepen="$DEEPENBY" origin "$BRANCH" || die "should_process_pr: Failed to fetch next $DEEPENBY revisions for $BRANCH" + DEEPENBY=$(( DEEPENBY * 2 )) + echo "::endgroup::" + MB="$(git merge-base "pulls/$PR" "origin/$BRANCH")" + done + fi fi ! git diff --name-only --exit-code "$MB..pulls/$PR" -- "${PATHS[@]}" return diff --git a/projects/github-actions/pr-is-up-to-date/run.sh b/projects/github-actions/pr-is-up-to-date/run.sh index cec7bd5a36ec..bfb17a71cb99 100755 --- a/projects/github-actions/pr-is-up-to-date/run.sh +++ b/projects/github-actions/pr-is-up-to-date/run.sh @@ -72,6 +72,7 @@ case "$GITHUB_EVENT_NAME" in ;; push) declare -i PAGE=1 + declare -i DEEPENBY=100 while :; do echo "::group::Fetching PRs (page $PAGE)" JSON=$(curl --fail --get --header "authorization: Bearer $API_TOKEN" --data-urlencode "base=${BRANCH}" "${GITHUB_API_URL}/repos/${GITHUB_REPOSITORY}/pulls?state=open&per_page=100&page=${PAGE}")