|
| 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