Skip to content
Open
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
28 changes: 19 additions & 9 deletions .github/workflows/check-parent-branch.yml
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Loading