Skip to content

Commit be6e883

Browse files
committed
fix(ci): let each consumer decide what "no previous release" means
The fallback filled NOTES_START_TAG with the root commit's SHA so the range would always be valid. That is right for the RC path, which feeds it to `git log`, and wrong for the stable path, which feeds it to `gh release create --notes-start-tag` -- the API's previous_tag_name, which takes a tag NAME. A SHA there is an invalid argument, not a lenient fallback, so the one case the fallback existed for would still have failed. It now stays empty when no tag is reachable, and each consumer handles that: the RC notes walk the whole history and drop the "since <tag>" wording rather than printing a blank where a tag should be, and the stable path omits the flag so GitHub picks its own previous release -- which is the correct answer when there is not one. Unreachable on this repo today (v1.9.2 is right there), so this is about the next fork or a fresh repository rather than about 1.9.4.
1 parent 6112f4f commit be6e883

1 file changed

Lines changed: 35 additions & 10 deletions

File tree

.github/workflows/build.yml

Lines changed: 35 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -756,12 +756,15 @@ jobs:
756756
# handled a skipped stable, and it does not run at all for an rc.1.
757757
if ! git rev-parse -q --verify "refs/tags/${NOTES_START_TAG}" >/dev/null; then
758758
# The nearest tag reachable from the release commit's parent, which
759-
# is what "since the last release" meant in the first place. Empty
760-
# only when no tag is reachable at all (a first release), so fall
761-
# back to the root commit to keep the range valid either way.
762-
FALLBACK="$(git describe --tags --abbrev=0 "${TAG}^" 2>/dev/null || true)"
763-
NOTES_START_TAG="${FALLBACK:-$(git rev-list --max-parents=0 HEAD | tail -1)}"
764-
echo "Previous-release tag did not exist; starting notes from ${NOTES_START_TAG}"
759+
# is what "since the last release" meant in the first place. Left
760+
# EMPTY when no tag is reachable at all, rather than filled with the
761+
# root commit: the stable path hands this to `gh release create
762+
# --notes-start-tag`, which is the API's previous_tag_name and takes
763+
# a tag NAME -- a commit SHA there is not a lenient fallback, it is
764+
# an invalid argument. Each consumer below decides what "no previous
765+
# release" means for it.
766+
NOTES_START_TAG="$(git describe --tags --abbrev=0 "${TAG}^" 2>/dev/null || true)"
767+
echo "Previous-release tag did not exist; using ${NOTES_START_TAG:-<none>}"
765768
fi
766769
echo "Computed notes_start_tag=${NOTES_START_TAG} for tag=${TAG}"
767770
@@ -820,14 +823,26 @@ jobs:
820823
# the re-cut was for. The commit range is the actual diff and can't lie.
821824
# Stable releases keep --generate-notes below: they're the public-facing
822825
# ones and want the PR links and the New Contributors section.
826+
# With no previous tag at all, the range is the whole history and
827+
# there is nothing to compare against, so say so rather than
828+
# emitting "since " with a blank where a tag should be.
829+
if [[ -n "$NOTES_START_TAG" ]]; then
830+
RC_RANGE="${NOTES_START_TAG}..${TAG}"
831+
RC_HEADING="## Changes since ${NOTES_START_TAG}"
832+
RC_LINK="**Full Changelog**: ${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}/compare/${NOTES_START_TAG}...${TAG}"
833+
else
834+
RC_RANGE="$TAG"
835+
RC_HEADING="## Changes"
836+
RC_LINK="**Full Changelog**: ${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}/commits/${TAG}"
837+
fi
823838
{
824-
echo "## Changes since ${NOTES_START_TAG}"
839+
echo "$RC_HEADING"
825840
echo
826841
git log --no-merges --reverse --pretty='- %s' \
827842
--invert-grep --grep='^chore(release): bump to' \
828-
"${NOTES_START_TAG}..${TAG}"
843+
"$RC_RANGE"
829844
echo
830-
echo "**Full Changelog**: ${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}/compare/${NOTES_START_TAG}...${TAG}"
845+
echo "$RC_LINK"
831846
} > "${RUNNER_TEMP}/rc-notes.md"
832847
cat "${RUNNER_TEMP}/rc-notes.md"
833848
NOTES_ARGS=(--notes-file "${RUNNER_TEMP}/rc-notes.md")
@@ -837,7 +852,17 @@ jobs:
837852
# prior release by date) doesn't work for this fork because the v1.4.0
838853
# release in the fork was re-published after v1.5.0, which makes GitHub
839854
# pick v1.4.0 as the "previous" for any v1.5.x release.
840-
NOTES_ARGS=(--generate-notes --notes-start-tag "$NOTES_START_TAG")
855+
#
856+
# Omitted entirely when there is no previous tag: this maps to the
857+
# API's previous_tag_name, which takes a tag NAME. Passing an empty
858+
# string or a commit SHA is an invalid argument, not a graceful
859+
# degradation. Without it GitHub falls back to its own choice of
860+
# previous release, which is exactly right when there isn't one.
861+
if [[ -n "$NOTES_START_TAG" ]]; then
862+
NOTES_ARGS=(--generate-notes --notes-start-tag "$NOTES_START_TAG")
863+
else
864+
NOTES_ARGS=(--generate-notes)
865+
fi
841866
fi
842867
# shellcheck disable=SC2086
843868
gh release create "$TAG" "${FILES[@]}" \

0 commit comments

Comments
 (0)