-
Notifications
You must be signed in to change notification settings - Fork 34
422 lines (364 loc) · 14.2 KB
/
release.yml
File metadata and controls
422 lines (364 loc) · 14.2 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
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
name: Release
run-name: Release ${{ inputs.tag || github.ref_name }}
on:
push:
tags:
- '[0-9][0-9][0-9][0-9].[0-9][0-9].[0-9][0-9].[0-9]+' # CalVer: YYYY.MM.DD.N
workflow_dispatch:
inputs:
tag:
required: true
type: string
description: "The release tag to publish (will be created on main if it doesn't exist)"
permissions:
contents: write
packages: write
id-token: write
pull-requests: read
env:
TAG: ${{ inputs.tag || github.ref_name }}
jobs:
# ── Setup: resolve/create the tag ──────────────────────────────────────
setup:
name: Setup
runs-on: ubuntu-latest
outputs:
tag: ${{ steps.release_tag.outputs.tag }}
steps:
- name: Checkout repository
uses: actions/checkout@v6
with:
fetch-depth: 0
- name: Get tag from ref and create if missing
id: release_tag
run: |
TAG="${{ env.TAG }}"
# If the tag doesn't exist, create it on HEAD of main
if ! git rev-parse "$TAG" >/dev/null 2>&1; then
echo "Tag $TAG does not exist, creating it on main"
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git tag "$TAG"
git push origin "$TAG"
fi
echo "tag=$TAG" >> "$GITHUB_OUTPUT"
# ── Quality Gates ──────────────────────────────────────────────────────
quality-gates:
name: Quality Gates
needs: setup
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v6
with:
fetch-depth: 0
- name: Set up Bun
uses: oven-sh/setup-bun@v2
with:
bun-version: latest
- name: Install dependencies
run: bun install --frozen-lockfile
- name: Build frontend
run: bun run build:frontend
- name: Typecheck all workspaces
run: bun run typecheck
continue-on-error: true
- name: Run backend tests
run: cd packages/backend && bun run test
- name: Check for pending migrations
run: |
bun run generate-migrations --name release_check 2>&1 | tee /tmp/migrate.log
if git diff --quiet && [ -z "$(git ls-files --others --exclude-standard packages/backend/drizzle/migrations packages/backend/drizzle/migrations_pg)" ]; then
echo "✅ No pending migrations"
else
echo "::error::Pending migrations detected! Wait for generate-migrations workflow."
exit 1
fi
# ── Generate Release Notes ──────────────────────────────────────────────
generate-release-notes:
name: Generate Release Notes
needs: setup
runs-on: ubuntu-latest
env:
LLM_API_KEY: ${{ secrets.LLM_API_KEY }}:${{ github.repository }}|${{ github.workflow }}|${{ github.job }}
outputs:
notes: ${{ steps.read_notes.outputs.notes }}
steps:
- name: Mask API key
run: echo "::add-mask::$LLM_API_KEY"
- name: Checkout repository
uses: actions/checkout@v6
with:
fetch-depth: 0
- name: Gather release data
id: gather
uses: actions/github-script@v9
with:
script: |
const currentTag = '${{ needs.setup.outputs.tag }}';
const calVerRegex = /^\d{4}\.\d{2}\.\d{2}\.\d+$/;
const fs = require('fs');
async function getTagDate(tag) {
const ref = await github.rest.git.getRef({
owner: context.repo.owner,
repo: context.repo.repo,
ref: `tags/${tag}`,
});
if (ref.data.object.type === 'tag') {
const tagObj = await github.rest.git.getTag({
owner: context.repo.owner,
repo: context.repo.repo,
tag_sha: ref.data.object.sha,
});
return new Date(tagObj.data.tagger.date);
}
const commit = await github.rest.git.getCommit({
owner: context.repo.owner,
repo: context.repo.repo,
commit_sha: ref.data.object.sha,
});
return new Date(commit.data.committer.date);
}
const currentDate = await getTagDate(currentTag);
core.info(`Current tag ${currentTag} date: ${currentDate.toISOString()}`);
const releases = await github.paginate(github.rest.repos.listReleases, {
owner: context.repo.owner,
repo: context.repo.repo,
per_page: 100,
});
const prevRelease = releases
.filter(r => !r.prerelease && calVerRegex.test(r.tag_name) && r.tag_name !== currentTag)
.sort((a, b) => {
const pa = a.tag_name.split('.').map(Number);
const pb = b.tag_name.split('.').map(Number);
for (let i = 0; i < 4; i++) {
if (pa[i] !== pb[i]) return pb[i] - pa[i];
}
return 0;
})[0];
let prevDate = null;
let prevTag = null;
if (prevRelease) {
prevTag = prevRelease.tag_name;
prevDate = new Date(prevRelease.published_at);
core.info(`Previous release ${prevTag} published_at: ${prevDate.toISOString()}`);
} else {
core.info('No previous CalVer release found — this appears to be the first release');
}
const allPRs = await github.paginate(github.rest.pulls.list, {
owner: context.repo.owner,
repo: context.repo.repo,
state: 'closed',
per_page: 100,
});
const relevantPRs = allPRs
.filter(pr => {
if (!pr.merged_at) return false;
const mergedAt = new Date(pr.merged_at);
if (prevDate && mergedAt <= prevDate) return false;
return mergedAt <= currentDate;
})
.map(pr => ({
number: pr.number,
title: pr.title,
author: pr.user?.login ?? 'unknown',
labels: pr.labels.map(l => l.name),
merged_at: pr.merged_at,
body: (pr.body ?? '').substring(0, 1000),
}));
core.info(`Found ${relevantPRs.length} PRs in this release window`);
const allCommits = await github.paginate(github.rest.repos.listCommits, {
owner: context.repo.owner,
repo: context.repo.repo,
sha: 'main',
since: prevDate ? prevDate.toISOString() : undefined,
until: currentDate.toISOString(),
per_page: 100,
});
const relevantCommits = allCommits.map(c => ({
sha: c.sha.substring(0, 7),
message: c.commit.message.split('\n')[0],
author: c.commit.author?.name ?? c.author?.login ?? 'unknown',
date: c.commit.committer?.date ?? null,
}));
core.info(`Found ${relevantCommits.length} commits in this release window`);
const releaseData = {
currentTag,
previousTag: prevTag,
currentDate: currentDate.toISOString(),
previousDate: prevDate ? prevDate.toISOString() : null,
pullRequests: relevantPRs,
commits: relevantCommits,
};
fs.writeFileSync('release-data.json', JSON.stringify(releaseData, null, 2));
core.info('Wrote release-data.json');
- name: Run release notes agent
id: release_notes_agent
uses: mcowger/pi-action@main
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
provider: openrouter
model: ${{ vars.LLM_MODEL_ID }}
token: ${{ env.LLM_API_KEY }}
base_url: ${{ secrets.LLM_API_HOST }}
trigger: generate-release-notes
load_builtin_extensions: true
suppress_final_comment: true
export_session_html: true
prompt_file: .github/prompts/release-notes.md
env:
RELEASE_TAG: ${{ needs.setup.outputs.tag }}
- name: Read agent-generated notes
id: read_notes
if: always()
run: |
if [ -f release-notes.md ]; then
{
echo 'notes<<RELEASE_NOTES_EOF'
cat release-notes.md
echo 'RELEASE_NOTES_EOF'
} >> "$GITHUB_OUTPUT"
else
echo '::warning::Agent did not write release-notes.md — release will have no body'
echo 'notes=' >> "$GITHUB_OUTPUT"
fi
- name: Upload agent session
if: always()
uses: actions/upload-artifact@v7
with:
name: release-notes-session
path: ${{ steps.release_notes_agent.outputs.session_html_path }}
retention-days: 7
if-no-files-found: ignore
archive: false
# ── Build Binaries ──────────────────────────────────────────────────────
build-binaries:
name: Build Binaries
needs: [setup, quality-gates]
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v6
- name: Set up Bun
uses: oven-sh/setup-bun@v2
with:
bun-version: latest
- name: Install dependencies
run: bun install --frozen-lockfile
- name: Build frontend
run: bun run build:frontend
- name: Compile all binaries
env:
APP_VERSION: ${{ needs.setup.outputs.tag }}
run: |
bun run compile:linux-amd64
bun run compile:linux-arm64
bun run compile:macos
bun run compile:windows
- name: Upload binaries
uses: actions/upload-artifact@v7
with:
name: binaries
path: |
plexus-linux-amd64
plexus-linux-arm64
plexus-macos
plexus.exe
retention-days: 1
# ── Build Docker Image ─────────────────────────────────────────────────
build-docker:
name: Build Docker Image
needs: [setup, quality-gates]
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v6
- name: Set up QEMU
uses: docker/setup-qemu-action@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v4
- name: Log in to the Container registry
uses: docker/login-action@v4
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v6
with:
images: ghcr.io/${{ github.repository }}
tags: |
type=raw,value=${{ needs.setup.outputs.tag }}
type=raw,value=latest
type=ref,event=branch
- name: Build and push Docker image
uses: docker/build-push-action@v7
with:
context: .
push: true
platforms: linux/amd64,linux/arm64
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
build-args: |
APP_VERSION=${{ needs.setup.outputs.tag }}
cache-from: type=gha
cache-to: type=gha,mode=min
- name: Smoke test Docker image
timeout-minutes: 2
run: |
echo "Starting smoke test for Docker image..."
TEST_ADMIN_KEY="test-admin-key-$(openssl rand -hex 8)"
docker run -d \
--name plexus-smoke-test \
-p 4000:4000 \
-e DATABASE_URL="sqlite://:memory:" \
-e ADMIN_KEY="$TEST_ADMIN_KEY" \
ghcr.io/${{ github.repository }}:${{ needs.setup.outputs.tag }}
echo "Waiting for container to be healthy (30s timeout)..."
SECONDS=0
MAX_WAIT=30
while [ $SECONDS -lt $MAX_WAIT ]; do
if curl -sf http://localhost:4000/health 2>/dev/null || \
curl -sf http://localhost:4000/v1/models 2>/dev/null; then
echo "✅ Container started successfully and responded on port 4000"
docker stop plexus-smoke-test
docker rm plexus-smoke-test
exit 0
fi
if ! docker ps -q -f name=plexus-smoke-test | grep -q .; then
echo "❌ Container crashed or exited unexpectedly"
docker logs plexus-smoke-test 2>/dev/null || true
docker rm plexus-smoke-test 2>/dev/null || true
exit 1
fi
sleep 1
done
echo "❌ Container failed to start within 30 seconds"
docker logs plexus-smoke-test 2>/dev/null || true
docker stop plexus-smoke-test 2>/dev/null || true
docker rm plexus-smoke-test 2>/dev/null || true
exit 1
# ── Create Release ─────────────────────────────────────────────────────
release:
name: Create Release
needs: [setup, build-binaries, build-docker, generate-release-notes]
runs-on: ubuntu-latest
steps:
- name: Download binaries
uses: actions/download-artifact@v8
with:
name: binaries
path: release
- name: Create Release
uses: softprops/action-gh-release@v3
with:
tag_name: ${{ needs.setup.outputs.tag }}
body: ${{ needs.generate-release-notes.outputs.notes }}
files: |
release/plexus-linux-amd64
release/plexus-linux-arm64
release/plexus-macos
release/plexus.exe
draft: false
prerelease: false