-
Notifications
You must be signed in to change notification settings - Fork 17
385 lines (329 loc) · 12.6 KB
/
release.yml
File metadata and controls
385 lines (329 loc) · 12.6 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
name: Release
on:
push:
tags:
- "v*"
permissions:
contents: write
packages: write
id-token: write
env:
REGISTRY: ghcr.io
IMAGE_NAME: onllm-dev/4dpocket
jobs:
# ─── Extract version from tag ─────────────────────────────────
meta:
runs-on: ubuntu-latest
outputs:
version: ${{ steps.version.outputs.version }}
tag: ${{ steps.version.outputs.tag }}
steps:
- name: Extract version from tag
id: version
run: |
TAG="${GITHUB_REF#refs/tags/}"
VERSION="${TAG#v}"
echo "tag=$TAG" >> "$GITHUB_OUTPUT"
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
echo "Version: $VERSION (tag: $TAG)"
# ─── Build per-platform Docker images (native runners) ────────
docker-build:
needs: meta
timeout-minutes: 30
strategy:
matrix:
include:
- platform: linux/amd64
runner: ubuntu-latest
- platform: linux/arm64
runner: ubuntu-24.04-arm
runs-on: ${{ matrix.runner }}
steps:
- uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v4
- name: Log in to GHCR
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Docker meta
id: docker-meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
- name: Build and push by digest
id: build
uses: docker/build-push-action@v6
with:
context: .
platforms: ${{ matrix.platform }}
labels: ${{ steps.docker-meta.outputs.labels }}
cache-from: type=gha,scope=${{ matrix.platform }}
cache-to: type=gha,mode=max,scope=${{ matrix.platform }}
outputs: type=image,name=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }},push-by-digest=true,name-canonical=true,push=true
- name: Export digest
run: |
mkdir -p /tmp/digests
digest="${{ steps.build.outputs.digest }}"
touch "/tmp/digests/${digest#sha256:}"
- name: Upload digest
uses: actions/upload-artifact@v4
with:
name: digest-${{ matrix.runner }}
path: /tmp/digests/*
if-no-files-found: error
# ─── Merge multi-arch manifest and push tags ──────────────────
docker:
runs-on: ubuntu-latest
needs: [meta, docker-build]
steps:
- name: Download digests
uses: actions/download-artifact@v4
with:
pattern: digest-*
path: /tmp/digests
merge-multiple: true
- name: Log in to GHCR
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Docker meta (tags + labels)
id: docker-meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}
type=raw,value=latest
- name: Create and push manifest
working-directory: /tmp/digests
run: |
docker buildx imagetools create \
$(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \
$(printf '${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}@sha256:%s ' *)
# ─── Smoke test published image ────────────────────────────────
smoke-test:
runs-on: ubuntu-latest
needs: [meta, docker]
steps:
- name: Smoke test Docker image
run: |
docker pull ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ needs.meta.outputs.version }}
docker run -d --name 4dp-smoke -p 4040:4040 \
-e FDP_DATABASE__URL=sqlite:////data/4dpocket.db \
-e FDP_AUTH__MODE=single \
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ needs.meta.outputs.version }}
# Wait for health
for i in $(seq 1 30); do
if curl -sf http://localhost:4040/api/v1/health > /dev/null 2>&1; then
echo "Container ready"
break
fi
sleep 1
done
# Validate SPA root serves index.html
STATUS=$(curl -s -o /dev/null -w '%{http_code}' http://localhost:4040/)
if [ "$STATUS" != "200" ]; then
echo "FAIL: GET / returned $STATUS (expected 200)"
docker logs 4dp-smoke
exit 1
fi
echo "SPA root: OK"
# Validate API
STATUS=$(curl -s -o /dev/null -w '%{http_code}' http://localhost:4040/api/v1/health)
if [ "$STATUS" != "200" ]; then
echo "FAIL: API health returned $STATUS (expected 200)"
docker logs 4dp-smoke
exit 1
fi
echo "API health: OK"
docker stop 4dp-smoke
# ─── Build Python package ──────────────────────────────────────
python:
runs-on: ubuntu-latest
needs: meta
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.12"
- name: Set up Node
uses: actions/setup-node@v4
with:
node-version: 22
- name: Install pnpm
run: corepack enable
- name: Build frontend
working-directory: frontend
run: pnpm install --frozen-lockfile && pnpm build
- name: Install build tools
run: pip install build
- name: Verify version matches tag
run: |
PKG_VERSION=$(python -c "
import re
with open('pyproject.toml') as f:
m = re.search(r'version\s*=\s*\"(.+?)\"', f.read())
print(m.group(1))
")
if [ "$PKG_VERSION" != "${{ needs.meta.outputs.version }}" ]; then
echo "ERROR: pyproject.toml version ($PKG_VERSION) != tag (${{ needs.meta.outputs.version }})"
exit 1
fi
- name: Build sdist and wheel
run: python -m build
- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
name: python-dist
path: dist/
# ─── Build Chrome extension ────────────────────────────────────
extension:
runs-on: ubuntu-latest
needs: meta
steps:
- uses: actions/checkout@v4
- name: Set up Node
uses: actions/setup-node@v4
with:
node-version: 22
- name: Install pnpm
run: corepack enable
- name: Install dependencies
working-directory: extension
run: pnpm install --frozen-lockfile
- name: Build Chrome extension
working-directory: extension
run: pnpm build
- name: Zip extension
run: |
cd extension/dist/chrome-mv3
zip -r ../../../4dpocket-chrome-extension-${{ needs.meta.outputs.version }}.zip .
- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
name: chrome-extension
path: 4dpocket-chrome-extension-${{ needs.meta.outputs.version }}.zip
# ─── Publish MCP npm package (Trusted Publishing via OIDC) ────
# Setup: npmjs.com → org "onllm-dev" → package/org Trusted Publishers →
# Add GitHub Actions with repo=onllm-dev/4DPocket, workflow=release.yml.
# No long-lived NPM_TOKEN needed — CI authenticates via GitHub OIDC.
npm:
runs-on: ubuntu-latest
needs: meta
permissions:
contents: read
id-token: write # required for OIDC trusted publishing
steps:
- uses: actions/checkout@v4
- name: Set up Node
uses: actions/setup-node@v4
with:
node-version: 22
registry-url: "https://registry.npmjs.org"
- name: Upgrade npm to version supporting trusted publishing
# npm >= 11.5.1 is required for OIDC trusted publishing. Installing
# into a user prefix avoids the known self-upgrade bug where the
# existing system npm breaks mid-update (MODULE_NOT_FOUND for
# promise-retry inside arborist).
run: |
NPM_PREFIX="$HOME/.npm-global"
mkdir -p "$NPM_PREFIX"
npm install -g --prefix "$NPM_PREFIX" npm@11.12.1
echo "$NPM_PREFIX/bin" >> "$GITHUB_PATH"
- name: Verify mcp-npm version matches tag
working-directory: mcp-npm
run: |
PKG_VERSION=$(node -p "require('./package.json').version")
if [ "$PKG_VERSION" != "${{ needs.meta.outputs.version }}" ]; then
echo "ERROR: mcp-npm/package.json version ($PKG_VERSION) != tag (${{ needs.meta.outputs.version }})"
exit 1
fi
- name: Publish to npm (trusted publishing + provenance)
working-directory: mcp-npm
run: |
VERSION="${{ needs.meta.outputs.version }}"
if npm view "@onllm-dev/4dpocket-mcp@$VERSION" version > /dev/null 2>&1; then
echo "@onllm-dev/4dpocket-mcp@$VERSION is already on npm — skipping publish."
exit 0
fi
npm publish --access public --provenance
# ─── Create GitHub Release ─────────────────────────────────────
# Intentionally does NOT depend on `npm` — the npm job requires the trusted
# publisher to be configured on npmjs.com, which is a one-time manual step.
# Keep the release notes / docker / pypi flow resilient if npm fails.
release:
runs-on: ubuntu-latest
needs: [meta, docker, python, extension, smoke-test]
steps:
- uses: actions/checkout@v4
- name: Download Python artifacts
uses: actions/download-artifact@v4
with:
name: python-dist
path: dist/
- name: Download Chrome extension
uses: actions/download-artifact@v4
with:
name: chrome-extension
path: .
- name: Create GitHub Release
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ needs.meta.outputs.tag }}
name: 4DPocket ${{ needs.meta.outputs.tag }}
generate_release_notes: true
files: |
dist/*
4dpocket-chrome-extension-${{ needs.meta.outputs.version }}.zip
body: |
## Install
**Docker (recommended):**
```bash
docker pull ghcr.io/onllm-dev/4dpocket:${{ needs.meta.outputs.version }}
```
**Docker Compose:**
```bash
curl -O https://raw.githubusercontent.com/onllm-dev/4DPocket/${{ needs.meta.outputs.tag }}/docker-compose.yml
curl -O https://raw.githubusercontent.com/onllm-dev/4DPocket/${{ needs.meta.outputs.tag }}/.env.example
cp .env.example .env
docker compose up -d
```
**Python:**
```bash
pip install 4dpocket==${{ needs.meta.outputs.version }}
```
## MCP Client
Connect stdio-based MCP clients (Claude Desktop, Cursor, etc.) to your instance:
```bash
npx -y @onllm-dev/4dpocket-mcp --url https://your.pocket.tld --token fdp_pat_xxx
```
See [`mcp-npm/README.md`](https://github.com/onllm-dev/4DPocket/blob/${{ needs.meta.outputs.tag }}/mcp-npm/README.md) for full client config snippets.
## Chrome Extension
1. Download `4dpocket-chrome-extension-${{ needs.meta.outputs.version }}.zip` from the assets below
2. Unzip it
3. Go to `chrome://extensions`, enable **Developer mode**
4. Click **Load unpacked** and select the unzipped folder
5. Click the extension icon, open **Settings**, enter your server URL and login
# ─── Publish to PyPI (trusted publisher via OIDC) ─────────────
pypi:
runs-on: ubuntu-latest
needs: [meta, python, smoke-test]
environment: pypi
permissions:
id-token: write
steps:
- name: Download artifacts
uses: actions/download-artifact@v4
with:
name: python-dist
path: dist/
- name: Publish to PyPI
uses: pypa/gh-action-pypi-publish@release/v1