chore: fix release-plz

This commit is contained in:
jdx 2025-08-18 11:51:16 -05:00
parent 96680f666f
commit 3600b64107
No known key found for this signature in database
GPG key ID: 584DADE86724B407
2 changed files with 78 additions and 59 deletions

View file

@ -2,42 +2,52 @@
# shellcheck shell=bash # shellcheck shell=bash
set -euxo pipefail set -euxo pipefail
# Get the latest released version # Get the current package.json version before any modifications
latest_tag="$(git tag --list | grep -E '^v[0-9]+\.[0-9]+\.[0-9]+(-rc\.[0-9]+)?$' | sort -V | tail -1)" cur_pkg_version="$(jq -r .version package.json)"
# Check if there are commits since the last release # Get the latest GitHub release version
if [ -n "$latest_tag" ]; then latest_release="$(gh release view --json tagName --jq .tagName 2>/dev/null || echo "")"
latest_release_version="${latest_release#v}"
# Check if package.json version is newer than the latest release
if [ -n "$latest_release_version" ] && [ "$cur_pkg_version" = "$latest_release_version" ]; then
echo "Package version $cur_pkg_version matches latest release $latest_release. Nothing to release."
# Still check if we need to create a new PR for unreleased changes
# Get the latest released version tag
latest_tag="$(git tag --list | grep -E '^v[0-9]+\.[0-9]+\.[0-9]+(-rc\.[0-9]+)?$' | sort -V | tail -1)"
# Check if there are commits since the last release
if [ -n "$latest_tag" ]; then
commits_since_release="$(git rev-list "$latest_tag"..HEAD --count)" commits_since_release="$(git rev-list "$latest_tag"..HEAD --count)"
if [ "$commits_since_release" -eq 0 ]; then if [ "$commits_since_release" -eq 0 ]; then
echo "No commits since last release $latest_tag" echo "No commits since last release $latest_tag"
exit 0 exit 0
fi fi
echo "Found $commits_since_release commits since $latest_tag" echo "Found $commits_since_release commits since $latest_tag"
fi fi
# Get the next version and changelog from git-cliff # Get the next version and changelog from git-cliff
version="$(git cliff --bumped-version)" version="$(git cliff --bumped-version)"
changelog="$(git cliff --bump --unreleased | tail -n +2)" changelog="$(git cliff --bump --unreleased | tail -n +2)"
if [ "${DRY_RUN:-1}" == 1 ]; then if [ "${DRY_RUN:-1}" == 1 ]; then
echo "version: $version" echo "version: $version"
echo "changelog: $changelog" echo "changelog: $changelog"
exit 0 exit 0
fi fi
# Check if there are any unreleased changes # Check if there are any unreleased changes
if [ -z "$changelog" ] || [ "$changelog" = "<!-- generated by git-cliff -->" ]; then if [ -z "$changelog" ] || [ "$changelog" = "<!-- generated by git-cliff -->" ]; then
echo "No unreleased changes found" echo "No unreleased changes found"
exit 0 exit 0
fi fi
# Configure git for automated commits # Configure git for automated commits
git config user.name mise-en-dev git config user.name mise-en-dev
git config user.email 123107610+mise-en-dev@users.noreply.github.com git config user.email 123107610+mise-en-dev@users.noreply.github.com
# Update package.json version # Create a PR with the version bump
cur_pkg_version="$(jq -r .version package.json)"
if [ "$cur_pkg_version" != "${version#v}" ]; then
npm version "${version#v}" --no-git-tag-version npm version "${version#v}" --no-git-tag-version
git add package.json package-lock.json git add package.json package-lock.json
@ -57,7 +67,16 @@ if [ "$cur_pkg_version" != "${version#v}" ]; then
gh pr edit --title "chore: release $version" --body "$changelog" gh pr edit --title "chore: release $version" --body "$changelog"
echo "Updated existing release PR" echo "Updated existing release PR"
fi fi
else elif [ -n "$cur_pkg_version" ] && [ "$cur_pkg_version" != "$latest_release_version" ]; then
echo "Package.json already at version ${version#v}, running postversion" # Package version is different from latest release, so cut a release
echo "Package version v$cur_pkg_version is newer than latest release $latest_release. Creating release."
# Configure git for automated commits
git config user.name mise-en-dev
git config user.email 123107610+mise-en-dev@users.noreply.github.com
./scripts/postversion.sh ./scripts/postversion.sh
else
echo "Could not determine release status"
exit 1
fi fi