2020 with :
2121 fetch-depth : 0
2222
23+ - uses : actions/setup-node@6044e13b5dc448c55e2357c09f80417699197238 # v6.2.0
24+ with :
25+ node-version : lts/*
26+
2327 - name : 🔍 Check for unreleased commits
2428 id : check
2529 run : |
@@ -34,21 +38,26 @@ jobs:
3438 echo "$COMMITS"
3539 fi
3640
41+ - name : 🔢 Determine next version
42+ if : steps.check.outputs.skip == 'false'
43+ id : version
44+ run : |
45+ VERSION_JSON=$(node scripts/next-version.ts)
46+ CURRENT_VERSION=$(echo "$VERSION_JSON" | jq -r .current)
47+ NEXT_VERSION=$(echo "$VERSION_JSON" | jq -r .next)
48+ FROM_REF=$(echo "$VERSION_JSON" | jq -r .from)
49+ echo "current=$CURRENT_VERSION" >> "$GITHUB_OUTPUT"
50+ echo "next=v${NEXT_VERSION}" >> "$GITHUB_OUTPUT"
51+ echo "from=$FROM_REF" >> "$GITHUB_OUTPUT"
52+
3753 - name : 📝 Generate changelog body
3854 if : steps.check.outputs.skip == 'false'
3955 id : changelog
56+ env :
57+ CURRENT_VERSION : ${{ steps.version.outputs.current }}
58+ NEXT_VERSION : ${{ steps.version.outputs.next }}
59+ FROM_REF : ${{ steps.version.outputs.from }}
4060 run : |
41- # Get the latest tag, or use initial commit if no tags exist
42- LATEST_TAG=$(git describe --tags --abbrev=0 origin/release 2>/dev/null || echo "")
43-
44- if [ -z "$LATEST_TAG" ]; then
45- FROM_REF=$(git rev-list --max-parents=0 HEAD)
46- CURRENT_VERSION="0.0.0"
47- else
48- FROM_REF="$LATEST_TAG"
49- CURRENT_VERSION="${LATEST_TAG#v}"
50- fi
51-
5261 # Categorize commits
5362 FEATURES=""
5463 FIXES=""
@@ -72,25 +81,12 @@ jobs:
7281 fi
7382 done <<< "$(git log "$FROM_REF"..origin/main --oneline --no-merges)"
7483
75- # Determine next version
76- HAS_BREAKING=$(git log "$FROM_REF"..origin/main --format='%B' | grep -c 'BREAKING CHANGE\|!:' || true)
77- HAS_FEAT=$(git log "$FROM_REF"..origin/main --oneline --no-merges | grep -cE '^[a-f0-9]+ feat(\(|:)' || true)
78-
79- IFS='.' read -r MAJOR MINOR PATCH <<< "$CURRENT_VERSION"
80-
81- if [ "$HAS_BREAKING" -gt 0 ] && [ "$MAJOR" -gt 0 ]; then
82- NEXT_VERSION="$((MAJOR + 1)).0.0"
83- elif [ "$HAS_FEAT" -gt 0 ]; then
84- NEXT_VERSION="${MAJOR}.$((MINOR + 1)).0"
85- else
86- NEXT_VERSION="${MAJOR}.${MINOR}.$((PATCH + 1))"
87- fi
88-
89- echo "next_version=v${NEXT_VERSION}" >> "$GITHUB_OUTPUT"
84+ # Strip the leading 'v' for display
85+ DISPLAY_NEXT="${NEXT_VERSION#v}"
9086
9187 # Build the PR body
9288 BODY="This PR will deploy the following changes to production (\`npmx.dev\`).\n\n"
93- BODY="${BODY}**Next version: \`v ${NEXT_VERSION}\`** (current: \`v${CURRENT_VERSION}\`)\n\n"
89+ BODY="${BODY}**Next version: \`${NEXT_VERSION}\`** (current: \`v${CURRENT_VERSION}\`)\n\n"
9490
9591 if [ -n "$FEATURES" ]; then
9692 BODY="${BODY}### Features\n\n${FEATURES}\n"
@@ -108,31 +104,31 @@ jobs:
108104 BODY="${BODY}---\n\n"
109105 BODY="${BODY}> Merging this PR will:\n"
110106 BODY="${BODY}> - Deploy to \`npmx.dev\` via Vercel\n"
111- BODY="${BODY}> - Create a \`v ${NEXT_VERSION}\` tag and GitHub Release\n"
112- BODY="${BODY}> - Publish \`npmx-connector@${NEXT_VERSION }\` to npm"
107+ BODY="${BODY}> - Create a \`${NEXT_VERSION}\` tag and GitHub Release\n"
108+ BODY="${BODY}> - Publish \`npmx-connector@${DISPLAY_NEXT }\` to npm"
113109
114110 # Write body to file, truncating if needed (GitHub limits PR body to 65536 chars)
115111 echo -e "$BODY" > /tmp/pr-body.md
116112 if [ "$(wc -c < /tmp/pr-body.md)" -gt 60000 ]; then
117113 COMMIT_COUNT=$(git log "$FROM_REF"..origin/main --oneline --no-merges | wc -l)
118114 COMPARE_URL="https://github.com/npmx-dev/npmx.dev/compare/${FROM_REF}...main"
119115 TRUNCATED="This PR will deploy the following changes to production (\`npmx.dev\`).\n\n"
120- TRUNCATED="${TRUNCATED}**Next version: \`v ${NEXT_VERSION}\`** (current: \`v${CURRENT_VERSION}\`)\n\n"
116+ TRUNCATED="${TRUNCATED}**Next version: \`${NEXT_VERSION}\`** (current: \`v${CURRENT_VERSION}\`)\n\n"
121117 TRUNCATED="${TRUNCATED}> **${COMMIT_COUNT} commits** are included in this release. The full changelog is too large to display here.\n>\n"
122118 TRUNCATED="${TRUNCATED}> [View full diff on GitHub](${COMPARE_URL})\n\n"
123119 TRUNCATED="${TRUNCATED}---\n\n"
124120 TRUNCATED="${TRUNCATED}> Merging this PR will:\n"
125121 TRUNCATED="${TRUNCATED}> - Deploy to \`npmx.dev\` via Vercel\n"
126- TRUNCATED="${TRUNCATED}> - Create a \`v ${NEXT_VERSION}\` tag and GitHub Release\n"
127- TRUNCATED="${TRUNCATED}> - Publish \`npmx-connector@${NEXT_VERSION }\` to npm"
122+ TRUNCATED="${TRUNCATED}> - Create a \`${NEXT_VERSION}\` tag and GitHub Release\n"
123+ TRUNCATED="${TRUNCATED}> - Publish \`npmx-connector@${DISPLAY_NEXT }\` to npm"
128124 echo -e "$TRUNCATED" > /tmp/pr-body.md
129125 fi
130126
131127 - name : 🚀 Create or update release PR
132128 if : steps.check.outputs.skip == 'false'
133129 env :
134130 GH_TOKEN : ${{ secrets.GITHUB_TOKEN }}
135- NEXT_VERSION : ${{ steps.changelog .outputs.next_version }}
131+ NEXT_VERSION : ${{ steps.version .outputs.next }}
136132 run : |
137133 EXISTING_PR=$(gh pr list --base release --head main --state open --json number --jq '.[0].number')
138134
0 commit comments