forked from neplextech/commandkit
-
Notifications
You must be signed in to change notification settings - Fork 0
204 lines (174 loc) · 6.65 KB
/
publish-latest.yaml
File metadata and controls
204 lines (174 loc) · 6.65 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
name: Publish latest builds
on:
workflow_dispatch:
inputs:
version:
description: 'Version to publish (e.g., 1.2.3)'
required: true
type: string
permissions:
id-token: write
contents: write
jobs:
publish:
name: Publish latest builds
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
registry-url: https://registry.npmjs.org
cache: 'pnpm'
- name: Install dependencies
run: pnpm install --frozen-lockfile
- name: Validate version input
run: |
if ! [[ "${{ github.event.inputs.version }}" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "❌ Version must be in semantic version format (e.g., 1.2.3)"
exit 1
fi
- name: Update package versions
run: |
target_version="${{ github.event.inputs.version }}"
echo "Setting version to: $target_version"
for dir in packages/*; do
[ -f "$dir/package.json" ] || continue
echo "Updating $dir/package.json..."
node -e "
const fs = require('fs');
const path = './$dir/package.json';
const pkg = require(path);
pkg.version = '$target_version';
fs.writeFileSync(path, JSON.stringify(pkg, null, 2));
console.log('Updated ' + pkg.name + ' to version ' + pkg.version);
"
done
- name: Build packages
run: pnpm dlx turbo build --filter='./packages/*'
- name: Publish packages
run: |
PACKAGES=(
"commandkit:packages/commandkit"
"create-commandkit:packages/create-commandkit"
"@commandkit/redis:packages/redis"
"@commandkit/i18n:packages/i18n"
"@commandkit/devtools:packages/devtools"
"@commandkit/cache:packages/cache"
"@commandkit/analytics:packages/analytics"
"@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"
echo "Publishing $name..."
VERSION=$(node -p "require('./$path/package.json').version")
if npm view "$name@$VERSION" version >/dev/null 2>&1; then
echo "📦 $name@$VERSION already exists on npm, skipping..."
else
if pnpm --filter="$name" publish --no-git-checks --access public; then
echo "✅ Published $name@$VERSION"
else
if 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
fi
fi
done
- name: Generate changelog
id: changelog
run: |
VERSION="v${{ github.event.inputs.version }}"
# Find the previous version tag
PREV_TAG=$(git tag --sort=-v:refname | grep -E '^v[0-9]+\.[0-9]+\.[0-9]+$' | head -n 1)
if [ -z "$PREV_TAG" ]; then
COMMIT_RANGE="HEAD"
echo "No previous tag found, using all commits"
else
COMMIT_RANGE="${PREV_TAG}..HEAD"
echo "Generating changelog from $PREV_TAG to HEAD"
fi
PACKAGES=(
"commandkit:packages/commandkit"
"create-commandkit:packages/create-commandkit"
"@commandkit/redis:packages/redis"
"@commandkit/i18n:packages/i18n"
"@commandkit/devtools:packages/devtools"
"@commandkit/cache:packages/cache"
"@commandkit/analytics:packages/analytics"
"@commandkit/ai:packages/ai"
"@commandkit/queue:packages/queue"
"@commandkit/tasks:packages/tasks"
"@commandkit/workflow:packages/workflow"
)
CHANGELOG=""
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
FEATS=""
FIXES=""
CHORES=""
DOCS=""
REFACTORS=""
PERFS=""
TESTS=""
OTHERS=""
while IFS='|' read -r msg hash; do
line="- ${msg} (\`${hash}\`)"
case "$msg" in
feat:*|feat\(*) FEATS+=$'\n'"$line" ;;
fix:*|fix\(*) FIXES+=$'\n'"$line" ;;
chore:*|chore\(*) CHORES+=$'\n'"$line" ;;
docs:*|docs\(*) DOCS+=$'\n'"$line" ;;
refactor:*|refactor\(*) REFACTORS+=$'\n'"$line" ;;
perf:*|perf\(*) PERFS+=$'\n'"$line" ;;
test:*|test\(*|tests:*|tests\(*) TESTS+=$'\n'"$line" ;;
*) OTHERS+=$'\n'"$line" ;;
esac
done <<< "$COMMITS"
PKG_SECTION="## ${name}"$'\n'
HAS_CONTENT=false
for category_label in \
"🚀 Features|$FEATS" \
"🐛 Bug Fixes|$FIXES" \
"🧹 Chores|$CHORES" \
"📖 Documentation|$DOCS" \
"♻️ Refactors|$REFACTORS" \
"⚡ Performance|$PERFS" \
"🧪 Tests|$TESTS" \
"📦 Other Changes|$OTHERS"; do
IFS='|' read -r label content <<< "$category_label"
if [ -n "$content" ]; then
PKG_SECTION+=$'\n'"### ${label}"$'\n'"${content}"$'\n'
HAS_CONTENT=true
fi
done
if [ "$HAS_CONTENT" = true ]; then
CHANGELOG+=$'\n'"${PKG_SECTION}"$'\n'
fi
done
if [ -z "$CHANGELOG" ]; then
CHANGELOG="No package changes detected since the last release."
fi
# Write to file to avoid shell escaping issues
echo "$CHANGELOG" > /tmp/changelog.md
- name: Create GitHub draft release
uses: softprops/action-gh-release@v2
with:
tag_name: v${{ github.event.inputs.version }}
name: v${{ github.event.inputs.version }}
body_path: /tmp/changelog.md
draft: true
generate_release_notes: false