Skip to content

Commit 91dda42

Browse files
committed
fix(release-changelog): handle missing bootstrap previous version
1 parent 0775100 commit 91dda42

2 files changed

Lines changed: 12 additions & 2 deletions

File tree

release/changelog/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ Generates a release changelog with `git-cliff` and stages the output file.
44

55
Use this action in release workflows that need a changelog file, a step summary, and an optional artifact generated from the commit range between the previous version and the new version.
66

7+
When `previous-version` is `0.0.0` and that ref does not exist, the action treats the release as the initial changelog generation. It warns in the workflow log, generates from `HEAD` so the first commit is included, and disables prepend mode for that run.
8+
79
```yaml
810
steps:
911
- uses: actions/checkout@v6

release/changelog/action.yml

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,16 +109,24 @@ runs:
109109
git-cliff --version
110110
111111
echo "Setting up git-cliff context..."
112+
initial_release_without_previous_ref="false"
113+
if [ "${PREVIOUS_VERSION}" = "0.0.0" ] && ! git rev-parse --verify --quiet "${PREVIOUS_VERSION}^{commit}" >/dev/null; then
114+
initial_release_without_previous_ref="true"
115+
echo "::warning title=Release changelog::Previous version 0.0.0 does not exist; generating the initial changelog from HEAD and disabling prepend."
116+
fi
117+
112118
output="${CHANGELOG_OUTPUT}"
113-
if [ "${PREPEND}" = "true" ]; then
119+
if [ "${PREPEND}" = "true" ] && [ "${initial_release_without_previous_ref}" != "true" ]; then
114120
output="${RUNNER_TEMP}/cliff/changelog/${CHANGELOG_OUTPUT}"
115121
mkdir -p "$(dirname "${output}")"
116122
[ -f "${output}" ] || touch "${output}"
117123
fi
118124
119125
range="${PREVIOUS_VERSION}..${VERSION}"
120126
prepend_args=()
121-
if [ "${PREPEND}" = "true" ]; then
127+
if [ "${initial_release_without_previous_ref}" = "true" ]; then
128+
range="HEAD"
129+
elif [ "${PREPEND}" = "true" ]; then
122130
range="${PREVIOUS_VERSION}..HEAD"
123131
prepend_args=(--prepend "${CHANGELOG_OUTPUT}")
124132
fi

0 commit comments

Comments
 (0)