| 1 | #!/usr/bin/env bash |
| 2 | # Build the real CLI entrypoint, then prove its embedded docs corpus and build |
| 3 | # identity match the exact release checkout before any publisher starts. |
| 4 | set -euo pipefail |
| 5 | |
| 6 | if [ "$#" -ne 2 ]; then |
| 7 | echo "usage: verify-embedded-docs.sh VERSION_OR_TAG FULL_COMMIT_SHA" >&2 |
| 8 | exit 2 |
| 9 | fi |
| 10 | |
| 11 | version="$1" |
| 12 | revision="$2" |
| 13 | case "$version" in |
| 14 | npm-v*) version="v${version#npm-v}" ;; |
| 15 | desktop-v*) version="v${version#desktop-v}" ;; |
| 16 | v*) ;; |
| 17 | *) version="v$version" ;; |
| 18 | esac |
| 19 | version_pattern='^v(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)(-([0-9A-Za-z-]+)(\.[0-9A-Za-z-]+)*)?)?$' |
| 20 | if [[ ! "$version" =~ $version_pattern ]]; then |
| 21 | echo "invalid docs build version: $version" >&2 |
| 22 | exit 2 |
| 23 | fi |
| 24 | if [[ ! "$revision" =~ ^[0-9a-f]{40}$ ]]; then |
| 25 | echo "invalid docs source revision: $revision" >&2 |
| 26 | exit 2 |
| 27 | fi |
| 28 | |
| 29 | repo_root="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")/.." && pwd)" |
| 30 | tmp_dir="$(mktemp -d "${TMPDIR:-/tmp}/reasonix-docs-verify.XXXXXX")" |
| 31 | cleanup() { |
| 32 | case "$tmp_dir" in |
| 33 | */reasonix-docs-verify.*) rm -rf -- "$tmp_dir" ;; |
| 34 | *) echo "refusing to clean unexpected docs verification directory: $tmp_dir" >&2 ;; |
| 35 | esac |
| 36 | } |
| 37 | trap cleanup EXIT |
| 38 | |
| 39 | binary="$tmp_dir/reasonix" |
| 40 | build_time_utc="$(date -u +%Y-%m-%dT%H:%M:%SZ)" |
| 41 | git_commit="$(printf '%s' "$revision" | cut -c1-12)" |
| 42 | ldflags="-s -w -X main.version=$version -X main.gitCommit=$git_commit -X main.buildTimeUTC=$build_time_utc -X reasonix/internal/productdocs.linkedVersion=$version -X reasonix/internal/productdocs.linkedRevision=$revision" |
| 43 | ( |
| 44 | cd "$repo_root" |
| 45 | CGO_ENABLED=0 go build -trimpath -ldflags="$ldflags" -o "$binary" ./cmd/reasonix |
| 46 | ) |
| 47 | |
| 48 | mkdir -p "$tmp_dir/reasonix-home" |
| 49 | manifest="$( |
| 50 | REASONIX_HOME="$tmp_dir/reasonix-home" "$binary" docs-manifest \ |
| 51 | --verify-source "$repo_root" \ |
| 52 | --expect-version "$version" \ |
| 53 | --expect-revision "$revision" |
| 54 | )" |
| 55 | printf 'Embedded docs verified: %s\n' "$manifest" |
| 56 |