diff --git a/.github/workflows/mcpx-release.yml b/.github/workflows/mcpx-release.yml new file mode 100644 index 0000000000..d03a6bfe40 --- /dev/null +++ b/.github/workflows/mcpx-release.yml @@ -0,0 +1,333 @@ +name: mcpx release + +# Cuts an mcpx release from the monorepo (decision 0005 §2.1-§2.3, §3, §5; +# #1881). It produces channel 1 (release binaries + checksums), exercises +# channel 2 (the curl|sh installer) against them, and builds channel 3 (the +# container image) from the same version stamp -- publishing the image to +# GHCR on a tag, building it only on a snapshot. +# +# mcpx lives in pkgs/mcpx of a monorepo, so its releases need a scheme that +# cannot collide with another package's: tags are `mcpx/vX.Y.Z`, and this +# workflow triggers on exactly that prefix. +# +# The version's single source is pkgs/mcpx/VERSION. A tag that disagrees with +# it is refused before anything is built -- a release whose name and whose +# `mcpx --version` differ is the failure this workflow exists to prevent. +# +# A manual run (workflow_dispatch) is a snapshot: it builds the same three +# artifacts with the same script and uploads them as a workflow artifact, +# without publishing a release. That run is the proof the release path works, +# and it is how a person checks a change before tagging. +on: + push: + tags: + - "mcpx/v*" + workflow_dispatch: + inputs: + version: + description: "Version to build (default: pkgs/mcpx/VERSION)" + required: false + type: string + +permissions: + contents: write + packages: write + +# CI tier policy: see .github/ci-policy.md +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: false + +jobs: + artifacts: + name: "release: build artifacts" + runs-on: ubuntu-latest + timeout-minutes: 30 + outputs: + version: ${{ steps.version.outputs.version }} + tag: ${{ steps.version.outputs.tag }} + steps: + - uses: actions/checkout@v7 + with: + fetch-depth: 0 + + - uses: actions/setup-go@v7 + with: + go-version-file: pkgs/mcpx/go.mod + cache: true + # Monorepo: setup-go looks for go.sum at the repository root unless + # told otherwise (same reason as .github/workflows/mcpx.yml). + cache-dependency-path: pkgs/mcpx/go.sum + + - name: Resolve the version, and refuse a tag that disagrees with it + id: version + working-directory: pkgs/mcpx + env: + EVENT: ${{ github.event_name }} + REF_NAME: ${{ github.ref_name }} + INPUT_VERSION: ${{ inputs.version }} + run: | + set -euo pipefail + file_version=$(tr -d '\n' 1.2.3 + tag_version=${REF_NAME#mcpx/v} + if [ "$tag_version" != "$file_version" ]; then + echo "::error::tag $REF_NAME says $tag_version, pkgs/mcpx/VERSION says $file_version" + echo "Bump pkgs/mcpx/VERSION in the commit the tag points at, then re-tag." + exit 1 + fi + version=$file_version + else + # A snapshot builds VERSION unless a version is given; it never + # publishes, so a mismatch here is a request, not a release. + version=${INPUT_VERSION:-$file_version} + version=${version#v} + fi + echo "version=$version" >>"$GITHUB_OUTPUT" + echo "tag=mcpx/v$version" >>"$GITHUB_OUTPUT" + echo "building mcpx $version" + + - name: Build the three static artifacts and their checksums + working-directory: pkgs/mcpx + run: ./scripts/release-artifacts.sh "$RUNNER_TEMP/artifacts" "${{ steps.version.outputs.version }}" + + - name: Smoke-test the host binary's reported version + # The version stamp is the whole point of the ldflags wiring, so read + # it back off the artifact this runner can execute. + run: | + set -euo pipefail + mkdir -p "$RUNNER_TEMP/smoke" + tar -C "$RUNNER_TEMP/smoke" -xzf "$RUNNER_TEMP/artifacts/mcpx-${{ steps.version.outputs.version }}-x86_64-linux.tar.gz" + got=$("$RUNNER_TEMP/smoke/mcpx" --version) + echo "mcpx --version: $got" + case "$got" in + *"${{ steps.version.outputs.version }}"*) ;; + *) echo "::error::artifact reports '$got', expected ${{ steps.version.outputs.version }}"; exit 1 ;; + esac + + - uses: actions/upload-artifact@v7 + with: + name: mcpx-${{ steps.version.outputs.version }} + path: | + ${{ runner.temp }}/artifacts/*.tar.gz + ${{ runner.temp }}/artifacts/SHA256SUMS + if-no-files-found: error + retention-days: 30 + + installer: + name: "release: installer exercise" + # The curl|sh installer (decision 0005 §2.2, §6.5) consumes the artifacts + # built above, so it is exercised here against a snapshot: install into a + # temp prefix and read the version back. A tag release also runs it, and + # `publish` waits for it, so a release cannot ship an installer that no + # longer works against the tarballs it just built. + needs: artifacts + runs-on: ubuntu-latest + timeout-minutes: 10 + steps: + - uses: actions/checkout@v7 + + - uses: actions/download-artifact@v8 + with: + name: mcpx-${{ needs.artifacts.outputs.version }} + path: ${{ runner.temp }}/artifacts + + - name: Install the snapshot into a temp prefix + env: + MCPX_VERSION: ${{ needs.artifacts.outputs.version }} + MCPX_BASE_URL: ${{ runner.temp }}/artifacts + MCPX_PREFIX: ${{ runner.temp }}/prefix + run: | + set -euo pipefail + sh pkgs/mcpx/scripts/install.sh + got=$("$MCPX_PREFIX/mcpx" --version) + echo "installed binary reports: $got" + case "$got" in + *"$MCPX_VERSION"*) ;; + *) echo "::error::installed binary reports '$got', expected $MCPX_VERSION"; exit 1 ;; + esac + + - name: Resolve the default version past another package's release + # The default (no MCPX_VERSION) resolution must not use + # /releases/latest: that is the newest release of the whole repo, + # and other packages publish here too. Feed the installer a fixture + # releases list whose newest entry is a graph release, followed by + # an mcpx prerelease, followed by the real mcpx release. + env: + MCPX_BASE_URL: ${{ runner.temp }}/artifacts + MCPX_PREFIX: ${{ runner.temp }}/prefix-default + run: | + set -euo pipefail + version="${{ needs.artifacts.outputs.version }}" + cat >"$RUNNER_TEMP/releases.json" <"$RUNNER_TEMP/err"; then + echo "::error::the installer accepted an unknown argument" + exit 1 + fi + grep -q "unknown argument" "$RUNNER_TEMP/err" || { + echo "::error::unknown-argument refusal gave the wrong error:" + cat "$RUNNER_TEMP/err" + exit 1 + } + rm -f /usr/local/bin/mcpx + sh pkgs/mcpx/scripts/install.sh --system + got=$(/usr/local/bin/mcpx --version) + echo "system-wide install reports: $got" + case "$got" in + *"$MCPX_VERSION"*) ;; + *) echo "::error::system-wide install reports '$got', expected $MCPX_VERSION"; exit 1 ;; + esac + + - name: Refuse a tampered artifact + # The installer verifies the checksum; prove it by breaking one. An + # installer that only *says* it verifies teaches the wrong habit. + env: + MCPX_VERSION: ${{ needs.artifacts.outputs.version }} + MCPX_PREFIX: ${{ runner.temp }}/tampered-prefix + run: | + set -euo pipefail + cp -r "$RUNNER_TEMP/artifacts" "$RUNNER_TEMP/tampered" + asset="$RUNNER_TEMP/tampered/mcpx-$MCPX_VERSION-x86_64-linux.tar.gz" + printf 'x' >>"$asset" + if MCPX_BASE_URL="$RUNNER_TEMP/tampered" sh pkgs/mcpx/scripts/install.sh 2>"$RUNNER_TEMP/err"; then + echo "::error::the installer accepted an artifact whose checksum does not match" + exit 1 + fi + grep -q "checksum mismatch" "$RUNNER_TEMP/err" || { + echo "::error::installer failed for the wrong reason:" + cat "$RUNNER_TEMP/err" + exit 1 + } + echo "tampered artifact refused, as it must be" + + container: + name: "release: container image" + # Channel 3 (decision 0005 §2.3, §6.6): the Containerfile already builds a + # working image; this wires it to the release version so the image cannot + # carry a fifth hand-synced copy of the string. A tag pushes it to GHCR; + # a snapshot builds it and reads `mcpx --version` back, proving the + # build-arg path without publishing anything. + needs: artifacts + runs-on: ubuntu-latest + timeout-minutes: 30 + steps: + - uses: actions/checkout@v7 + + - name: Log in to GHCR + if: github.event_name == 'push' + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Build the image at the release version, and read it back + env: + VERSION: ${{ needs.artifacts.outputs.version }} + # Lowercased: GHCR rejects uppercase, and an owner or repo name can + # carry it. The image sits under the repository, so it cannot + # collide with another package's image in the same org. + IMAGE: ghcr.io/${{ github.repository }}/mcpx + run: | + set -euo pipefail + image=$(printf '%s' "$IMAGE" | tr '[:upper:]' '[:lower:]') + tags=(--tag "$image:$VERSION") + if [ "$GITHUB_EVENT_NAME" = "push" ]; then + tags+=(--tag "$image:latest") + fi + docker build \ + --file pkgs/mcpx/Containerfile \ + --build-arg "VERSION=$VERSION" \ + "${tags[@]}" \ + pkgs/mcpx + got=$(docker run --rm "$image:$VERSION" --version) + echo "image mcpx --version: $got" + case "$got" in + *"$VERSION"*) ;; + *) echo "::error::image reports '$got', expected $VERSION"; exit 1 ;; + esac + if [ "$GITHUB_EVENT_NAME" = "push" ]; then + docker push "$image:$VERSION" + docker push "$image:latest" + echo "published $image:$VERSION" + else + echo "snapshot: built $image:$VERSION, not pushed" + fi + + publish: + name: "release: publish" + # Only a tag publishes. A snapshot run stops at the artifacts and the + # installer exercise above. + if: github.event_name == 'push' + needs: [artifacts, installer] + runs-on: ubuntu-latest + timeout-minutes: 10 + steps: + - uses: actions/download-artifact@v8 + with: + name: mcpx-${{ needs.artifacts.outputs.version }} + path: dist + + - name: Publish the GitHub release + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + TAG: ${{ needs.artifacts.outputs.tag }} + VERSION: ${{ needs.artifacts.outputs.version }} + run: | + set -euo pipefail + cd dist + sha256sum -c SHA256SUMS + cat >notes.md < \| sh`; system-wide: `curl -fsSL \| sh -s -- --system` (fallback: `curl -fsSL \| sudo sh`) | Not yet — there are no releases for it to download | +| bash installer | per-user: `curl -fsSL \| sh`; system-wide: `curl -fsSL \| sh -s -- --system` (fallback: `curl -fsSL \| sudo sh`) | **Shipped, waiting on the first tag** — `pkgs/mcpx/scripts/install.sh` is in this repository and CI installs a snapshot artifact with it (checksum verified, refusal of a tampered tarball proven); it downloads a GitHub release, and no `mcpx/v*` tag has been cut yet, so the commands above do not work until one is | | agent prompt | a prompt you paste to your agent, with the `llms.txt` URL | Not yet | | pwsh (install.ps1) | `irm /install.ps1 \| iex` | **Blocked** — mcpx does not build for Windows today; WSL is the Windows answer | | rpm / deb | `dnf install ./mcpx-.rpm` | Not yet | | flatpak | — | Not recommended (decided in the release design, #1881) | | pkg | — | Not yet — and still an open question: macOS `.pkg`, FreeBSD `pkg`, or Homebrew | -| docker (published) | `docker run … ghcr.io//mcpx` | Not yet — local builds only, see the container row | +| docker (published) | `docker run --rm ghcr.io/developing-today/code/mcpx ls` | **Wired, not yet published** — an `mcpx/v*` tag pushes `ghcr.io/developing-today/code/mcpx:` and `:latest`; no tag has been cut yet, so pull the local build in the container row until one is | Nix caveats, stated plainly: the flake is a large monorepo flake, so installing one package from it fetches and evaluates a lot (the cost @@ -48,8 +48,8 @@ lives on the machine. Every row except the service is shipped today. | Mode | What to do | Status | | --- | --- | --- | | Just run the binary | Nothing. Any command that needs the daemon starts one (`daemon.autostart`, default true), and an auto-started daemon exits after 4 hours idle (`autostart.idleExit`) | Shipped | -| Per-user | Binary in `~/.local/bin`; config at `~/.config/mcpx/config.json` | Config shipped; the binary location arrives with the installer (#1881) | -| Per-host | Binary in `/usr/local/bin` (the installer's `--system`); config at `/etc/mcpx/config.json`, the last stop on the config search path | Config shipped but was undocumented until this page; binary location awaits #1881 | +| Per-user | Binary in `~/.local/bin`; config at `~/.config/mcpx/config.json` | Config shipped; the installer ships and places the binary there once a release exists (#1881) | +| Per-host | Binary in `/usr/local/bin` (the installer's `--system`); config at `/etc/mcpx/config.json`, the last stop on the config search path | Config shipped but was undocumented until this page; the installer's `--system` form places the binary once a release exists (#1881) | | Local host (a daemon other machines reach) | `mcpx daemon --address --port ` on that host; clients set `daemon.endpoint` / `MCPX_DAEMON_ENDPOINT` — a client with an endpoint set never autostarts a local daemon. Remember: the API is unauthenticated, the network is the access control | Shipped | | Persistent daemon | `mcpx daemon` (foreground) or `mcpx daemon --detached`; a deliberately started daemon's `daemon.idleExit` defaults to `0` — it never idle-exits | Shipped | | System service | A launchd plist or systemd unit running `mcpx daemon`, with `daemon.autostart` false on clients so no stray second daemon starts | **Proposed**, not shipped — until then, the on-demand daemon above is the supported path | diff --git a/pkgs/mcpx/scripts/install.sh b/pkgs/mcpx/scripts/install.sh new file mode 100755 index 0000000000..fa7ed68024 --- /dev/null +++ b/pkgs/mcpx/scripts/install.sh @@ -0,0 +1,204 @@ +#!/bin/sh +# Install mcpx from a GitHub release. +# +# curl -fsSL https://raw.githubusercontent.com/developing-today/code/main/pkgs/mcpx/scripts/install.sh | sh +# +# Channel 2 of decision 0005 §2: it installs the release binaries from +# channel 1, so nothing here builds anything. +# +# Per-user by default (~/.local/bin, no sudo). The system-wide variant is +# documented, not default: +# +# curl -fsSL .../install.sh | sh -s -- --system +# +# --system installs into /usr/local/bin and escalates only the copy with +# sudo when that directory is not writable. MCPX_PREFIX overrides either +# default: +# +# curl -fsSL .../install.sh | sudo MCPX_PREFIX=/usr/local/bin sh +# +# The checksum is verified before anything is installed. An installer that +# skips verification teaches people to pipe unverified binaries, which is +# exactly the habit this channel exists to avoid. +# +# A bare binary has no JavaScript runtime, so `mcpx run` and `mcpx exec` need +# Deno, Bun or Node on PATH. The install text says so; `mcpx doctor` reports +# what it found. +# +# Overrides, all optional: +# MCPX_VERSION version to install (default: the latest mcpx release) +# MCPX_PREFIX install directory (default: ~/.local/bin) +# MCPX_RELEASES_URL releases-list endpoint used to resolve the default +# version; CI points it at a fixture file:// URL +# MCPX_BASE_URL where the tarballs and SHA256SUMS live; defaults to the +# release download URL. A local directory or file:// URL +# works, which is how CI exercises this script against a +# snapshot without network or a published release. +set -eu + +repo=developing-today/code + +# Arguments: --system selects the system-wide prefix (/usr/local/bin); +# --user is the explicit form of the default. Anything else is a mistake +# worth refusing rather than silently installing somewhere unexpected -- +# an earlier version of this script ignored its arguments entirely, so +# `sh -s -- --system` quietly did a per-user install (Codex finding on +# PR #2584). +system=0 +for arg in "$@"; do + case "$arg" in + --system) system=1 ;; + --user) system=0 ;; + *) + printf '%s\n' "mcpx installer: unknown argument '$arg' (expected --system or --user)" >&2 + exit 1 + ;; + esac +done + +if [ -n "${MCPX_PREFIX:-}" ]; then + prefix=$MCPX_PREFIX +elif [ "$system" -eq 1 ]; then + prefix=/usr/local/bin +else + prefix=${HOME}/.local/bin +fi +base_url=${MCPX_BASE_URL:-} + +say() { printf '%s\n' "$*" >&2; } +die() { + say "mcpx installer: $*" + exit 1 +} + +# ---- what this machine is ------------------------------------------------- + +case "$(uname -s)" in +Linux) os=linux ;; +Darwin) os=darwin ;; +*) die "unsupported system $(uname -s); mcpx releases are Linux and macOS only (decision 0005 §1)" ;; +esac + +case "$(uname -m)" in +x86_64 | amd64) arch=amd64 ;; +arm64 | aarch64) arch=arm64 ;; +*) die "unsupported machine $(uname -m)" ;; +esac + +# The release asset names use the flake's system spelling (decision 0005 §1), +# so the mapping is explicit rather than composed at the call site. +case "${os}-${arch}" in +linux-amd64) system=x86_64-linux ;; +linux-arm64) system=aarch64-linux ;; +darwin-arm64) system=aarch64-darwin ;; +darwin-amd64) die "no x86_64 macOS release: the flake has no x86_64-darwin system (decision 0005 §1)" ;; +*) die "no release for ${os}/${arch}" ;; +esac + +# ---- which version -------------------------------------------------------- + +version=${MCPX_VERSION:-} +if [ -z "$version" ]; then + # Ask the API for the latest mcpx release. `gh` is not assumed; this is a + # curl|sh installer, so it uses curl. + # + # NOT /releases/latest: that endpoint returns the newest release of the + # whole repository, and this monorepo publishes other packages' releases + # too (graph, via .github/workflows/goreleaser.yml) — when one of those + # is newest there is no mcpx version to extract and the default install + # breaks. List releases instead (the API returns them newest-first) and + # take the first non-prerelease mcpx/v tag. In each release object + # tag_name precedes prerelease, so the awk below can carry the candidate + # from one line to the other. + releases_url=${MCPX_RELEASES_URL:-"https://api.github.com/repos/${repo}/releases?per_page=100"} + version=$(curl -fsSL "$releases_url" | awk ' + /"tag_name":/ { + pending = "" + if (match($0, /"tag_name": *"mcpx\/v[^"]*"/)) { + pending = substr($0, RSTART, RLENGTH) + sub(/"tag_name": *"mcpx\/v/, "", pending) + sub(/"$/, "", pending) + } + next + } + /"prerelease": *true/ { pending = "" } + /"prerelease": *false/ && pending != "" { print pending; exit } + ') || die "could not ask GitHub for the latest mcpx release" + [ -n "$version" ] || + die "no mcpx release found; set MCPX_VERSION to a version that exists (see https://github.com/${repo}/releases)" +fi +version=${version#v} + +if [ -z "$base_url" ]; then + base_url="https://github.com/${repo}/releases/download/mcpx/v${version}" +fi + +asset="mcpx-${version}-${system}.tar.gz" +say "mcpx installer: ${version} for ${system} -> ${prefix}" + +# ---- fetch and verify ----------------------------------------------------- + +tmp=$(mktemp -d) +trap 'rm -rf "$tmp"' EXIT INT TERM + +fetch() { + # $1 = base (a local directory, a file:// URL, or an https URL) + # $2 = destination path + file=$(basename "$2") + case "$1" in + file://*) cp "${1#file://}/${file}" "$2" ;; + /*) cp "$1/${file}" "$2" ;; + *) curl -fsSL "$1/${file}" -o "$2" ;; + esac +} + +say " fetching ${asset}" +fetch "$base_url" "$tmp/$asset" || die "could not download ${asset} from ${base_url}" +say " fetching SHA256SUMS" +fetch "$base_url" "$tmp/SHA256SUMS" || die "could not download SHA256SUMS from ${base_url}" + +# Verify only this asset's line: SHA256SUMS covers all three platforms, and +# the others are not here to be checked. +line=$(grep " ${asset}\$" "$tmp/SHA256SUMS" || true) +[ -n "$line" ] || die "${asset} is not listed in SHA256SUMS" +say " verifying checksum" +if command -v sha256sum >/dev/null 2>&1; then + (cd "$tmp" && printf '%s\n' "$line" | sha256sum -c -) || die "checksum mismatch for ${asset}" +elif command -v shasum >/dev/null 2>&1; then + (cd "$tmp" && printf '%s\n' "$line" | shasum -a 256 -c -) || die "checksum mismatch for ${asset}" +else + die "neither sha256sum nor shasum is available; cannot verify the download" +fi + +tar -C "$tmp" -xzf "$tmp/$asset" || die "could not unpack ${asset}" + +# ---- install -------------------------------------------------------------- + +if ! mkdir -p "$prefix" 2>/dev/null; then + say " ${prefix} does not exist and cannot be created; trying sudo" + sudo mkdir -p "$prefix" +fi +if [ -w "$prefix" ]; then + mv "$tmp/mcpx" "$prefix/mcpx" + chmod 0755 "$prefix/mcpx" +else + # The per-user default never needs this; --system (or an MCPX_PREFIX + # pointing somewhere unwritable) escalates only this copy, exactly as + # docs/install.md promises. + say " ${prefix} is not writable; trying sudo" + sudo mv "$tmp/mcpx" "$prefix/mcpx" + sudo chmod 0755 "$prefix/mcpx" +fi + +installed=$("$prefix/mcpx" --version 2>/dev/null || echo "mcpx (unknown version)") +say " installed: ${installed} at ${prefix}/mcpx" + +case ":${PATH}:" in +*":${prefix}:"*) ;; +*) say " note: ${prefix} is not on PATH; add it to your shell profile" ;; +esac + +# The caveat every non-nix channel states (decision 0005 §1, §5). +say "" +say "mcpx needs a JavaScript runtime for 'mcpx run' and 'mcpx exec'." +say "Install Deno, Bun or Node, then run 'mcpx doctor' to confirm what it found." diff --git a/pkgs/mcpx/scripts/release-artifacts.sh b/pkgs/mcpx/scripts/release-artifacts.sh new file mode 100755 index 0000000000..c602b1bfab --- /dev/null +++ b/pkgs/mcpx/scripts/release-artifacts.sh @@ -0,0 +1,97 @@ +#!/usr/bin/env bash +# Build the release artifacts for one mcpx version. +# +# This is the one implementation of "what a release is" (decision 0005 §2.1, +# §5): three CGO_ENABLED=0 static binaries for the flake's systems, one +# tarball each, and a SHA256SUMS file. The release workflow +# (.github/workflows/mcpx-release.yml) calls it, and so can a person on a +# laptop -- a snapshot is a workflow_dispatch run of the same script, not a +# second code path that could drift. +# +# scripts/release-artifacts.sh [version] +# +# The version defaults to pkgs/mcpx/VERSION (the single source, §3). The +# workflow passes the tag's version instead, so a tag that disagrees with +# VERSION is caught by the caller before anything is built. +# +# Linux binaries are fully static. The behaviour that buys is recorded where +# the install page reads it (docs/container.md, decision 0005 §5): pure-Go +# os/user parses /etc/passwd instead of asking NSS, and the pure-Go resolver +# does not honour nsswitch.conf. +set -euo pipefail + +out=${1:?usage: release-artifacts.sh [version]} +here=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")/.." && pwd) +version=${2:-$(tr -d '\n' <"$here/VERSION")} + +# The tag scheme and the tarball names both use the version without a +# leading v: tags are mcpx/vX.Y.Z, artifacts mcpx--.tar.gz. +case "$version" in +v*) version=${version#v} ;; +esac + +mkdir -p "$out" +out=$(cd -- "$out" && pwd) + +# The three release targets, in the flake's own system spelling so the names +# match what a reader of flake.nix expects (decision 0005 §1). +targets=( + x86_64-linux:linux:amd64 + aarch64-linux:linux:arm64 + aarch64-darwin:darwin:arm64 +) + +cd "$here" +for t in "${targets[@]}"; do + IFS=: read -r system goos goarch <<<"$t" + name="mcpx-${version}-${system}" + stage="$out/.stage/$name" + mkdir -p "$stage" + + echo "==> $name (GOOS=$goos GOARCH=$goarch CGO_ENABLED=0)" + CGO_ENABLED=0 GOOS=$goos GOARCH=$goarch go build \ + -trimpath \ + -buildvcs=false \ + -ldflags "-s -w -X main.version=${version}" \ + -o "$stage/mcpx" ./cmd/mcpx + + # A static binary is the promise, so check it rather than trust the flag. + # file(1) reads a cross-built ELF or Mach-O as happily as the host's own, + # so every target is checked here, not only the one this machine can run. + if command -v file >/dev/null 2>&1; then + desc=$(file -b "$stage/mcpx") + case "$goos" in + linux) + case "$desc" in + *"statically linked"*) ;; + *) echo "error: $name is not a static binary: $desc" >&2; exit 1 ;; + esac + ;; + darwin) + case "$desc" in + *Mach-O*) ;; + *) echo "error: $name is not a Mach-O binary: $desc" >&2; exit 1 ;; + esac + ;; + esac + fi + + tar -C "$stage" -czf "$out/$name.tar.gz" mcpx + rm -rf "$out/.stage" +done + +( + cd "$out" + # sha256sum is GNU; macOS ships shasum instead. The workflow runs on Linux, + # but a person on a laptop runs this same script, so pick whichever exists. + if command -v sha256sum >/dev/null 2>&1; then + sha256sum mcpx-*.tar.gz >SHA256SUMS + else + shasum -a 256 mcpx-*.tar.gz >SHA256SUMS + fi +) + +echo "==> artifacts in $out" +ls -l "$out" +echo "==> SHA256SUMS" +cat "$out/SHA256SUMS"