diff --git a/scripts/release-plz.sh b/scripts/release-plz.sh index 4f449fe..995fac4 100755 --- a/scripts/release-plz.sh +++ b/scripts/release-plz.sh @@ -2,62 +2,81 @@ # shellcheck shell=bash set -euxo pipefail -# Get the latest released version -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)" - if [ "$commits_since_release" -eq 0 ]; then - echo "No commits since last release $latest_tag" - exit 0 - fi - echo "Found $commits_since_release commits since $latest_tag" -fi - -# Get the next version and changelog from git-cliff -version="$(git cliff --bumped-version)" -changelog="$(git cliff --bump --unreleased | tail -n +2)" - -if [ "${DRY_RUN:-1}" == 1 ]; then - echo "version: $version" - echo "changelog: $changelog" - exit 0 -fi - -# Check if there are any unreleased changes -if [ -z "$changelog" ] || [ "$changelog" = "" ]; then - echo "No unreleased changes found" - exit 0 -fi - -# Configure git for automated commits -git config user.name mise-en-dev -git config user.email 123107610+mise-en-dev@users.noreply.github.com - -# Update package.json version +# Get the current package.json version before any modifications cur_pkg_version="$(jq -r .version package.json)" -if [ "$cur_pkg_version" != "${version#v}" ]; then - npm version "${version#v}" --no-git-tag-version - - git add package.json package-lock.json - git status - # Create release branch and commit - git checkout -B release - git commit -m "chore: release $version" +# Get the latest GitHub release version +latest_release="$(gh release view --json tagName --jq .tagName 2>/dev/null || echo "")" +latest_release_version="${latest_release#v}" - # Push to release branch - git push origin release --force +# 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 - # Create or update PR - if gh pr create --title "chore: release $version" --body "$changelog" --label "release"; then - echo "Created new release PR" - else - gh pr edit --title "chore: release $version" --body "$changelog" - echo "Updated existing release PR" - fi + # 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)" + if [ "$commits_since_release" -eq 0 ]; then + echo "No commits since last release $latest_tag" + exit 0 + fi + echo "Found $commits_since_release commits since $latest_tag" + fi + + # Get the next version and changelog from git-cliff + version="$(git cliff --bumped-version)" + changelog="$(git cliff --bump --unreleased | tail -n +2)" + + if [ "${DRY_RUN:-1}" == 1 ]; then + echo "version: $version" + echo "changelog: $changelog" + exit 0 + fi + + # Check if there are any unreleased changes + if [ -z "$changelog" ] || [ "$changelog" = "" ]; then + echo "No unreleased changes found" + exit 0 + fi + + # Configure git for automated commits + git config user.name mise-en-dev + git config user.email 123107610+mise-en-dev@users.noreply.github.com + + # Create a PR with the version bump + npm version "${version#v}" --no-git-tag-version + + git add package.json package-lock.json + git status + + # Create release branch and commit + git checkout -B release + git commit -m "chore: release $version" + + # Push to release branch + git push origin release --force + + # Create or update PR + if gh pr create --title "chore: release $version" --body "$changelog" --label "release"; then + echo "Created new release PR" + else + gh pr edit --title "chore: release $version" --body "$changelog" + echo "Updated existing release PR" + fi +elif [ -n "$cur_pkg_version" ] && [ "$cur_pkg_version" != "$latest_release_version" ]; then + # 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 else - echo "Package.json already at version ${version#v}, running postversion" - ./scripts/postversion.sh -fi + echo "Could not determine release status" + exit 1 +fi diff --git a/scripts/test.sh b/scripts/test.sh index 416099c..9a07937 100755 --- a/scripts/test.sh +++ b/scripts/test.sh @@ -2,10 +2,10 @@ set -euxo pipefail function assert_equal() { - if [ "$1" != "$2" ]; then - echo "Assertion failed: Expected '$1', got '$2'" >&2 - return 1 - fi + if [ "$1" != "$2" ]; then + echo "Assertion failed: Expected '$1', got '$2'" >&2 + return 1 + fi } EXPECTED_OUTPUT="jq-1.7.1" @@ -14,7 +14,7 @@ which jq # windows bash does not seem to work with shims if [[ "$(uname)" != "MINGW"* ]]; then - assert_equal "$EXPECTED_OUTPUT" "$(jq --version)" + assert_equal "$EXPECTED_OUTPUT" "$(jq --version)" fi # checking that environment variables set in mise.toml are properly set