diff --git a/.github/workflows/check-parent-branch.yml b/.github/workflows/check-parent-branch.yml index 3a432e6bd..2ad310590 100644 --- a/.github/workflows/check-parent-branch.yml +++ b/.github/workflows/check-parent-branch.yml @@ -1,5 +1,5 @@ # Block PRs targeting wip branches (v2.1-wip, v3.0-wip) when they are -# behind their parent branch (v2.0 and v2.1-wip respectively). +# behind their parent branches (v2.0, and v2.1-wip + v2.0 respectively). # This prevents unpropagated commits from accumulating, which leads to # costly backports of many commits generating large conflicts. # See https://github.com/TransmodelEcosystem/NeTEx/issues/982 @@ -21,13 +21,23 @@ jobs: - name: Verify base branch contains all parent commits run: | case "${{ github.base_ref }}" in - v2.1-wip) parent=v2.0 ;; - v3.0-wip) parent=v2.1-wip ;; + v2.1-wip) parents="v2.0" ;; + v3.0-wip) parents="v2.1-wip v2.0" ;; esac - behind=$(git rev-list --count "origin/${{ github.base_ref }}..origin/$parent") - if [ "$behind" -gt 0 ]; then - echo "::error::${{ github.base_ref }} is $behind commit(s) behind $parent. Merge $parent into ${{ github.base_ref }} first." - git log --oneline "origin/${{ github.base_ref }}..origin/$parent" - exit 1 - fi + target="origin/${{ github.base_ref }}" + pr="${{ github.event.pull_request.head.sha }}" + + # Count the commits of the target's parent branch (e.g. v2.0 for + # v2.1-wip) found neither in the target branch nor in this PR. An + # ordinary PR does not bring them in, so it stays blocked while the + # target lags behind. A backport PR does, so it is not blocked by + # the very lag it fixes. + for parent in $parents; do + behind=$(git rev-list --count "origin/$parent" --not "$target" "$pr") + if [ "$behind" -gt 0 ]; then + echo "::error::${{ github.base_ref }} is $behind commit(s) behind $parent. Merge $parent into ${{ github.base_ref }} first." + git log --oneline "origin/$parent" --not "$target" "$pr" + exit 1 + fi + done