Skip to content

Commit dd6f687

Browse files
committed
use release-based workflow
1 parent 10eca94 commit dd6f687

4 files changed

Lines changed: 148 additions & 15 deletions

File tree

‎.github/workflows/pages.yaml‎

Lines changed: 39 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -20,22 +20,46 @@ jobs:
2020
node-version: "22"
2121
cache: "pnpm"
2222
- run: pnpm install --frozen-lockfile
23-
# - name: cache built clangd
24-
# id: cache-build
25-
# uses: actions/cache@v3
26-
# with:
27-
# path: ./public/wasm
28-
# key: build-script-${{ hashFiles('build.sh') }}
29-
# - if: ${{ steps.cache-build.outputs.cache-hit != 'true' }}
30-
# name: build clangd
31-
# run: |
32-
# sudo apt update
33-
# sudo apt install vim git build-essential cmake ninja-build python3
34-
# ./build.sh
35-
- name: Get clangd wasm
23+
- name: Get clangd wasm from the latest artifact release
24+
env:
25+
GH_TOKEN: ${{ github.token }}
26+
RELEASE_REPOSITORY: ${{ github.repository }}
3627
run: |
37-
curl --output public/wasm/clangd.wasm https://clangd.guyutongxue.site/wasm/clangd.wasm
38-
curl --output public/wasm/clangd.js https://clangd.guyutongxue.site/wasm/clangd.js
28+
set -euo pipefail
29+
release_prefix="clangd-wasm/"
30+
release_tag=$(
31+
gh api --paginate "repos/${RELEASE_REPOSITORY}/releases?per_page=100" |
32+
jq -sr --arg prefix "$release_prefix" '
33+
add
34+
| map(select(
35+
(.draft | not)
36+
and (.tag_name | startswith($prefix))
37+
))
38+
| sort_by(.published_at)
39+
| last
40+
| .tag_name // empty
41+
'
42+
)
43+
if [[ -z "$release_tag" ]]; then
44+
echo "No published clangd wasm release found with prefix ${release_prefix}" >&2
45+
echo "Run scripts/release-clangd-wasm.sh locally first." >&2
46+
exit 1
47+
fi
48+
artifact_dir=$(mktemp -d)
49+
trap 'rm -rf "$artifact_dir"' EXIT
50+
echo "Using ${release_tag}"
51+
gh release download "$release_tag" \
52+
--repo "$RELEASE_REPOSITORY" \
53+
--pattern clangd.js \
54+
--pattern clangd.wasm \
55+
--pattern SHA256SUMS \
56+
--dir "$artifact_dir"
57+
(
58+
cd "$artifact_dir"
59+
sha256sum -c SHA256SUMS
60+
)
61+
install -m 0644 "$artifact_dir/clangd.js" public/wasm/clangd.js
62+
install -m 0644 "$artifact_dir/clangd.wasm" public/wasm/clangd.wasm
3963
- run: pnpm build
4064
- uses: actions/upload-pages-artifact@v3
4165
with:

‎README.md‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,3 +183,27 @@ pnpm pack:runtime
183183
```
184184

185185
The output is `clangd-browser-runtime.tar.gz`. It includes the main code-block files, lower-level entries, internal chunks, and prebuilt WebAssembly artifacts.
186+
187+
## Release clangd artifacts
188+
189+
The Pages workflow downloads `clangd.js`, `clangd.wasm`, and `SHA256SUMS` from the newest published repository release whose tag identifies it as a clangd WebAssembly release:
190+
191+
```text
192+
clangd-wasm/<release-id>
193+
```
194+
195+
To publish the artifacts currently in `public/wasm`, install and authenticate the GitHub CLI and run this locally:
196+
197+
```bash
198+
pnpm release:wasm
199+
```
200+
201+
The default release ID is a UTC timestamp. An explicit ID can be supplied when a recognizable version is preferable:
202+
203+
```bash
204+
pnpm release:wasm -- llvm-22.0.0
205+
```
206+
207+
The script validates both artifacts, creates `SHA256SUMS`, targets the current commit, and refuses duplicate release tags. CI only downloads the latest repository-wide release in the `clangd-wasm/` tag namespace; it does not create or build releases.
208+
209+
The repository is read from the `origin` GitHub remote and passed explicitly to `gh`. If the remote is named differently or does not use a standard GitHub URL, set `GH_REPO=owner/repository` when running the command.

‎package.json‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
"watch": "tsc -w",
1010
"build": "pnpm run clean && tsc && vite build && node scripts/copy-runtime-assets.mjs",
1111
"pack:runtime": "pnpm build && bash scripts/package-runtime.sh",
12+
"release:wasm": "bash scripts/release-clangd-wasm.sh",
1213
"demo:origins": "node scripts/serve-test.mjs",
1314
"test:browser": "playwright test"
1415
},

‎scripts/release-clangd-wasm.sh‎

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
workspace_dir=$(cd "$(dirname "$0")/.." && pwd)
5+
wasm_dir="$workspace_dir/public/wasm"
6+
release_id=${1:-$(date -u +%Y%m%d-%H%M%S)}
7+
8+
cd "$workspace_dir"
9+
10+
if [[ ! "$release_id" =~ ^[A-Za-z0-9._-]+$ ]]; then
11+
echo "Release ID must contain only letters, numbers, dots, underscores, and hyphens." >&2
12+
exit 1
13+
fi
14+
15+
for command_name in gh git sha256sum; do
16+
if ! command -v "$command_name" >/dev/null 2>&1; then
17+
echo "Required command not found: $command_name" >&2
18+
exit 1
19+
fi
20+
done
21+
22+
release_repository=${GH_REPO:-}
23+
if [[ -z "$release_repository" ]]; then
24+
origin_url=$(git remote get-url origin 2>/dev/null || true)
25+
case "$origin_url" in
26+
git@github.com:*)
27+
release_repository=${origin_url#git@github.com:}
28+
;;
29+
ssh://git@github.com/*)
30+
release_repository=${origin_url#ssh://git@github.com/}
31+
;;
32+
https://github.com/*)
33+
release_repository=${origin_url#https://github.com/}
34+
;;
35+
esac
36+
release_repository=${release_repository%.git}
37+
fi
38+
39+
if [[ ! "$release_repository" =~ ^[^/]+/[^/]+$ ]]; then
40+
echo "Could not determine the GitHub repository from the origin remote." >&2
41+
echo "Set GH_REPO to owner/repository and try again." >&2
42+
exit 1
43+
fi
44+
45+
for artifact in clangd.js clangd.wasm; do
46+
if [[ ! -s "$wasm_dir/$artifact" ]]; then
47+
echo "Missing or empty artifact: public/wasm/$artifact" >&2
48+
exit 1
49+
fi
50+
done
51+
52+
gh auth status >/dev/null
53+
54+
release_tag="clangd-wasm/$release_id"
55+
if gh release view "$release_tag" --repo "$release_repository" >/dev/null 2>&1; then
56+
echo "Release already exists: $release_tag" >&2
57+
exit 1
58+
fi
59+
60+
release_tmp=$(mktemp -d)
61+
trap 'rm -rf "$release_tmp"' EXIT
62+
checksum_file="$release_tmp/SHA256SUMS"
63+
(
64+
cd "$wasm_dir"
65+
sha256sum clangd.js clangd.wasm
66+
) > "$checksum_file"
67+
68+
commit_sha=$(git -C "$workspace_dir" rev-parse HEAD)
69+
release_notes=$(printf '%s\n\n%s\n%s\n' \
70+
"Prebuilt clangd WebAssembly artifacts." \
71+
"Source commit: $commit_sha" \
72+
"Verify after download with: sha256sum -c SHA256SUMS")
73+
74+
echo "Creating GitHub Release $release_repository@$release_tag"
75+
gh release create "$release_tag" \
76+
"$wasm_dir/clangd.js" \
77+
"$wasm_dir/clangd.wasm" \
78+
"$checksum_file" \
79+
--repo "$release_repository" \
80+
--target "$commit_sha" \
81+
--title "clangd wasm: $release_id" \
82+
--notes "$release_notes"
83+
84+
echo "Created $release_tag"

0 commit comments

Comments
 (0)