|
2 | 2 | # shellcheck shell=bash |
3 | 3 | set -euxo pipefail |
4 | 4 |
|
5 | | -# Get the latest released version |
6 | | -latest_tag="$(git tag --list | grep -E '^v[0-9]+\.[0-9]+\.[0-9]+(-rc\.[0-9]+)?$' | sort -V | tail -1)" |
7 | | - |
8 | | -# Check if there are commits since the last release |
9 | | -if [ -n "$latest_tag" ]; then |
10 | | - commits_since_release="$(git rev-list "$latest_tag"..HEAD --count)" |
11 | | - if [ "$commits_since_release" -eq 0 ]; then |
12 | | - echo "No commits since last release $latest_tag" |
13 | | - exit 0 |
14 | | - fi |
15 | | - echo "Found $commits_since_release commits since $latest_tag" |
16 | | -fi |
| 5 | +# Get the current package.json version before any modifications |
| 6 | +cur_pkg_version="$(jq -r .version package.json)" |
17 | 7 |
|
18 | | -# Get the next version and changelog from git-cliff |
19 | | -version="$(git cliff --bumped-version)" |
20 | | -changelog="$(git cliff --bump --unreleased | tail -n +2)" |
| 8 | +# Get the latest GitHub release version |
| 9 | +latest_release="$(gh release view --json tagName --jq .tagName 2>/dev/null || echo "")" |
| 10 | +latest_release_version="${latest_release#v}" |
21 | 11 |
|
22 | | -if [ "${DRY_RUN:-1}" == 1 ]; then |
23 | | - echo "version: $version" |
24 | | - echo "changelog: $changelog" |
25 | | - exit 0 |
26 | | -fi |
| 12 | +# Check if package.json version is newer than the latest release |
| 13 | +if [ -n "$latest_release_version" ] && [ "$cur_pkg_version" = "$latest_release_version" ]; then |
| 14 | + echo "Package version $cur_pkg_version matches latest release $latest_release. Nothing to release." |
| 15 | + # Still check if we need to create a new PR for unreleased changes |
27 | 16 |
|
28 | | -# Check if there are any unreleased changes |
29 | | -if [ -z "$changelog" ] || [ "$changelog" = "<!-- generated by git-cliff -->" ]; then |
30 | | - echo "No unreleased changes found" |
31 | | - exit 0 |
32 | | -fi |
| 17 | + # Get the latest released version tag |
| 18 | + latest_tag="$(git tag --list | grep -E '^v[0-9]+\.[0-9]+\.[0-9]+(-rc\.[0-9]+)?$' | sort -V | tail -1)" |
33 | 19 |
|
34 | | -# Configure git for automated commits |
35 | | -git config user.name mise-en-dev |
36 | | -git config user.email 123107610+mise-en-dev@users.noreply.github.com |
| 20 | + # Check if there are commits since the last release |
| 21 | + if [ -n "$latest_tag" ]; then |
| 22 | + commits_since_release="$(git rev-list "$latest_tag"..HEAD --count)" |
| 23 | + if [ "$commits_since_release" -eq 0 ]; then |
| 24 | + echo "No commits since last release $latest_tag" |
| 25 | + exit 0 |
| 26 | + fi |
| 27 | + echo "Found $commits_since_release commits since $latest_tag" |
| 28 | + fi |
37 | 29 |
|
38 | | -# Update package.json version |
39 | | -cur_pkg_version="$(jq -r .version package.json)" |
40 | | -if [ "$cur_pkg_version" != "${version#v}" ]; then |
41 | | - npm version "${version#v}" --no-git-tag-version |
42 | | - |
43 | | - git add package.json package-lock.json |
44 | | - git status |
45 | | - |
46 | | - # Create release branch and commit |
47 | | - git checkout -B release |
48 | | - git commit -m "chore: release $version" |
49 | | - |
50 | | - # Push to release branch |
51 | | - git push origin release --force |
52 | | - |
53 | | - # Create or update PR |
54 | | - if gh pr create --title "chore: release $version" --body "$changelog" --label "release"; then |
55 | | - echo "Created new release PR" |
56 | | - else |
57 | | - gh pr edit --title "chore: release $version" --body "$changelog" |
58 | | - echo "Updated existing release PR" |
59 | | - fi |
| 30 | + # Get the next version and changelog from git-cliff |
| 31 | + version="$(git cliff --bumped-version)" |
| 32 | + changelog="$(git cliff --bump --unreleased | tail -n +2)" |
| 33 | + |
| 34 | + if [ "${DRY_RUN:-1}" == 1 ]; then |
| 35 | + echo "version: $version" |
| 36 | + echo "changelog: $changelog" |
| 37 | + exit 0 |
| 38 | + fi |
| 39 | + |
| 40 | + # Check if there are any unreleased changes |
| 41 | + if [ -z "$changelog" ] || [ "$changelog" = "<!-- generated by git-cliff -->" ]; then |
| 42 | + echo "No unreleased changes found" |
| 43 | + exit 0 |
| 44 | + fi |
| 45 | + |
| 46 | + # Configure git for automated commits |
| 47 | + git config user.name mise-en-dev |
| 48 | + git config user.email 123107610+mise-en-dev@users.noreply.github.com |
| 49 | + |
| 50 | + # Create a PR with the version bump |
| 51 | + npm version "${version#v}" --no-git-tag-version |
| 52 | + |
| 53 | + git add package.json package-lock.json |
| 54 | + git status |
| 55 | + |
| 56 | + # Create release branch and commit |
| 57 | + git checkout -B release |
| 58 | + git commit -m "chore: release $version" |
| 59 | + |
| 60 | + # Push to release branch |
| 61 | + git push origin release --force |
| 62 | + |
| 63 | + # Create or update PR |
| 64 | + if gh pr create --title "chore: release $version" --body "$changelog" --label "release"; then |
| 65 | + echo "Created new release PR" |
| 66 | + else |
| 67 | + gh pr edit --title "chore: release $version" --body "$changelog" |
| 68 | + echo "Updated existing release PR" |
| 69 | + fi |
| 70 | +elif [ -n "$cur_pkg_version" ] && [ "$cur_pkg_version" != "$latest_release_version" ]; then |
| 71 | + # Package version is different from latest release, so cut a release |
| 72 | + echo "Package version v$cur_pkg_version is newer than latest release $latest_release. Creating release." |
| 73 | + |
| 74 | + # Configure git for automated commits |
| 75 | + git config user.name mise-en-dev |
| 76 | + git config user.email 123107610+mise-en-dev@users.noreply.github.com |
| 77 | + |
| 78 | + ./scripts/postversion.sh |
60 | 79 | else |
61 | | - echo "Package.json already at version ${version#v}, running postversion" |
62 | | - ./scripts/postversion.sh |
63 | | -fi |
| 80 | + echo "Could not determine release status" |
| 81 | + exit 1 |
| 82 | +fi |
0 commit comments