Skip to content
Merged
Show file tree
Hide file tree
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
35 changes: 34 additions & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -361,16 +361,49 @@ jobs:
path: release
merge-multiple: true

# `--unreleased` means "commits belonging to no tag". On the tag-push route
# the tag already points at HEAD by the time this runs, so nothing is
# unreleased and the notes come out empty — which is exactly what shipped
# in v0.3.1. Resolve an explicit <prev>..<tag> range instead, and only fall
# back to --unreleased when the tag genuinely does not exist yet (the
# workflow_dispatch route, where release-plz tags before dispatching).
- name: Resolve the changelog range
id: range
env:
TAG: ${{ needs.plan.outputs.release_tag }}
run: |
set -euo pipefail
if git rev-parse -q --verify "refs/tags/${TAG}" >/dev/null; then
PREV="$(git describe --tags --abbrev=0 "${TAG}^" 2>/dev/null || true)"
if [[ -n "$PREV" ]]; then
ARGS="${PREV}..${TAG}"
else
ARGS="--tag ${TAG}" # first ever release: no predecessor
fi
else
ARGS="--unreleased --tag ${TAG}"
fi
echo "resolved git-cliff range args: ${ARGS}"
echo "args=${ARGS}" >> "$GITHUB_OUTPUT"

- name: Generate changelog from commits
uses: orhun/git-cliff-action@v4
id: changelog
with:
config: cliff.toml
args: --unreleased --tag ${{ needs.plan.outputs.release_tag }} --strip header
args: ${{ steps.range.outputs.args }} --strip header
env:
OUTPUT: release-changelog.md
GITHUB_REPO: ${{ github.repository }}

# An empty changelog is not a fatal condition, but it is always a bug —
# v0.3.1 shipped one and nothing said so.
- name: Warn on an empty changelog
run: |
if [[ ! -s release-changelog.md ]] || ! grep -qE '^\s*-' release-changelog.md; then
echo "::warning::the generated changelog has no entries — check the range resolved above"
fi

- name: Compose release body
env:
TAG: ${{ needs.plan.outputs.release_tag }}
Expand Down
9 changes: 7 additions & 2 deletions cliff.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,13 @@ body = """
- {% if commit.scope %}**{{ commit.scope }}**: {% endif %}{{ commit.message | split(pat="\n") | first | trim }}
{% endfor %}
{% endfor -%}
{% if previous and previous.version %}
**Full Changelog**: https://github.com/reddb-io/dit/compare/{{ previous.version }}...{{ version }}
{% if previous and previous.version and previous.version != version %}
{# Our tags carry a `v` prefix, but the two callers disagree on whether the
rendered version does: release-plz passes a bare `0.3.2` while release.yml
passes the tag `v0.3.2` (hence the trim on the heading above). Emitting
either verbatim produces a 404 in one of the two — `compare/0.3.1...0.3.2`
was the broken half. Normalise, then re-add the `v` the tags actually use. #}
**Full Changelog**: https://github.com/reddb-io/dit/compare/v{{ previous.version | trim_start_matches(pat="v") }}...v{{ version | trim_start_matches(pat="v") }}
{% endif %}
"""

Expand Down