Skip to content

Commit 9a1c8bb

Browse files
committed
ci: add bridge build and asset publish workflows
1 parent 3656c6d commit 9a1c8bb

3 files changed

Lines changed: 237 additions & 0 deletions

File tree

.github/workflows/ci.yml

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
branches: [main]
8+
9+
jobs:
10+
build-webgpu-bridge:
11+
name: Build WebGPU Bridge (WASM)
12+
runs-on: ubuntu-latest
13+
env:
14+
LLAMA_CPP_TAG: b8011
15+
steps:
16+
- uses: actions/checkout@v4
17+
18+
- name: Clone llama.cpp source
19+
run: |
20+
git clone --depth 1 --branch "$LLAMA_CPP_TAG" https://github.com/ggml-org/llama.cpp.git third_party/llama_cpp
21+
22+
- name: Setup Emscripten SDK
23+
uses: mymindstorm/setup-emsdk@v14
24+
with:
25+
version: 3.1.70
26+
27+
- name: Build bridge artifacts
28+
env:
29+
OUT_DIR: ${{ runner.temp }}/webgpu_bridge_dist
30+
run: ./scripts/build_bridge.sh
31+
32+
- name: Verify outputs
33+
run: |
34+
test -f "${{ runner.temp }}/webgpu_bridge_dist/llama_webgpu_bridge.js"
35+
test -f "${{ runner.temp }}/webgpu_bridge_dist/llama_webgpu_core.js"
36+
test -f "${{ runner.temp }}/webgpu_bridge_dist/llama_webgpu_core.wasm"
37+
38+
- name: Upload bridge artifacts
39+
uses: actions/upload-artifact@v4
40+
with:
41+
name: webgpu-bridge-dist
42+
path: |
43+
${{ runner.temp }}/webgpu_bridge_dist/llama_webgpu_bridge.js
44+
${{ runner.temp }}/webgpu_bridge_dist/llama_webgpu_core.js
45+
${{ runner.temp }}/webgpu_bridge_dist/llama_webgpu_core.wasm
Lines changed: 161 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,161 @@
1+
name: Publish Bridge Assets
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
assets_tag:
7+
description: Tag to publish to assets repo (for example v0.1.1)
8+
required: true
9+
assets_repo:
10+
description: Asset repository in owner/repo format
11+
required: true
12+
default: leehack/llama-web-bridge-assets
13+
llama_cpp_tag:
14+
description: llama.cpp tag to build from
15+
required: true
16+
default: b8011
17+
18+
permissions:
19+
contents: read
20+
21+
jobs:
22+
build-bridge-assets:
23+
name: Build bridge assets
24+
runs-on: ubuntu-latest
25+
steps:
26+
- uses: actions/checkout@v4
27+
28+
- name: Clone llama.cpp source
29+
run: |
30+
git clone --depth 1 --branch "${{ inputs.llama_cpp_tag }}" https://github.com/ggml-org/llama.cpp.git third_party/llama_cpp
31+
32+
- name: Setup Emscripten SDK
33+
uses: mymindstorm/setup-emsdk@v14
34+
with:
35+
version: 3.1.70
36+
37+
- name: Build bridge artifacts
38+
env:
39+
OUT_DIR: ${{ runner.temp }}/webgpu_bridge_dist
40+
run: ./scripts/build_bridge.sh
41+
42+
- name: Generate manifest and checksums
43+
env:
44+
OUT_DIR: ${{ runner.temp }}/webgpu_bridge_dist
45+
ASSETS_TAG: ${{ inputs.assets_tag }}
46+
LLAMA_CPP_TAG: ${{ inputs.llama_cpp_tag }}
47+
SOURCE_REPO: ${{ github.repository }}
48+
SOURCE_COMMIT: ${{ github.sha }}
49+
run: |
50+
test -f "$OUT_DIR/llama_webgpu_bridge.js"
51+
test -f "$OUT_DIR/llama_webgpu_core.js"
52+
test -f "$OUT_DIR/llama_webgpu_core.wasm"
53+
54+
python3 - <<'PY'
55+
import hashlib
56+
import json
57+
import os
58+
from datetime import datetime, timezone
59+
60+
out_dir = os.environ['OUT_DIR']
61+
files = [
62+
'llama_webgpu_bridge.js',
63+
'llama_webgpu_core.js',
64+
'llama_webgpu_core.wasm',
65+
]
66+
67+
manifest = {
68+
'bridge_assets_tag': os.environ['ASSETS_TAG'],
69+
'source_repository': os.environ['SOURCE_REPO'],
70+
'source_commit': os.environ['SOURCE_COMMIT'],
71+
'llama_cpp_tag': os.environ['LLAMA_CPP_TAG'],
72+
'generated_at_utc': datetime.now(timezone.utc).strftime('%Y-%m-%dT%H:%M:%SZ'),
73+
'files': {},
74+
}
75+
76+
checksums = []
77+
for name in files:
78+
path = os.path.join(out_dir, name)
79+
with open(path, 'rb') as f:
80+
data = f.read()
81+
digest = hashlib.sha256(data).hexdigest()
82+
manifest['files'][name] = {
83+
'size_bytes': len(data),
84+
'sha256': digest,
85+
}
86+
checksums.append(f'{digest} {name}')
87+
88+
with open(os.path.join(out_dir, 'manifest.json'), 'w', encoding='utf-8') as f:
89+
json.dump(manifest, f, indent=2)
90+
f.write('\n')
91+
92+
with open(os.path.join(out_dir, 'sha256sums.txt'), 'w', encoding='utf-8') as f:
93+
f.write('\n'.join(checksums))
94+
f.write('\n')
95+
PY
96+
97+
- name: Upload built assets
98+
uses: actions/upload-artifact@v4
99+
with:
100+
name: webgpu-bridge-dist
101+
path: |
102+
${{ runner.temp }}/webgpu_bridge_dist/llama_webgpu_bridge.js
103+
${{ runner.temp }}/webgpu_bridge_dist/llama_webgpu_core.js
104+
${{ runner.temp }}/webgpu_bridge_dist/llama_webgpu_core.wasm
105+
${{ runner.temp }}/webgpu_bridge_dist/manifest.json
106+
${{ runner.temp }}/webgpu_bridge_dist/sha256sums.txt
107+
108+
publish-assets-repo:
109+
name: Publish to assets repository
110+
needs: build-bridge-assets
111+
runs-on: ubuntu-latest
112+
steps:
113+
- name: Validate assets PAT secret
114+
env:
115+
ASSETS_PAT: ${{ secrets.WEBGPU_BRIDGE_ASSETS_PAT }}
116+
run: |
117+
if [ -z "$ASSETS_PAT" ]; then
118+
echo "error: WEBGPU_BRIDGE_ASSETS_PAT secret is required"
119+
exit 1
120+
fi
121+
122+
- name: Checkout assets repository
123+
uses: actions/checkout@v4
124+
with:
125+
repository: ${{ inputs.assets_repo }}
126+
token: ${{ secrets.WEBGPU_BRIDGE_ASSETS_PAT }}
127+
path: assets-repo
128+
129+
- name: Download bridge assets artifact
130+
uses: actions/download-artifact@v4
131+
with:
132+
name: webgpu-bridge-dist
133+
path: bridge-dist
134+
135+
- name: Publish assets and tag
136+
env:
137+
ASSETS_TAG: ${{ inputs.assets_tag }}
138+
run: |
139+
if git -C assets-repo ls-remote --exit-code --tags origin "refs/tags/$ASSETS_TAG" >/dev/null 2>&1; then
140+
echo "error: tag already exists in assets repo: $ASSETS_TAG"
141+
exit 1
142+
fi
143+
144+
cp bridge-dist/* assets-repo/
145+
146+
cd assets-repo
147+
git config user.name "github-actions[bot]"
148+
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
149+
150+
git add llama_webgpu_bridge.js llama_webgpu_core.js llama_webgpu_core.wasm manifest.json sha256sums.txt
151+
152+
if git diff --cached --quiet; then
153+
echo "No asset changes detected; skipping commit and tag."
154+
exit 0
155+
fi
156+
157+
git commit -m "chore: publish webgpu bridge $ASSETS_TAG"
158+
git push origin HEAD
159+
160+
git tag "$ASSETS_TAG"
161+
git push origin "$ASSETS_TAG"

README.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,39 @@ Build outputs:
3333
- `dist/llama_webgpu_core.js`
3434
- `dist/llama_webgpu_core.wasm`
3535

36+
## CI
37+
38+
This repo includes a wasm build gate in:
39+
40+
- `.github/workflows/ci.yml`
41+
42+
It builds against pinned `llama.cpp` tag `b8011` and uploads build artifacts.
43+
3644
## Publishing
3745

3846
Published, versioned artifacts are consumed from:
3947

4048
- `leehack/llama-web-bridge-assets`
49+
50+
Publish workflow:
51+
52+
- `.github/workflows/publish_assets.yml`
53+
54+
Required repository secret:
55+
56+
- `WEBGPU_BRIDGE_ASSETS_PAT` (token with write access to
57+
`leehack/llama-web-bridge-assets`)
58+
59+
Example publish:
60+
61+
1. Run `Publish Bridge Assets` workflow
62+
2. Inputs:
63+
- `assets_tag`: `v0.1.1`
64+
- `assets_repo`: `leehack/llama-web-bridge-assets`
65+
- `llama_cpp_tag`: `b8011`
66+
67+
After publish, assets are CDN-available at:
68+
69+
- `https://cdn.jsdelivr.net/gh/leehack/llama-web-bridge-assets@v0.1.1/llama_webgpu_bridge.js`
70+
- `https://cdn.jsdelivr.net/gh/leehack/llama-web-bridge-assets@v0.1.1/llama_webgpu_core.js`
71+
- `https://cdn.jsdelivr.net/gh/leehack/llama-web-bridge-assets@v0.1.1/llama_webgpu_core.wasm`

0 commit comments

Comments
 (0)