From b463ef74c669416710794d387ea087aef3ae45b6 Mon Sep 17 00:00:00 2001 From: Bernhard Froehler Date: Sun, 25 Oct 2026 20:07:02 +0000 Subject: [PATCH] CI: use the other repository's branch of the same name only if it is ahead of main The integration jobs check out the other repository (com_bfstop / bfstop) at the branch with the name of the PR branch if one exists, else main. A branch which was merged and not deleted still exists, but is a stale copy of an old main: the next PR with that name was tested against it (bfstop#241 against com_bfstop's merged pin-actions branch, which lacked #21). Now the branch is used only if it has commits main hasn't (GitHub compare API); a failing API call fails the step instead of silently using main. Co-Authored-By: Claude Sonnet 5.5 Claude-Session: https://claude.ai/code/session_01LhhhdjhErC9ZiaS4HyRjsh --- .github/workflows/ci.yml | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b559bf7..16722a2 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -80,17 +80,26 @@ jobs: } >> "$GITHUB_ENV" - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 - # use the plugin's branch of the same name if there is one (for changes - # spanning both), else main + # use the plugin's branch of the same name if there is one and it + # has commits main hasn't (for changes spanning both), else main: a + # branch which was merged and not deleted is a stale copy of an old main - name: Determine bfstop branch id: plugin + env: + GH_TOKEN: ${{ github.token }} run: | branch="${GITHUB_HEAD_REF:-$GITHUB_REF_NAME}" - if git ls-remote --exit-code --heads https://github.com/codeling/bfstop.git "$branch" > /dev/null; then - echo "ref=$branch" >> "$GITHUB_OUTPUT" - else - echo "ref=main" >> "$GITHUB_OUTPUT" + ref=main + ahead=none + if [[ "$branch" =~ ^[A-Za-z0-9._/-]+$ ]] \ + && git ls-remote --exit-code --heads https://github.com/codeling/bfstop.git "$branch" > /dev/null; then + ahead="$(gh api "repos/codeling/bfstop/compare/main...$branch" --jq .ahead_by)" + if [ "$ahead" -gt 0 ]; then + ref="$branch" + fi fi + echo "ref=$ref" >> "$GITHUB_OUTPUT" + echo "Using bfstop $ref (a branch '$branch' there is ahead of main by: $ahead)" - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: repository: codeling/bfstop