-
Notifications
You must be signed in to change notification settings - Fork 110
263 lines (226 loc) · 8.79 KB
/
Copy pathrelease.yml
File metadata and controls
263 lines (226 loc) · 8.79 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
name: Release
on:
push:
tags:
- 'v*'
workflow_dispatch:
inputs:
version:
description: 'Version to release (e.g., 2.6.0) - leave empty to use existing tag'
required: false
type: string
dry_run:
description: 'Dry run (skip actual publish)'
required: false
type: boolean
default: false
concurrency:
group: release-${{ github.ref_name }}
cancel-in-progress: false
permissions:
contents: read
jobs:
validate:
name: Validate Release
runs-on: ubuntu-latest
outputs:
version: ${{ steps.version.outputs.version }}
tag: ${{ steps.version.outputs.tag }}
npm_tag: ${{ steps.version.outputs.npm_tag }}
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
fetch-depth: 0
- name: Determine version
id: version
run: |
if [ "${{ github.event_name }}" = "push" ]; then
# Tag push - extract version from tag
TAG="${GITHUB_REF#refs/tags/}"
VERSION="${TAG#v}"
elif [ -n "${{ inputs.version }}" ]; then
# Manual dispatch with version input
VERSION="${{ inputs.version }}"
TAG="v${VERSION}"
else
# Manual dispatch without version - use package.json
VERSION=$(node -p "require('./package.json').version")
TAG="v${VERSION}"
fi
if [[ "$VERSION" == *"-"* ]]; then
PRE_ID="${VERSION#*-}"
PRE_ID="${PRE_ID%%.*}"
case "$PRE_ID" in
beta) NPM_TAG="beta";;
rc) NPM_TAG="rc";;
*) NPM_TAG="next";;
esac
else
NPM_TAG="latest"
fi
echo "version=${VERSION}" >> $GITHUB_OUTPUT
echo "tag=${TAG}" >> $GITHUB_OUTPUT
echo "npm_tag=${NPM_TAG}" >> $GITHUB_OUTPUT
echo "[PKG] Release version: ${VERSION} (tag: ${TAG})"
echo "[PKG] npm tag: ${NPM_TAG}"
- name: Validate version format
run: |
VERSION="${{ steps.version.outputs.version }}"
if ! [[ "$VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+(-[a-zA-Z0-9.]+)?$ ]]; then
echo "[ERROR] Invalid version format: $VERSION"
echo "Expected: X.Y.Z or X.Y.Z-prerelease"
exit 1
fi
echo "[OK] Version format valid: $VERSION"
- name: Enforce release source ref
run: |
if [ "${{ github.event_name }}" = "workflow_dispatch" ] && [ "${GITHUB_REF}" != "refs/heads/main" ]; then
echo "[ERROR] workflow_dispatch releases must run from refs/heads/main (got ${GITHUB_REF})"
exit 1
fi
if [ "${{ github.event_name }}" = "push" ]; then
git fetch origin main
if ! git merge-base --is-ancestor "${GITHUB_SHA}" "origin/main"; then
echo "[ERROR] Release tag commit is not reachable from origin/main"
exit 1
fi
fi
echo "[OK] Release source ref is valid"
- name: Verify version consistency
run: |
VERSION="${{ steps.version.outputs.version }}"
echo "Checking version consistency across all files..."
# Check package.json
PKG_VERSION=$(node -p "require('./package.json').version")
if [ "$PKG_VERSION" != "$VERSION" ]; then
echo "[ERROR] package.json version ($PKG_VERSION) doesn't match release version ($VERSION)"
exit 1
fi
# Check root plugin.json (plugin repos have independent versions)
PLUGIN_VERSION=$(node -p "require('./.claude-plugin/plugin.json').version")
if [ "$PLUGIN_VERSION" != "$VERSION" ]; then
echo "[ERROR] .claude-plugin/plugin.json version ($PLUGIN_VERSION) doesn't match release version ($VERSION)"
exit 1
fi
echo "[OK] All version numbers match: $VERSION"
test:
name: Run Tests
runs-on: ubuntu-latest
needs: validate
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
- uses: actions/setup-node@53b83947a5a98c8d113130e565377fae1a50d02f # v6.3.0
with:
node-version: '20'
cache: 'npm'
- run: npm ci
- name: Run tests
run: npm test
- name: Validate plugin structure
run: node scripts/validate-plugins.js
- name: Validate repo consistency
run: npm run validate
- name: Validate agent templates
run: node scripts/expand-templates.js --check
- name: Validate adapter freshness
run: node scripts/gen-adapters.js --check
publish-npm:
name: Publish to npm
runs-on: ubuntu-latest
needs: [validate, test]
environment: npm
permissions:
contents: read
id-token: write
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
- uses: actions/setup-node@53b83947a5a98c8d113130e565377fae1a50d02f # v6.3.0
with:
node-version: '20'
cache: 'npm'
registry-url: 'https://registry.npmjs.org'
- run: npm ci
- name: Publish to npm
if: ${{ !inputs.dry_run }}
run: npm publish --provenance --access public --tag "${{ needs.validate.outputs.npm_tag }}"
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
- name: Dry run publish
if: ${{ inputs.dry_run }}
run: |
echo "[DRY-RUN] Skipping actual publish"
npm publish --dry-run --tag "${{ needs.validate.outputs.npm_tag }}"
create-release:
name: Create GitHub Release
runs-on: ubuntu-latest
needs: [validate, publish-npm]
if: ${{ !inputs.dry_run }}
permissions:
contents: write
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
fetch-depth: 0
- name: Create tag if needed
if: ${{ github.event_name == 'workflow_dispatch' }}
run: |
TAG="${{ needs.validate.outputs.tag }}"
if ! git rev-parse "$TAG" >/dev/null 2>&1; then
echo "Creating tag: $TAG"
git tag "$TAG"
git push origin "$TAG"
else
echo "Tag $TAG already exists"
fi
- name: Extract changelog for version
id: changelog
run: |
VERSION="${{ needs.validate.outputs.version }}"
# Extract changelog section for this version
CHANGELOG=$(awk "/^## \\[${VERSION}\\]/{flag=1; next} /^## \\[/{flag=0} flag" CHANGELOG.md)
if [ -z "$CHANGELOG" ]; then
CHANGELOG="See [CHANGELOG.md](https://github.com/${{ github.repository }}/blob/main/CHANGELOG.md) for details."
fi
# Write to file to preserve formatting
echo "$CHANGELOG" > release_notes.md
echo "Generated release notes:"
cat release_notes.md
- name: Create GitHub Release
uses: softprops/action-gh-release@a06a81a03ee405af7f2048a818ed3f03bbf83c7b # v2
with:
tag_name: ${{ needs.validate.outputs.tag }}
name: ${{ needs.validate.outputs.tag }}
body_path: release_notes.md
draft: false
prerelease: ${{ contains(needs.validate.outputs.version, '-') }}
generate_release_notes: false
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
notify:
name: Release Summary
runs-on: ubuntu-latest
needs: [validate, publish-npm, create-release]
if: always()
steps:
- name: Summary
run: |
echo "## Release Summary" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "**Version:** ${{ needs.validate.outputs.version }}" >> $GITHUB_STEP_SUMMARY
echo "**Tag:** ${{ needs.validate.outputs.tag }}" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
if [ "${{ needs.publish-npm.result }}" = "success" ]; then
echo "[OK] **npm:** Published successfully" >> $GITHUB_STEP_SUMMARY
echo " - https://www.npmjs.com/package/agentsys" >> $GITHUB_STEP_SUMMARY
else
echo "[ERROR] **npm:** ${{ needs.publish-npm.result }}" >> $GITHUB_STEP_SUMMARY
fi
echo "" >> $GITHUB_STEP_SUMMARY
if [ "${{ needs.create-release.result }}" = "success" ]; then
echo "[OK] **GitHub Release:** Created successfully" >> $GITHUB_STEP_SUMMARY
echo " - https://github.com/${{ github.repository }}/releases/tag/${{ needs.validate.outputs.tag }}" >> $GITHUB_STEP_SUMMARY
elif [ "${{ needs.create-release.result }}" = "skipped" ]; then
echo "[SKIP] **GitHub Release:** Skipped (dry run)" >> $GITHUB_STEP_SUMMARY
else
echo "[ERROR] **GitHub Release:** ${{ needs.create-release.result }}" >> $GITHUB_STEP_SUMMARY
fi