-
-
Notifications
You must be signed in to change notification settings - Fork 22
265 lines (235 loc) · 9.37 KB
/
Copy pathpublish-latest.yaml
File metadata and controls
265 lines (235 loc) · 9.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
name: Publish packages
on:
workflow_dispatch:
inputs:
version:
description: 'Release version or npm tag (e.g., 1.2.3, 1.2.3-rc.1, or canary)'
required: false
type: string
permissions:
id-token: write
contents: write
jobs:
publish:
name: Publish packages
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- uses: pnpm/action-setup@v4
with:
version: '10.30.3'
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: actions/setup-node@v4
with:
node-version: 24
- name: Install dependencies
run: pnpm install --frozen-lockfile
- name: Determine release mode
id: release
env:
VERSION_INPUT: ${{ github.event.inputs.version || '' }}
run: |
input="$VERSION_INPUT"
timestamp=$(date -u +'%Y%m%d%H%M%S')
strict_version_regex='^(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)$'
prerelease_regex='^(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)-([0-9A-Za-z-]+)\.([0-9]+)$'
if [[ "$input" =~ $strict_version_regex ]]; then
publish_tag='latest'
package_version="$input"
release_tag="v$input"
release_name="v$input"
prerelease='false'
mode='release'
elif [[ "$input" =~ $prerelease_regex ]]; then
publish_tag="${BASH_REMATCH[4]}"
package_version="$input"
release_tag="v$input"
release_name="v$input"
prerelease='true'
mode='prerelease'
else
publish_tag="${input:-dev}"
if [[ ! "$publish_tag" =~ ^[A-Za-z0-9][A-Za-z0-9._-]*$ ]]; then
echo "Invalid npm dist-tag: $publish_tag"
exit 1
fi
package_version=''
dev_suffix="-dev.$timestamp"
release_tag="dev-$timestamp"
release_name="Development build $timestamp"
prerelease='true'
mode='development'
fi
{
echo "publish_tag=$publish_tag"
echo "package_version=$package_version"
echo "release_tag=$release_tag"
echo "release_name=$release_name"
echo "prerelease=$prerelease"
echo "mode=$mode"
echo "dev_suffix=${dev_suffix:-}"
} >> "$GITHUB_OUTPUT"
echo "Mode: $mode"
echo "NPM tag: $publish_tag"
if [ -n "$package_version" ]; then
echo "Package version: $package_version"
else
echo "Package version suffix: $dev_suffix"
fi
- name: Update package versions
env:
MODE: ${{ steps.release.outputs.mode }}
PACKAGE_VERSION: ${{ steps.release.outputs.package_version }}
DEV_SUFFIX: ${{ steps.release.outputs.dev_suffix }}
run: |
for dir in packages/*; do
[ -f "$dir/package.json" ] || continue
if [ "$MODE" = 'development' ]; then
node -e '
const fs = require("fs");
const path = process.argv[1];
const suffix = process.argv[2];
const pkg = JSON.parse(fs.readFileSync(path, "utf8"));
pkg.version += suffix;
fs.writeFileSync(path, JSON.stringify(pkg, null, 2) + "\n");
console.log(`Updated ${pkg.name} to ${pkg.version}`);
' "$dir/package.json" "$DEV_SUFFIX"
else
node -e '
const fs = require("fs");
const path = process.argv[1];
const version = process.argv[2];
const pkg = JSON.parse(fs.readFileSync(path, "utf8"));
pkg.version = version;
fs.writeFileSync(path, JSON.stringify(pkg, null, 2) + "\n");
console.log(`Updated ${pkg.name} to ${pkg.version}`);
' "$dir/package.json" "$PACKAGE_VERSION"
fi
done
- name: Build packages
run: pnpm dlx turbo build --filter='./packages/*'
- name: Publish packages with npm trusted publishing
env:
NPM_TAG: ${{ steps.release.outputs.publish_tag }}
run: |
PACKAGES=(
"commandkit:packages/commandkit"
"create-commandkit:packages/create-commandkit"
"@commandkit/redis:packages/redis"
"@commandkit/i18n:packages/i18n"
"@commandkit/cache:packages/cache"
"@commandkit/analytics:packages/analytics"
"@commandkit/ratelimit:packages/ratelimit"
"@commandkit/ai:packages/ai"
"@commandkit/queue:packages/queue"
"@commandkit/tasks:packages/tasks"
"@commandkit/workflow:packages/workflow"
)
for entry in "${PACKAGES[@]}"; do
IFS=":" read -r name path <<< "$entry"
version=$(node -p "require('./$path/package.json').version")
echo "Publishing $name@$version under '$NPM_TAG'..."
if npm view "$name@$version" version >/dev/null 2>&1; then
echo "📦 $name@$version already exists on npm, skipping..."
elif (
cd "$path"
npm publish --provenance --access public --tag "$NPM_TAG"
); then
echo "✅ Published $name@$version under '$NPM_TAG'"
elif npm view "$name@$version" version >/dev/null 2>&1; then
echo "📦 $name@$version was published by another process, skipping..."
else
echo "❌ Failed to publish $name@$version"
exit 1
fi
done
- name: Generate changelog
env:
RELEASE_TAG: ${{ steps.release.outputs.release_tag }}
NPM_TAG: ${{ steps.release.outputs.publish_tag }}
RELEASE_MODE: ${{ steps.release.outputs.mode }}
run: |
previous_tag=$(git tag --sort=-v:refname | grep -E '^v[0-9]+\.[0-9]+\.[0-9]+$' | head -n 1)
if [ -z "$previous_tag" ]; then
commit_range='HEAD'
echo 'No previous stable tag found, using all commits'
else
commit_range="$previous_tag..HEAD"
echo "Generating changelog from $previous_tag to HEAD"
fi
PACKAGES=(
"commandkit:packages/commandkit"
"create-commandkit:packages/create-commandkit"
"@commandkit/redis:packages/redis"
"@commandkit/i18n:packages/i18n"
"@commandkit/cache:packages/cache"
"@commandkit/analytics:packages/analytics"
"@commandkit/ratelimit:packages/ratelimit"
"@commandkit/ai:packages/ai"
"@commandkit/queue:packages/queue"
"@commandkit/tasks:packages/tasks"
"@commandkit/workflow:packages/workflow"
)
changelog="## $RELEASE_TAG\n\n"
changelog+="Published under the npm \`$NPM_TAG\` tag in \`$RELEASE_MODE\` mode.\n"
for entry in "${PACKAGES[@]}"; do
IFS=":" read -r name path <<< "$entry"
commits=$(git log "$commit_range" --pretty=format:"%s|%h" -- "$path" 2>/dev/null || true)
[ -z "$commits" ] && continue
features=''
fixes=''
chores=''
docs=''
refactors=''
performance=''
tests=''
others=''
while IFS='|' read -r message hash; do
line="- ${message} (\`${hash}\`)"
case "$message" in
feat:*|feat\(*) features+=$'\n'"$line" ;;
fix:*|fix\(*) fixes+=$'\n'"$line" ;;
chore:*|chore\(*) chores+=$'\n'"$line" ;;
docs:*|docs\(*) docs+=$'\n'"$line" ;;
refactor:*|refactor\(*) refactors+=$'\n'"$line" ;;
perf:*|perf\(*) performance+=$'\n'"$line" ;;
test:*|test\(*|tests:*|tests\(*) tests+=$'\n'"$line" ;;
*) others+=$'\n'"$line" ;;
esac
done <<< "$commits"
package_section="### ${name}\n"
has_content=false
for category in \
"Features|$features" \
"Bug Fixes|$fixes" \
"Chores|$chores" \
"Documentation|$docs" \
"Refactors|$refactors" \
"Performance|$performance" \
"Tests|$tests" \
"Other Changes|$others"; do
IFS='|' read -r label content <<< "$category"
if [ -n "$content" ]; then
package_section+="\n#### ${label}\n${content}\n"
has_content=true
fi
done
if [ "$has_content" = true ]; then
changelog+="\n${package_section}\n"
fi
done
if [ "$changelog" = "## $RELEASE_TAG\n\nPublished under the npm \`$NPM_TAG\` tag in \`$RELEASE_MODE\` mode.\n" ]; then
changelog+="\nNo package changes detected since the last stable release.\n"
fi
printf '%b' "$changelog" > /tmp/changelog.md
- name: Create GitHub release
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ steps.release.outputs.release_tag }}
name: ${{ steps.release.outputs.release_name }}
body_path: /tmp/changelog.md
prerelease: ${{ steps.release.outputs.prerelease }}
draft: false
generate_release_notes: false