mirror of
https://github.com/jdx/mise-action.git
synced 2026-05-14 22:00:34 +00:00
63 lines
1.9 KiB
Bash
Executable file
63 lines
1.9 KiB
Bash
Executable file
#!/usr/bin/env bash
|
|
# 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" = "<!-- generated by git-cliff -->" ]; 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
|
|
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"
|
|
|
|
# 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
|
|
else
|
|
echo "Package.json already at version ${version#v}, running postversion"
|
|
./scripts/postversion.sh
|
|
fi
|