Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: fixed

Speed up processing of tag push with paths.
24 changes: 19 additions & 5 deletions projects/github-actions/pr-is-up-to-date/funcs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions projects/github-actions/pr-is-up-to-date/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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}")
Expand Down