|
| 1 | +#!/usr/bin/env bash |
| 2 | +# Downloads protoc-gen-connect-openapi for docs OpenAPI generation. |
| 3 | +# Must be run from the workspace root. |
| 4 | +# Supports Linux (including WSL2) and macOS only. |
| 5 | +# |
| 6 | +# WHY a binary download instead of "go install": |
| 7 | +# This script runs as an Nx target that docs/generate-proto-docs depends on. |
| 8 | +# Docs OpenAPI generation happens both in CI (has Go) and on Vercel |
| 9 | +# (Node.js-only, no Go). Using a pre-built binary means Vercel never needs a |
| 10 | +# Go toolchain. Nx remote cache means the download is skipped on repeated runs. |
| 11 | +# |
| 12 | +# WHY uname instead of "go env GOOS/GOARCH": |
| 13 | +# Same reason — this script must work without Go present. |
| 14 | +set -euo pipefail |
| 15 | + |
| 16 | +# ── VERSIONS & CHECKSUMS ──────────────────────────────────────────────────── |
| 17 | +# To upgrade: update VERSION and the SHA256_<os>_<arch> vars below. |
| 18 | +# Note: macOS ships a universal binary, so darwin_amd64 and darwin_arm64 share |
| 19 | +# the same tarball and checksum. |
| 20 | + |
| 21 | +CONNECT_OPENAPI_VERSION="0.25.2" |
| 22 | +# checksums from upstream checksums.txt |
| 23 | +CONNECT_OPENAPI_SHA256_linux_amd64="90821ab96f16747dc5a4ab93900a6bc6b968d63f47553a08274dc594301bced3" |
| 24 | +CONNECT_OPENAPI_SHA256_linux_arm64="9726418d7af55f87e3bbb2a4fa6233016b200caf5a285ce1c6e6428ef225536d" |
| 25 | +CONNECT_OPENAPI_SHA256_darwin_amd64="a6bc3d87b4caaa7048d22fe0f45e3b5e778b4b209f84a836b3335fb2fd14b588" |
| 26 | +CONNECT_OPENAPI_SHA256_darwin_arm64="a6bc3d87b4caaa7048d22fe0f45e3b5e778b4b209f84a836b3335fb2fd14b588" |
| 27 | + |
| 28 | +# ── HELPERS ────────────────────────────────────────────────────────────────── |
| 29 | + |
| 30 | +verify_sha256() { |
| 31 | + local file="$1" expected="$2" |
| 32 | + local actual |
| 33 | + if command -v sha256sum &>/dev/null; then |
| 34 | + actual=$(sha256sum "$file" | cut -d' ' -f1) |
| 35 | + else |
| 36 | + actual=$(shasum -a 256 "$file" | cut -d' ' -f1) |
| 37 | + fi |
| 38 | + if [ "$actual" != "$expected" ]; then |
| 39 | + echo "ERROR: SHA256 mismatch for $(basename "$file")" >&2 |
| 40 | + echo " expected: $expected" >&2 |
| 41 | + echo " actual: $actual" >&2 |
| 42 | + exit 1 |
| 43 | + fi |
| 44 | +} |
| 45 | + |
| 46 | +# ── PLATFORM DETECTION ─────────────────────────────────────────────────────── |
| 47 | + |
| 48 | +_uname_os=$(uname -s | tr '[:upper:]' '[:lower:]') |
| 49 | +_uname_arch=$(uname -m) |
| 50 | +case "$_uname_os" in |
| 51 | + linux) GOOS="linux" ;; |
| 52 | + darwin) GOOS="darwin" ;; |
| 53 | + *) echo "Unsupported OS: $_uname_os" >&2; exit 1 ;; |
| 54 | +esac |
| 55 | +case "$_uname_arch" in |
| 56 | + x86_64) GOARCH="amd64" ;; |
| 57 | + aarch64 | arm64) GOARCH="arm64" ;; |
| 58 | + *) echo "Unsupported arch: $_uname_arch" >&2; exit 1 ;; |
| 59 | +esac |
| 60 | + |
| 61 | +BIN_DIR="${PWD}/.artifacts/bin/${GOOS}/${GOARCH}" |
| 62 | +mkdir -p "$BIN_DIR" |
| 63 | + |
| 64 | +TMP=$(mktemp -d "${TMPDIR:-/tmp}/zitadel-docs-proto-plugins.XXXXXX") |
| 65 | +trap 'rm -rf "$TMP"' EXIT |
| 66 | + |
| 67 | +# ── INSTALL ─────────────────────────────────────────────────────────────────── |
| 68 | + |
| 69 | +# ----- protoc-gen-connect-openapi (sudorandom/protoc-gen-connect-openapi) ----- |
| 70 | +# macOS ships a single universal ("all") tarball for both amd64 and arm64. |
| 71 | +case "$GOOS" in |
| 72 | + linux) OAI_ARCH="$GOARCH" ;; |
| 73 | + darwin) OAI_ARCH="all" ;; |
| 74 | +esac |
| 75 | +sha256_var="CONNECT_OPENAPI_SHA256_${GOOS}_${GOARCH}" |
| 76 | +echo "Downloading protoc-gen-connect-openapi v${CONNECT_OPENAPI_VERSION} (${GOOS}/${OAI_ARCH})..." |
| 77 | +curl -fsSL \ |
| 78 | + "https://github.com/sudorandom/protoc-gen-connect-openapi/releases/download/v${CONNECT_OPENAPI_VERSION}/protoc-gen-connect-openapi_${CONNECT_OPENAPI_VERSION}_${GOOS}_${OAI_ARCH}.tar.gz" \ |
| 79 | + -o "${TMP}/oai.tar.gz" |
| 80 | +verify_sha256 "${TMP}/oai.tar.gz" "${!sha256_var}" |
| 81 | +tar -xzf "${TMP}/oai.tar.gz" -C "${TMP}" protoc-gen-connect-openapi |
| 82 | +install -m 755 "${TMP}/protoc-gen-connect-openapi" "${BIN_DIR}/protoc-gen-connect-openapi" |
| 83 | + |
| 84 | +echo "protoc-gen-connect-openapi installed to ${BIN_DIR}" |
0 commit comments