|
| 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" |
0 commit comments