From 13370d4f687f39fae269078fceac011ea8a991f8 Mon Sep 17 00:00:00 2001 From: Johnathan Falk Date: Tue, 17 Nov 2026 06:34:43 -0500 Subject: [PATCH] feat(reusable-ci): add opt-in fetch-base-branch-tip input to the Go CI job go-ci checks out at depth 1 with no base ref, so a consumer test that diffs a file against the default branch cannot resolve origin/. A caller cannot add steps to a reusable workflow's job, so add a boolean input (default false) that fetches the default branch's tip at depth 1 right after checkout and verifies it resolves. The branch name is passed through env, not interpolated. Co-Authored-By: Claude Sonnet 5.5 Claude-Session: https://claude.ai/code/session_011To9HLujjbB26zYLfwT1HY --- .github/workflows/reusable-ci.yml | 29 +++++++++++++++++-- ...61117-reusable-ci-fetch-base-branch-tip.md | 16 ++++++++++ 2 files changed, 43 insertions(+), 2 deletions(-) create mode 100644 changelog.d/20261117-reusable-ci-fetch-base-branch-tip.md diff --git a/.github/workflows/reusable-ci.yml b/.github/workflows/reusable-ci.yml index 9ab61d9a..173411b3 100644 --- a/.github/workflows/reusable-ci.yml +++ b/.github/workflows/reusable-ci.yml @@ -1,7 +1,7 @@ # file: .github/workflows/reusable-ci.yml -# version: 1.21.0 +# version: 1.22.0 # guid: reusable-ci-2025-09-24-core-workflow -# last-edited: 2026-11-07 +# last-edited: 2026-11-17 name: Reusable CI Workflow @@ -69,6 +69,17 @@ on: required: false type: boolean default: true + fetch-base-branch-tip: + description: >- + Before the Go tests run, fetch the tip of the repository's default + branch at depth 1 so `origin/` resolves in the + otherwise shallow, single-ref checkout. Set true when a Go test diffs + a file against the default branch (for example a test that only lets + a list shrink) and fails without that ref. Only the Go CI job is + affected. Default false leaves the checkout unchanged. + required: false + type: boolean + default: false skip-linting: description: 'Skip linting' required: false @@ -634,6 +645,20 @@ jobs: with: submodules: recursive + # Opt-in (fetch-base-branch-tip). The checkout above is depth 1 with no + # base ref, so a test that diffs a file against the default branch has + # nothing to diff against. Fetch the default branch's tip alone, not its + # history. The branch name goes through env, never into the script text. + - name: Fetch default branch tip + if: inputs.fetch-base-branch-tip + shell: bash + env: + DEFAULT_BRANCH: ${{ github.event.repository.default_branch }} + run: | + set -euo pipefail + git fetch --no-tags --depth=1 origin "${DEFAULT_BRANCH}" + git rev-parse --verify "origin/${DEFAULT_BRANCH}" + - name: Get ghcommon workflow ref id: ghcommon-ref run: | diff --git a/changelog.d/20261117-reusable-ci-fetch-base-branch-tip.md b/changelog.d/20261117-reusable-ci-fetch-base-branch-tip.md new file mode 100644 index 00000000..a96162ba --- /dev/null +++ b/changelog.d/20261117-reusable-ci-fetch-base-branch-tip.md @@ -0,0 +1,16 @@ +### Added + +#### `reusable-ci.yml` gains an opt-in `fetch-base-branch-tip` input for Go CI + +The `go-ci` job checks the repository out at depth 1 with no base ref, so a Go +test that diffs a file against the default branch (for example a test that only +lets a list shrink) cannot resolve `origin/` and fails. A caller +cannot add a step to a reusable workflow's job, so the fetch has to live here. + +`fetch-base-branch-tip` (boolean, default `false`) adds a step right after +"Checkout repository" in `go-ci` that runs +`git fetch --no-tags --depth=1 origin "${DEFAULT_BRANCH}"` and then verifies +`origin/` resolves. `DEFAULT_BRANCH` comes from +`github.event.repository.default_branch` through `env:`, not through script +interpolation. Only the default branch's tip is fetched, never its history. The +default keeps every existing caller's behaviour unchanged.