Skip to content

Commit 1166335

Browse files
committed
ci: address follow-up Copilot review
Cross-port of dunglas/mercure#1246 follow-up: - Use matching-refs in create_tag so transient API failures aren't read as "tag absent". - Build the release tree from `git status` partitions so additions, deletions, and modifications round-trip correctly. - Clarify the "no file changes" error with operator guidance. - Check that git is installed in release.sh.
1 parent 8b157a5 commit 1166335

2 files changed

Lines changed: 37 additions & 19 deletions

File tree

.github/workflows/release.yaml

Lines changed: 31 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -177,21 +177,33 @@ jobs:
177177
parent_sha=$(gh api "repos/${REPO}/git/refs/heads/main" -q .object.sha)
178178
base_tree=$(gh api "repos/${REPO}/git/commits/${parent_sha}" -q .tree.sha)
179179
180-
# Capture every touched file so transitive go.sum or PGO
181-
# side effects aren't dropped from the release commit.
182-
mapfile -t changed < <(git diff --name-only HEAD)
183-
if [[ ${#changed[@]} -eq 0 ]]; then
184-
echo "::error::No file changes detected after PGO/bump steps."
180+
# Capture every touched file (modifications, additions,
181+
# deletions) so transitive go.sum or PGO side effects aren't
182+
# dropped from the release commit. Deletions are represented
183+
# with a null sha in the tree.
184+
mapfile -t modified < <(git diff --name-only --diff-filter=ACMR HEAD)
185+
mapfile -t deleted < <(git diff --name-only --diff-filter=D HEAD)
186+
mapfile -t untracked < <(git ls-files --others --exclude-standard)
187+
if [[ ${#modified[@]} -eq 0 && ${#deleted[@]} -eq 0 && ${#untracked[@]} -eq 0 ]]; then
188+
echo "::error::No file changes after PGO/bump. Is v${VERSION} already on main? Delete the local tags and pick a different version, or recreate the tags manually."
185189
exit 1
186190
fi
187-
printf 'Including in release tree: %s\n' "${changed[@]}"
191+
present=("${modified[@]}" "${untracked[@]}")
192+
[[ ${#present[@]} -gt 0 ]] && printf 'Including (added/modified): %s\n' "${present[@]}"
193+
[[ ${#deleted[@]} -gt 0 ]] && printf 'Including (deleted): %s\n' "${deleted[@]}"
188194
189195
tree_entries=$(
190-
for path in "${changed[@]}"; do
191-
sha=$(make_blob "${path}")
192-
jq -nc --arg path "${path}" --arg sha "${sha}" \
193-
'{path: $path, mode: "100644", type: "blob", sha: $sha}'
194-
done | jq -sc .
196+
{
197+
for path in "${modified[@]}" "${untracked[@]}"; do
198+
sha=$(make_blob "${path}")
199+
jq -nc --arg path "${path}" --arg sha "${sha}" \
200+
'{path: $path, mode: "100644", type: "blob", sha: $sha}'
201+
done
202+
for path in "${deleted[@]}"; do
203+
jq -nc --arg path "${path}" \
204+
'{path: $path, mode: "100644", type: "blob", sha: null}'
205+
done
206+
} | jq -sc .
195207
)
196208
197209
tree_sha=$(jq -nc \
@@ -213,14 +225,18 @@ jobs:
213225
fi
214226
215227
# Idempotent: skip if tag already points at the release commit,
216-
# fail if it points elsewhere.
228+
# fail if it points elsewhere. matching-refs distinguishes
229+
# "tag absent" (HTTP 200, empty array) from real failures, which
230+
# still trip set -e.
217231
create_tag() {
218232
local tag="$1"
219233
local existing
220-
if existing=$(gh api "repos/${REPO}/git/refs/tags/${tag}" 2>/dev/null); then
234+
existing=$(gh api "repos/${REPO}/git/matching-refs/tags/${tag}" \
235+
--jq ".[] | select(.ref == \"refs/tags/${tag}\") | {sha: .object.sha, type: .object.type}")
236+
if [[ -n "${existing}" ]]; then
221237
local obj_sha obj_type
222-
obj_sha=$(jq -r .object.sha <<<"${existing}")
223-
obj_type=$(jq -r .object.type <<<"${existing}")
238+
obj_sha=$(jq -r .sha <<<"${existing}")
239+
obj_type=$(jq -r .type <<<"${existing}")
224240
if [[ "${obj_type}" == "tag" ]]; then
225241
obj_sha=$(gh api "repos/${REPO}/git/tags/${obj_sha}" -q .object.sha)
226242
fi

release.sh

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,12 @@ set -o errexit
99
set -o pipefail
1010
trap 'echo "Aborting on line $LINENO. Exit: $?" >&2' ERR
1111

12-
if ! command -v gh >/dev/null; then
13-
echo 'The "gh" command must be installed.' >&2
14-
exit 1
15-
fi
12+
for cmd in git gh; do
13+
if ! command -v "$cmd" >/dev/null; then
14+
echo "The \"$cmd\" command must be installed." >&2
15+
exit 1
16+
fi
17+
done
1618

1719
if [[ $# -ne 1 ]]; then
1820
echo "Usage: ./release.sh version" >&2

0 commit comments

Comments
 (0)