From efbbeba402af398bebe007a5ae011136093be6eb Mon Sep 17 00:00:00 2001 From: "sentry-junior[bot]" <264270552+sentry-junior[bot]@users.noreply.github.com> Date: Thu, 26 Nov 2026 11:30:24 +0000 Subject: [PATCH] feat(cli): Ship linux-x64-musl and windows-arm64 binaries Node.js publishes official linux-x64-musl and win-arm64 builds, so the standalone binary can cover Alpine on x64 and Windows on ARM. Every other platform (musl on arm64, 32-bit x86, armv7, other OSes) has no official Node.js build and keeps using `npm install -g sentry`. - build.ts builds both targets. Targets carry an optional libc, and `--single` picks the musl target on a musl host. - The bash installer installs sentry-linux-x64-musl on musl x64, after checking for libstdc++, libgcc, and libatomic, which Node's musl build links and Alpine leaves out. It installs sentry-windows-arm64.exe from Git Bash on ARM64. install.ps1 picks the arm64 asset on ARM64. - Every installer refusal now names the npm fallback with Node.js 20+. - CI builds both targets, runs them on Alpine and windows-11-arm before the nightly publishes, and checks the GHCR manifest against the built files instead of a fixed list. The smoke and manifest checks move into tested scripts. - The getting-started platform table lists the new binaries and the npm fallback. `sentry cli upgrade` already picks `-musl` and `windows-arm64` assets, and the Craft targets match the new files by pattern. Co-Authored-By: BYK <126780+BYK@users.noreply.github.com> --- .github/workflows/cli-build.yml | 86 ++++++++++++------ .github/workflows/install-scripts.yml | 3 +- .../src/content/docs/getting-started.mdx | 18 +++- package.json | 2 +- packages/cli/install | 41 ++++++--- packages/cli/install.ps1 | 21 +++-- packages/cli/script/build.ts | 73 +++++++++++---- packages/cli/script/generate-docs-sections.ts | 13 ++- packages/cli/src/lib/upgrade.ts | 4 +- packages/cli/test/lib/binary.musl.test.ts | 43 ++++++++- .../cli/test/lib/install-ps1-script.test.ts | 23 ++++- packages/cli/test/lib/install-scenarios.ts | 2 +- packages/cli/test/lib/install-script.test.ts | 91 ++++++++++++++++--- scripts/check-installer-libc.sh | 34 +++++-- scripts/cli-binary-smoke.mjs | 76 ++++++++++++++++ scripts/cli-binary-smoke.test.mjs | 55 +++++++++++ scripts/cli-nightly-verify.mjs | 84 +++++++++++++++++ scripts/cli-nightly-verify.test.mjs | 56 ++++++++++++ 18 files changed, 622 insertions(+), 103 deletions(-) create mode 100644 scripts/cli-binary-smoke.mjs create mode 100644 scripts/cli-binary-smoke.test.mjs create mode 100644 scripts/cli-nightly-verify.mjs create mode 100644 scripts/cli-nightly-verify.test.mjs diff --git a/.github/workflows/cli-build.yml b/.github/workflows/cli-build.yml index b7a50aa042..6b13061c88 100644 --- a/.github/workflows/cli-build.yml +++ b/.github/workflows/cli-build.yml @@ -51,6 +51,10 @@ jobs: os: ubuntu-latest - target: linux-arm64 os: ubuntu-latest + - target: linux-x64-musl + os: ubuntu-latest + - target: windows-arm64 + os: ubuntu-latest - target: windows-x64 os: ubuntu-latest steps: @@ -126,18 +130,9 @@ jobs: SENTRY_AUTH_TOKEN: "" SENTRY_TOKEN: "" SENTRY_CONFIG_DIR: ${{ runner.temp }}/.sentry-smoke - NIGHTLY_VERSION: ${{ needs.nightly-version.outputs.version }} - TARGET: ${{ matrix.target }} - shell: bash - run: | - binary="packages/cli/dist-bin/sentry-${TARGET}" - "$binary" --help - if [[ "$GITHUB_REF" == 'refs/heads/main' ]]; then - test "$("$binary" --version)" = "$NIGHTLY_VERSION" - fi - output=$("$binary" auth status 2>&1) && status=$? || status=$? - test "$status" -eq 10 - printf '%s\n' "$output" | grep -qi 'not authenticated' + EXPECTED_VERSION: ${{ github.ref == 'refs/heads/main' && needs.nightly-version.outputs.version || '' }} + BINARY: packages/cli/dist-bin/sentry-${{ matrix.target }} + run: node scripts/cli-binary-smoke.mjs - name: Verify code signature (darwin) if: matrix.target == 'darwin-arm64' && github.event_name == 'push' shell: bash @@ -155,6 +150,49 @@ jobs: name: sentry-${{ matrix.target }}-gz path: packages/cli/dist-bin/*.gz + # The build job smoke-tests only binaries its runner can run. This job runs + # the cross-compiled musl and Windows arm64 binaries on their own platform. + smoke-binary: + name: Smoke Test Binary (${{ matrix.target }}) + needs: [nightly-version, build-binary] + runs-on: ${{ matrix.os }} + container: ${{ matrix.container }} + timeout-minutes: 10 + strategy: + fail-fast: false + matrix: + include: + - target: linux-x64-musl + binary: sentry-linux-x64-musl + os: ubuntu-latest + container: alpine:3.24@sha256:f59abe656b692d901e184be3445e084786602108599d2a51d229c0f5a48c71bf + - target: windows-arm64 + binary: sentry-windows-arm64.exe + os: windows-11-arm + steps: + - uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4 + with: + persist-credentials: false + # Alpine has none of the binary's C++ runtime libraries. Add the ones the + # installer asks for, and Node.js for the smoke test script. The + # windows-11-arm image comes with Node.js. + - name: Install Alpine packages + if: matrix.target == 'linux-x64-musl' + run: apk add --no-cache libstdc++ libatomic nodejs + - name: Download binary artifact + uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # v4 + with: + name: sentry-${{ matrix.target }} + path: dist-bin + - name: Smoke test + env: + SENTRY_AUTH_TOKEN: "" + SENTRY_TOKEN: "" + SENTRY_CONFIG_DIR: ${{ runner.temp }}/.sentry-smoke + EXPECTED_VERSION: ${{ github.ref == 'refs/heads/main' && needs.nightly-version.outputs.version || '' }} + BINARY: dist-bin/${{ matrix.binary }} + run: node scripts/cli-binary-smoke.mjs + generate-patches: name: Generate nightly delta patches if: github.ref == 'refs/heads/main' && github.event_name == 'push' @@ -198,14 +236,18 @@ jobs: if: >- always() && github.ref == 'refs/heads/main' && github.event_name == 'push' && needs.nightly-version.result == 'success' && needs.build-binary.result == 'success' && + needs.smoke-binary.result == 'success' && (needs.generate-patches.result == 'success' || needs.generate-patches.result == 'failure') - needs: [nightly-version, build-binary, generate-patches] + needs: [nightly-version, build-binary, smoke-binary, generate-patches] runs-on: ubuntu-latest timeout-minutes: 15 permissions: contents: read packages: write steps: + - uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4 + with: + persist-credentials: false - name: Download compressed binaries uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # v4 with: @@ -240,22 +282,8 @@ jobs: - name: Verify public nightly and immutable version tag env: NIGHTLY_VERSION: ${{ needs.nightly-version.outputs.version }} - shell: bash - run: | - set -euo pipefail - token=$(curl -fsS 'https://ghcr.io/token?scope=repository:getsentry/toolkit:pull' | jq -er '.token') - for tag in nightly "nightly-${NIGHTLY_VERSION}"; do - manifest=$(curl -fsS \ - -H "Authorization: Bearer ${token}" \ - -H 'Accept: application/vnd.oci.image.manifest.v1+json' \ - "https://ghcr.io/v2/getsentry/toolkit/manifests/${tag}") - jq -e --arg version "$NIGHTLY_VERSION" ' - .annotations.version == $version and - .annotations["org.opencontainers.image.source"] == "https://github.com/getsentry/toolkit" and - ([.layers[].annotations["org.opencontainers.image.title"]] | sort) == - (["sentry-darwin-arm64.gz", "sentry-darwin-x64.gz", "sentry-linux-arm64.gz", "sentry-linux-x64.gz", "sentry-windows-x64.exe.gz"] | sort) - ' <<< "$manifest" > /dev/null - done + ARTIFACTS_DIR: artifacts + run: node scripts/cli-nightly-verify.mjs build-npm: name: Build npm Package diff --git a/.github/workflows/install-scripts.yml b/.github/workflows/install-scripts.yml index 5352295187..93352e16c4 100644 --- a/.github/workflows/install-scripts.yml +++ b/.github/workflows/install-scripts.yml @@ -51,7 +51,8 @@ jobs: sentry --version # glibc distros with the musl package installed have the musl loader, which - # the installer once took as proof of musl. Alpine must still be refused. + # the installer once took as proof of musl. Alpine must get the musl build, + # and only once its C++ runtime libraries are installed. linux-libc: name: bash detects ${{ matrix.libc }} on ${{ matrix.image }} runs-on: ubuntu-latest diff --git a/apps/cli-docs/src/content/docs/getting-started.mdx b/apps/cli-docs/src/content/docs/getting-started.mdx index 2dfa943e9f..9bedca36c2 100644 --- a/apps/cli-docs/src/content/docs/getting-started.mdx +++ b/apps/cli-docs/src/content/docs/getting-started.mdx @@ -121,13 +121,18 @@ It installs stable releases only. To switch to nightly afterwards, run - Linux + Linux (glibc) x64, arm64 - Standalone binary requires glibc + Debian, Ubuntu, Fedora, Arch, and most others - Windows + Linux (musl) x64 + Alpine: run apk add libstdc++ libatomic first + + + Windows + x64, arm64 Via PowerShell, Git Bash, MSYS2, or WSL @@ -135,8 +140,11 @@ It installs stable releases only. To switch to nightly afterwards, run {/* GENERATED:END platform-support */} -On Alpine and other musl-based Linux systems, install Node.js and use -`npm install -g sentry` instead of the standalone installer. +The standalone binary embeds Node.js, so it exists only for platforms that +Node.js publishes official builds for. On any other platform, such as musl on +arm64 or 32-bit systems, the installers stop and point you to the npm package: +install Node.js 20 or later and run `npm install -g sentry`, or use another +[package manager](#package-managers). ## Homebrew diff --git a/package.json b/package.json index b8bad5a16f..a682304660 100644 --- a/package.json +++ b/package.json @@ -23,7 +23,7 @@ }, "scripts": { "docs:check": "node scripts/check-doc-links.mjs", - "test:ci-projects": "node --test scripts/ci-projects.test.mjs scripts/check-workspace-deps.test.mjs scripts/cli-nightly-version.test.mjs scripts/cli-nightly-watchdog.test.mjs scripts/platform-setup-pr.test.mjs scripts/codemod-version-changed.test.mjs scripts/cloudflare-deployment.test.mjs scripts/deploy-workflow.test.mjs scripts/migrate-cloudflare-token.test.mjs scripts/oxc-config.test.mjs scripts/cli-lint-rules.test.mjs scripts/workflow-policy.test.mjs scripts/tsconfig-policy.test.mjs", + "test:ci-projects": "node --test scripts/ci-projects.test.mjs scripts/check-workspace-deps.test.mjs scripts/cli-binary-smoke.test.mjs scripts/cli-nightly-version.test.mjs scripts/cli-nightly-verify.test.mjs scripts/cli-nightly-watchdog.test.mjs scripts/platform-setup-pr.test.mjs scripts/codemod-version-changed.test.mjs scripts/cloudflare-deployment.test.mjs scripts/deploy-workflow.test.mjs scripts/migrate-cloudflare-token.test.mjs scripts/oxc-config.test.mjs scripts/cli-lint-rules.test.mjs scripts/workflow-policy.test.mjs scripts/tsconfig-policy.test.mjs", "dev": "pnpm --filter '@sentry/mcp-cloudflare...' --if-present run build && dotenv -e .env -e .env.local -- pnpm --parallel --filter @sentry/mcp-cloudflare --filter @sentry/mcp-core --filter @sentry/mcp-server-mocks --if-present run dev", "dev:stdio": "pnpm --filter '@sentry/mcp-core...' --if-present run build 1>&2 && dotenv -e .env -e .env.local -- pnpm --silent --dir packages/cli run cli mcp", "build": "dotenv -e .env -e .env.local -- pnpm -r --filter '!sentry' --filter '!sentry-cli-docs' --if-present run build", diff --git a/packages/cli/install b/packages/cli/install index 2bf7c74f02..9365334fd3 100755 --- a/packages/cli/install +++ b/packages/cli/install @@ -39,6 +39,9 @@ GHCR_REPO="ghcr.io/v2/getsentry/toolkit" # --retry-all-errors (7.71). curl_retry=(--retry 3 --retry-connrefused --retry-max-time 60) +# Where there is no standalone binary, the npm package runs on Node.js. +npm_fallback="Install Node.js 20 or later and run: npm install -g sentry" + no_room_message="There is not enough room to download sentry (about 140 MB) into the install directory, or it is not writable. Free up space or set SENTRY_INSTALL_DIR to another directory, then retry." # Installer state. The steps below fill these in; error reports read them. @@ -48,9 +51,9 @@ no_completions=false no_agent_skills=false os="" # darwin, linux, or windows arch="" # x64 or arm64 -libc_variant="" # set to musl only to report why the install stopped +libc_variant="" # "musl" on musl-based Linux, such as Alpine suffix="" # ".exe" on Windows -asset="" # release file name, such as sentry-linux-x64 +asset="" # release file name, such as sentry-linux-x64-musl version="" # the exact version being installed gz_url="" # release downloads and their SHA-256 checksums gz_sha="" @@ -227,29 +230,45 @@ detect_platform() { Darwin*) os="darwin" ;; Linux*) os="linux" ;; MINGW*|MSYS*|CYGWIN*) os="windows" ;; - *) die "Unsupported OS: $(uname -s)" "detect-os" ;; + *) die "Unsupported OS: $(uname -s). ${npm_fallback}" "detect-os" ;; esac arch=$(uname -m) case "$arch" in x86_64) arch="x64" ;; aarch64|arm64) arch="arm64" ;; - *) die "Unsupported architecture: $arch" "detect-arch" ;; + *) die "Unsupported architecture: $arch. ${npm_fallback}" "detect-arch" ;; esac - # The standalone binary is a Node.js SEA, and official Node.js builds - # target glibc. + # The standalone binary is a Node.js SEA, so it exists only where Node.js + # publishes an official build. Its only musl build is for x64. if [[ "$os" == "linux" ]] && is_musl; then libc_variant="musl" - die "The standalone binary requires glibc. On musl (Alpine), install Node.js and run: npm install -g sentry" "detect-libc" + [[ "$arch" == "x64" ]] \ + || die "Unsupported: linux-${arch}-musl (the musl binary is x64 only). ${npm_fallback}" "detect-libc" + require_musl_libraries fi if [[ "$os" == "windows" ]]; then suffix=".exe" - [[ "$arch" == "x64" ]] || die "Unsupported: windows-$arch (only windows-x64 is supported)" "detect-arch" fi - asset="sentry-${os}-${arch}${suffix}" + asset="sentry-${os}-${arch}${libc_variant:+-${libc_variant}}${suffix}" +} + +# The musl build of Node.js links against libstdc++, libgcc, and libatomic, +# which Alpine does not install by default. Stop before the download when one +# is missing. +require_musl_libraries() { + local lib missing=() + for lib in libstdc++.so.6 libgcc_s.so.1 libatomic.so.1; do + if [[ ! -e "/lib/${lib}" && ! -e "/usr/lib/${lib}" && ! -e "/usr/local/lib/${lib}" ]]; then + missing+=("$lib") + fi + done + if (( ${#missing[@]} > 0 )); then + die "The musl binary needs ${missing[*]}. On Alpine, run: apk add libstdc++ libatomic, then retry. Or: ${npm_fallback}" "detect-libc-deps" + fi } # Succeeds on musl-based Linux, such as Alpine. @@ -502,7 +521,7 @@ fetch_registry_release() { { read -r gz_url; read -r gz_sha; } <<< "$(registry_file "$metadata" "${asset}.gz")" || true { read -r raw_url; read -r raw_sha; } <<< "$(registry_file "$metadata" "$asset")" || true if [[ -z "$gz_url" && -z "$raw_url" ]]; then - die "Sentry CLI ${version} has no ${asset} build" "resolve-asset" + die "Sentry CLI ${version} has no ${asset} build. ${npm_fallback}" "resolve-asset" fi } @@ -584,7 +603,7 @@ download_nightly() { muted "Installing nightly sentry ${version}..." digest=$(layer_digest "${asset}.gz" <<< "$manifest") - [[ -n "$digest" ]] || die "No nightly build found for ${asset}.gz" "ghcr-digest" + [[ -n "$digest" ]] || die "No nightly build found for ${asset}.gz. ${npm_fallback}" "ghcr-digest" download_nightly_blob "$token" "$digest" unpack_binary "$blob_file" diff --git a/packages/cli/install.ps1 b/packages/cli/install.ps1 index 8f9bec0dfa..425901a02f 100644 --- a/packages/cli/install.ps1 +++ b/packages/cli/install.ps1 @@ -41,12 +41,14 @@ function Install-SentryCli { Write-Verbose "Could not enable TLS 1.2: $_" } - $asset = 'sentry-windows-x64.exe' + # Where there is no standalone binary, the npm package runs on Node.js. + $npmFallback = 'Install Node.js 20 or later and run: npm install -g sentry' # What error reports say about the install. Each step updates it. $state = @{ Step = 'start'; Version = 'unknown'; Arch = 'unknown' } function Invoke-Install { - Assert-WindowsX64 + # The functions below read $asset from this scope. + $asset = Get-WindowsAsset $release = Resolve-Release $binary = Save-Binary $release try { @@ -62,7 +64,8 @@ function Install-SentryCli { # Step 1: check that this machine can run the binary # ------------------------------------------------------------------------- - function Assert-WindowsX64 { + # Returns the release file name for this machine's architecture. + function Get-WindowsAsset { $state.Step = 'detect-os' if ($env:OS -ne 'Windows_NT') { Stop-Install 'This installer is for Windows. On macOS and Linux, run: curl https://cli.sentry.dev/install -fsS | bash' @@ -73,10 +76,14 @@ function Install-SentryCli { # PROCESSOR_ARCHITEW6432 to the real architecture. $arch = if ($env:PROCESSOR_ARCHITEW6432) { $env:PROCESSOR_ARCHITEW6432 } else { $env:PROCESSOR_ARCHITECTURE } $state.Arch = "$arch" - if ($arch -ne 'AMD64') { - Stop-Install "Unsupported: windows-$arch (only windows-x64 is supported). Install Node.js and run: npm install -g sentry" + switch ($arch) { + 'AMD64' { $state.Arch = 'x64' } + 'ARM64' { $state.Arch = 'arm64' } + default { + Stop-Install "Unsupported: windows-$arch (only x64 and arm64 are supported). $npmFallback" + } } - $state.Arch = 'x64' + return "sentry-windows-$($state.Arch).exe" } # ------------------------------------------------------------------------- @@ -115,7 +122,7 @@ function Install-SentryCli { } $state.Version = $release.Version if ($null -eq $release.Gz -and $null -eq $release.Raw) { - Stop-Install "Sentry CLI $($release.Version) has no $asset build" + Stop-Install "Sentry CLI $($release.Version) has no $asset build. $npmFallback" } return $release } diff --git a/packages/cli/script/build.ts b/packages/cli/script/build.ts index 431adc61fa..55a796a584 100644 --- a/packages/cli/script/build.ts +++ b/packages/cli/script/build.ts @@ -24,6 +24,8 @@ * sentry-darwin-x64 * sentry-linux-arm64 * sentry-linux-x64 + * sentry-linux-x64-musl + * sentry-windows-arm64.exe * sentry-windows-x64.exe * dist-build/ (chunks and sourcemaps, embedded and uploaded) */ @@ -69,33 +71,66 @@ const NODE_VERSION = "lts"; */ const SENTRY_CLIENT_ID = process.env["SENTRY_CLIENT_ID"]; -/** Build targets configuration */ +/** + * Build targets configuration. `libc: "musl"` marks a Linux build on Node's + * musl archive; every other Linux build targets glibc. + */ type BuildTarget = { os: "darwin" | "linux" | "win32"; arch: "arm64" | "x64"; + libc?: "musl"; }; +/** + * Each target needs an official Node.js build at NODE_VERSION. There is none + * for musl on arm64, 32-bit x86, or armv7, so those platforms use the npm + * package instead. + */ const ALL_TARGETS: BuildTarget[] = [ { os: "darwin", arch: "arm64" }, { os: "darwin", arch: "x64" }, { os: "linux", arch: "arm64" }, { os: "linux", arch: "x64" }, + { os: "linux", arch: "x64", libc: "musl" }, + { os: "win32", arch: "arm64" }, { os: "win32", arch: "x64" }, ]; +/** `--target` name of a target, such as `linux-x64-musl` or `windows-x64`. */ +function getTargetName(target: BuildTarget): string { + const platformName = target.os === "win32" ? "windows" : target.os; + const libcSuffix = target.libc ? `-${target.libc}` : ""; + return `${platformName}-${target.arch}${libcSuffix}`; +} + /** Get package name for a target (uses "windows" instead of "win32") */ function getPackageName(target: BuildTarget): string { - const platformName = target.os === "win32" ? "windows" : target.os; - return `sentry-${platformName}-${target.arch}`; + return `sentry-${getTargetName(target)}`; } /** - * Map our BuildTarget to fossilize's platform string. - * Fossilize uses Node's archive naming: "win" not "win32". + * Map our BuildTarget to fossilize's platform string, which names the Node + * archive to download (`node-v-`): "win" not "win32", + * and a `-musl` suffix for musl builds. */ function getFossilizePlatform(target: BuildTarget): string { const os = target.os === "win32" ? "win" : target.os; - return `${os}-${target.arch}`; + const libcSuffix = target.libc ? `-${target.libc}` : ""; + return `${os}-${target.arch}${libcSuffix}`; +} + +/** + * The libc of this machine on Linux. Node's report names the glibc version + * only when Node runs on glibc. + */ +function getHostLibc(): BuildTarget["libc"] { + if (process.platform !== "linux") { + return; + } + const report = process.report.getReport() as { + header?: { glibcVersionRuntime?: string }; + }; + return report.header?.glibcVersionRuntime ? undefined : "musl"; } /** @@ -435,15 +470,13 @@ async function postProcessTarget(target: BuildTarget): Promise { } } -/** Parse target string (e.g., "darwin-x64", "linux-arm64") into BuildTarget */ +/** + * Parse target string (e.g., "darwin-x64", "linux-x64-musl") into + * BuildTarget. "win32-" is accepted as an alias for "windows-". + */ function parseTarget(targetStr: string): BuildTarget | null { - // Handle "windows" alias for "win32" - const normalized = targetStr.replace("windows-", "win32-"); - const parts = normalized.split("-"); - const os = parts[0] as BuildTarget["os"]; - const arch = parts[1] as BuildTarget["arch"]; - - const target = ALL_TARGETS.find((t) => t.os === os && t.arch === arch); + const normalized = targetStr.replace(/^win32-/, "windows-"); + const target = ALL_TARGETS.find((t) => getTargetName(t) === normalized); return target ?? null; } @@ -464,18 +497,24 @@ async function build(): Promise { const target = parseTarget(targetArg); if (!target) { logger.error( - `Invalid target: ${targetArg}\nValid targets: ${ALL_TARGETS.map((t) => `${t.os === "win32" ? "windows" : t.os}-${t.arch}`).join(", ")}`, + `Invalid target: ${targetArg}\nValid targets: ${ALL_TARGETS.map(getTargetName).join(", ")}`, ); process.exit(1); } targets = [target]; logger.info(`Building for target: ${getPackageName(target)}`); } else if (singleBuild) { + const hostLibc = getHostLibc(); const currentTarget = ALL_TARGETS.find( - (t) => t.os === process.platform && t.arch === process.arch, + (t) => + t.os === process.platform && + t.arch === process.arch && + t.libc === hostLibc, ); if (!currentTarget) { - logger.error(`Unsupported platform: ${process.platform}-${process.arch}`); + logger.error( + `Unsupported platform: ${process.platform}-${process.arch}${hostLibc ? `-${hostLibc}` : ""}`, + ); process.exit(1); } targets = [currentTarget]; diff --git a/packages/cli/script/generate-docs-sections.ts b/packages/cli/script/generate-docs-sections.ts index 7901047334..15d9446379 100644 --- a/packages/cli/script/generate-docs-sections.ts +++ b/packages/cli/script/generate-docs-sections.ts @@ -542,8 +542,17 @@ function generateSelfHostedEnvVarsTable(): string { */ const PLATFORM_ROWS: readonly [string, string, string][] = [ ["macOS", "x64, arm64 (Apple Silicon)", ""], - ["Linux", "x64, arm64", "Standalone binary requires glibc"], - ["Windows", "x64", "Via PowerShell, Git Bash, MSYS2, or WSL"], + [ + "Linux (glibc)", + "x64, arm64", + "Debian, Ubuntu, Fedora, Arch, and most others", + ], + [ + "Linux (musl)", + "x64", + "Alpine: run apk add libstdc++ libatomic first", + ], + ["Windows", "x64, arm64", "Via PowerShell, Git Bash, MSYS2, or WSL"], ]; /** Generate the platform support table for getting-started.mdx. */ diff --git a/packages/cli/src/lib/upgrade.ts b/packages/cli/src/lib/upgrade.ts index bc624a5f8d..207b55b134 100644 --- a/packages/cli/src/lib/upgrade.ts +++ b/packages/cli/src/lib/upgrade.ts @@ -1007,8 +1007,8 @@ async function streamDecompressToFile( /** * Build the gzip filename for the current platform binary. * - * Nightly builds are stored in GHCR as `sentry--.gz` (or - * `sentry-windows-x64.exe.gz` on Windows). This filename is the + * Nightly builds are stored in GHCR as `sentry--[-musl].gz` (or + * `sentry-windows-.exe.gz` on Windows). This filename is the * `org.opencontainers.image.title` annotation on the matching OCI layer. * * @returns Filename of the gzip-compressed binary for this platform diff --git a/packages/cli/test/lib/binary.musl.test.ts b/packages/cli/test/lib/binary.musl.test.ts index 1cf9d8ebce..6727b298ac 100644 --- a/packages/cli/test/lib/binary.musl.test.ts +++ b/packages/cli/test/lib/binary.musl.test.ts @@ -1,6 +1,7 @@ /** - * Tests for isMusl() against simulated libc layouts. Kept in a separate file - * so the node:child_process and node:fs mocks don't leak into binary.test.ts. + * Tests for isMusl() and getPlatformBinaryName() against simulated libc + * layouts. Kept in a separate file so the node:child_process and node:fs + * mocks don't leak into binary.test.ts. */ import type { SpawnSyncReturns } from "node:child_process"; @@ -85,3 +86,41 @@ describe.runIf(process.platform === "linux")("isMusl", () => { expect(await detect()).toBe(false); }); }); + +// The release file that `sentry cli upgrade` downloads must be one that +// script/build.ts builds. +describe("getPlatformBinaryName", () => { + const platform = Object.getOwnPropertyDescriptor(process, "platform"); + const arch = Object.getOwnPropertyDescriptor(process, "arch"); + + beforeEach(() => { + vi.resetModules(); + }); + + afterEach(() => { + mocks.ldd = undefined; + if (platform && arch) { + Object.defineProperty(process, "platform", platform); + Object.defineProperty(process, "arch", arch); + } + }); + + test.each([ + ["sentry-darwin-arm64", "darwin", "arm64", glibcLdd], + ["sentry-darwin-x64", "darwin", "x64", glibcLdd], + ["sentry-linux-arm64", "linux", "arm64", glibcLdd], + ["sentry-linux-x64", "linux", "x64", glibcLdd], + ["sentry-linux-x64-musl", "linux", "x64", muslLdd], + ["sentry-windows-arm64.exe", "win32", "arm64", glibcLdd], + ["sentry-windows-x64.exe", "win32", "x64", glibcLdd], + ])("names %s on %s %s", async (expected, os, cpu, ldd) => { + mocks.ldd = ldd; + Object.defineProperty(process, "platform", { + configurable: true, + value: os, + }); + Object.defineProperty(process, "arch", { configurable: true, value: cpu }); + const { getPlatformBinaryName } = await import("../../src/lib/binary.js"); + expect(getPlatformBinaryName()).toBe(expected); + }); +}); diff --git a/packages/cli/test/lib/install-ps1-script.test.ts b/packages/cli/test/lib/install-ps1-script.test.ts index 9a8005aeb2..9d8db69384 100644 --- a/packages/cli/test/lib/install-ps1-script.test.ts +++ b/packages/cli/test/lib/install-ps1-script.test.ts @@ -229,6 +229,25 @@ describe.skipIf(!hasPwsh)("PowerShell install script", () => { expect(recorded("post-args")).toEqual(["init"]); }); + test("installs the arm64 binary on Windows ARM64", () => { + const arm64Asset = "sentry-windows-arm64.exe"; + env["PROCESSOR_ARCHITECTURE"] = "ARM64"; + applyScenario( + { ...at(INSTALL_SCENARIOS, 0), name: "arm64" }, + { ...served, name: arm64Asset }, + testDir, + env, + ); + + const result = run(); + + expect(result.status, result.stdout + result.stderr).toBe(0); + expect(recorded("urls").at(-1)).toBe( + toolkitDownload(LATEST_VERSION, `${arm64Asset}.gz`), + ); + expect(existsSync(join(installDir, "sentry.exe"))).toBe(true); + }); + test("passes --no-modify-path to setup when SENTRY_NO_MODIFY_PATH=1", () => { env["SENTRY_NO_MODIFY_PATH"] = "1"; @@ -249,9 +268,9 @@ describe.skipIf(!hasPwsh)("PowerShell install script", () => { { name: "unsupported architectures", setup: () => { - env["PROCESSOR_ARCHITECTURE"] = "ARM64"; + env["PROCESSOR_ARCHITECTURE"] = "x86"; }, - message: "only windows-x64 is supported", + message: "only x64 and arm64 are supported", }, { name: "the nightly channel", diff --git a/packages/cli/test/lib/install-scenarios.ts b/packages/cli/test/lib/install-scenarios.ts index 53d7cf5154..33b1700b13 100644 --- a/packages/cli/test/lib/install-scenarios.ts +++ b/packages/cli/test/lib/install-scenarios.ts @@ -180,7 +180,7 @@ export const INSTALL_SCENARIOS: InstallScenario[] = [ name: "stops when the release has no build for this platform", registry: { status: 200, missingAsset: true }, ok: false, - output: [`Sentry CLI ${LATEST_VERSION} has no`], + output: [`Sentry CLI ${LATEST_VERSION} has no`, "npm install -g sentry"], requests: () => [`${REGISTRY}/latest`], }, { diff --git a/packages/cli/test/lib/install-script.test.ts b/packages/cli/test/lib/install-script.test.ts index 8d77d34ebb..11011579c9 100644 --- a/packages/cli/test/lib/install-script.test.ts +++ b/packages/cli/test/lib/install-script.test.ts @@ -505,31 +505,94 @@ process.exitCode = result.status ?? 1; }, ); - test("directs musl users to the npm package before downloading a glibc binary", () => { + /** Make `uname` report this platform, and `ldd` report musl when asked. */ + function fakePlatform(system: string, machine: string, libc?: "musl") { writeFileSync( join(binDir, "uname"), - '#!/bin/sh\ncase "$1" in -s) echo Linux ;; -m) echo x86_64 ;; esac\n', + `#!/bin/sh\ncase "$1" in -s) echo ${system} ;; -m) echo ${machine} ;; esac\n`, { mode: 0o700 }, ); - // Like the real musl ldd: version on stderr, non-zero exit. - writeFileSync( - join(binDir, "ldd"), - "#!/bin/sh\nprintf 'musl libc (x86_64)\\n' >&2\nexit 1\n", - { - mode: 0o700, - }, - ); - const result = spawnSync("bash", [installScript, "--no-modify-path"], { + if (libc === "musl") { + // Like the real musl ldd: version on stderr, non-zero exit. + writeFileSync( + join(binDir, "ldd"), + "#!/bin/sh\nprintf 'musl libc (x86_64)\\n' >&2\nexit 1\n", + { mode: 0o700 }, + ); + } + } + + /** Serve `name` as this platform's release file. */ + function serve(name: string) { + applyScenario( + { ...at(INSTALL_SCENARIOS, 0), name }, + { ...served, name }, + testDir, env, - encoding: "utf8", - timeout: 10_000, - }); + ); + } + + test("directs musl arm64 users to the npm package before downloading", () => { + fakePlatform("Linux", "aarch64", "musl"); + + const result = install(); expect(result.status).not.toBe(0); + expect(result.stderr).toContain("linux-arm64-musl"); expect(result.stderr).toContain("npm install -g sentry"); expect(recorded("curl-urls")).toEqual([]); }); + // The installer looks for these where Alpine installs them. A glibc host + // keeps them elsewhere, such as /usr/lib/x86_64-linux-gnu. + const hasMuslLibraries = [ + "libstdc++.so.6", + "libgcc_s.so.1", + "libatomic.so.1", + ].every((lib) => + ["/lib", "/usr/lib", "/usr/local/lib"].some((dir) => + existsSync(join(dir, lib)), + ), + ); + + test.skipIf(hasMuslLibraries)( + "names the libraries the musl binary needs before downloading it", + () => { + fakePlatform("Linux", "x86_64", "musl"); + + const result = install(); + + expect(result.status).not.toBe(0); + expect(result.stderr).toContain("apk add libstdc++ libatomic"); + expect(result.stderr).toContain("npm install -g sentry"); + expect(recorded("curl-urls")).toEqual([]); + }, + ); + + test.runIf(hasMuslLibraries)("installs the musl build on musl x64", () => { + fakePlatform("Linux", "x86_64", "musl"); + serve("sentry-linux-x64-musl"); + + const result = install(); + + expect(result.status, result.output).toBe(0); + expect(recorded("curl-urls").at(-1)).toBe( + toolkitDownload(LATEST_VERSION, "sentry-linux-x64-musl.gz"), + ); + }); + + test("installs the arm64 build on Windows ARM64", () => { + fakePlatform("MINGW64_NT-10.0-26100", "aarch64"); + serve("sentry-windows-arm64.exe"); + + const result = install(); + + expect(result.status, result.output).toBe(0); + expect(recorded("curl-urls").at(-1)).toBe( + toolkitDownload(LATEST_VERSION, "sentry-windows-arm64.exe.gz"), + ); + }); + function install() { const result = spawnSync("bash", [installScript, "--no-modify-path"], { env, diff --git a/scripts/check-installer-libc.sh b/scripts/check-installer-libc.sh index b1bd5c315d..61b5808c20 100755 --- a/scripts/check-installer-libc.sh +++ b/scripts/check-installer-libc.sh @@ -4,7 +4,8 @@ # # EXPECTED_LIBC=glibc: on a glibc distro, install the musl package, which adds # the musl loader, and check the installer still installs a working binary. -# EXPECTED_LIBC=musl: check the installer stops and points to the npm package. +# EXPECTED_LIBC=musl: check the installer names the C++ runtime libraries the +# musl binary needs, then installs them and checks it installs the binary. set -eu expected="${EXPECTED_LIBC:?set EXPECTED_LIBC to glibc or musl}" @@ -30,15 +31,19 @@ if [ ! -e "$loader" ]; then exit 1 fi -SENTRY_INSTALL_DIR=$(mktemp -d) -export SENTRY_INSTALL_DIR log=$(mktemp) -status=0 -bash packages/cli/install --no-modify-path >"$log" 2>&1 || status=$? -cat "$log" +# Sets status, and log to the installer's output. +run_installer() { + SENTRY_INSTALL_DIR=$(mktemp -d) + export SENTRY_INSTALL_DIR + status=0 + bash packages/cli/install --no-modify-path >"$log" 2>&1 || status=$? + cat "$log" +} case "$expected" in glibc) + run_installer if [ "$status" -ne 0 ]; then echo "Installer exited $status on glibc with $loader present" >&2 exit 1 @@ -46,12 +51,23 @@ case "$expected" in "$SENTRY_INSTALL_DIR/sentry" --version ;; musl) + run_installer if [ "$status" -eq 0 ]; then - echo "Installer installed the glibc binary on musl" >&2 + echo "Installer installed a binary on musl without its C++ runtime libraries" >&2 exit 1 fi - if ! grep -q "npm install -g sentry" "$log"; then - echo "Installer did not point musl users to the npm package" >&2 + if ! grep -q "apk add libstdc++ libatomic" "$log"; then + echo "Installer did not name the libraries the musl binary needs" >&2 + exit 1 + fi + + apk add --no-cache libstdc++ libatomic + run_installer + if [ "$status" -eq 0 ]; then + "$SENTRY_INSTALL_DIR/sentry" --version + elif ! grep -q "has no sentry-linux-x64-musl build" "$log"; then + # Releases before the first musl build have none to install. + echo "Installer exited $status on musl with the libraries installed" >&2 exit 1 fi ;; diff --git a/scripts/cli-binary-smoke.mjs b/scripts/cli-binary-smoke.mjs new file mode 100644 index 0000000000..2775f782c8 --- /dev/null +++ b/scripts/cli-binary-smoke.mjs @@ -0,0 +1,76 @@ +import { spawnSync } from "node:child_process"; +import { chmodSync } from "node:fs"; +import { pathToFileURL } from "node:url"; + +/** Exit code of `sentry auth status` without credentials. */ +const NOT_AUTHENTICATED_EXIT = 10; + +function run(binary, args) { + const result = spawnSync(binary, args, { encoding: "utf8" }); + if (result.error) { + throw new Error(`${binary} ${args.join(" ")}: ${result.error.message}`); + } + return { + status: result.status, + output: `${result.stdout}${result.stderr}`, + }; +} + +/** + * Runs a standalone binary the way a new user does, with no credentials. + * Returns human-readable problems, empty when it works. When + * `expectedVersion` is set, `--version` must print it. + */ +export function smokeTest(binary, { expectedVersion } = {}) { + const problems = []; + + const help = run(binary, ["--help"]); + if (help.status !== 0) { + problems.push(`--help exited ${help.status}:\n${help.output}`); + } + + if (expectedVersion) { + const version = run(binary, ["--version"]); + if (version.output.trim() !== expectedVersion) { + problems.push( + `--version printed ${JSON.stringify(version.output.trim())}, expected ${expectedVersion}`, + ); + } + } + + const auth = run(binary, ["auth", "status"]); + if ( + auth.status !== NOT_AUTHENTICATED_EXIT || + !/not authenticated/i.test(auth.output) + ) { + problems.push( + `auth status exited ${auth.status}, expected ${NOT_AUTHENTICATED_EXIT} with "not authenticated":\n${auth.output}`, + ); + } + + return problems; +} + +if ( + process.argv[1] && + import.meta.url === pathToFileURL(process.argv[1]).href +) { + const binary = process.env.BINARY; + if (!binary) { + throw new Error("BINARY is required"); + } + // Downloaded workflow artifacts lose the exec bit. + if (process.platform !== "win32") { + chmodSync(binary, 0o755); + } + const problems = smokeTest(binary, { + expectedVersion: process.env.EXPECTED_VERSION || undefined, + }); + for (const problem of problems) { + console.error(`::error::${problem}`); + } + if (problems.length > 0) { + process.exit(1); + } + console.log(`${binary} passed the smoke test`); +} diff --git a/scripts/cli-binary-smoke.test.mjs b/scripts/cli-binary-smoke.test.mjs new file mode 100644 index 0000000000..6efa7fbba4 --- /dev/null +++ b/scripts/cli-binary-smoke.test.mjs @@ -0,0 +1,55 @@ +import assert from "node:assert/strict"; +import { mkdtempSync, rmSync, writeFileSync } from "node:fs"; +import { tmpdir } from "node:os"; +import { join } from "node:path"; +import { after, describe, test } from "node:test"; +import { smokeTest } from "./cli-binary-smoke.mjs"; + +const directory = mkdtempSync(join(tmpdir(), "cli-binary-smoke-")); +after(() => rmSync(directory, { recursive: true, force: true })); + +/** A stand-in binary: `case` arms keyed by the first argument. */ +function fakeBinary(name, arms) { + const path = join(directory, name); + writeFileSync(path, `#!/bin/sh\ncase "$1" in\n${arms}\nesac\n`, { + mode: 0o755, + }); + return path; +} + +const WORKING = ` --help) echo USAGE ;; + --version) echo 4.0.0 ;; + auth) echo "Error: Not authenticated." >&2; exit 10 ;;`; + +describe("smokeTest", () => { + test("passes a binary that works without credentials", () => { + const binary = fakeBinary("working", WORKING); + assert.deepEqual(smokeTest(binary, { expectedVersion: "4.0.0" }), []); + }); + + test("reports a binary that cannot start", () => { + const binary = fakeBinary( + "broken", + ' *) echo "Error loading shared library libstdc++.so.6" >&2; exit 127 ;;', + ); + const problems = smokeTest(binary); + assert.equal(problems.length, 2); + assert.match(problems[0], /--help exited 127/); + assert.match(problems[1], /libstdc\+\+/); + }); + + test("reports a version other than the expected one", () => { + const binary = fakeBinary("old", WORKING); + assert.deepEqual(smokeTest(binary, { expectedVersion: "4.0.1" }), [ + '--version printed "4.0.0", expected 4.0.1', + ]); + }); + + test("reports a binary that claims to be authenticated", () => { + const binary = fakeBinary( + "authenticated", + " --help) echo USAGE ;;\n auth) echo Authenticated ;;", + ); + assert.match(smokeTest(binary)[0], /auth status exited 0/); + }); +}); diff --git a/scripts/cli-nightly-verify.mjs b/scripts/cli-nightly-verify.mjs new file mode 100644 index 0000000000..20dd249f48 --- /dev/null +++ b/scripts/cli-nightly-verify.mjs @@ -0,0 +1,84 @@ +import { readdirSync } from "node:fs"; +import { pathToFileURL } from "node:url"; + +const REPOSITORY = "getsentry/toolkit"; +const SOURCE = `https://github.com/${REPOSITORY}`; + +/** + * Returns human-readable problems with a published nightly manifest: it must + * carry `version`, name this repository as its source, and have one layer for + * each compressed binary the build produced (`files`), no more and no fewer. + */ +export function checkNightlyManifest(manifest, { version, files }) { + const problems = []; + const annotations = manifest.annotations ?? {}; + if (annotations.version !== version) { + problems.push( + `version is ${JSON.stringify(annotations.version)}, expected ${version}`, + ); + } + if (annotations["org.opencontainers.image.source"] !== SOURCE) { + problems.push( + `source is ${JSON.stringify(annotations["org.opencontainers.image.source"])}, expected ${SOURCE}`, + ); + } + const byName = (a, b) => a.localeCompare(b); + const layers = (manifest.layers ?? []) + .map((layer) => layer.annotations?.["org.opencontainers.image.title"] ?? "") + .sort(byName); + const expected = [...files].sort(byName); + if (JSON.stringify(layers) !== JSON.stringify(expected)) { + problems.push( + `layers are ${layers.join(", ")}, expected ${expected.join(", ")}`, + ); + } + return problems; +} + +async function getJson(url, headers) { + const response = await fetch(url, { headers }); + if (!response.ok) { + throw new Error(`GET ${url} returned ${response.status}`); + } + return await response.json(); +} + +async function main() { + const version = process.env.NIGHTLY_VERSION; + const artifactsDir = process.env.ARTIFACTS_DIR; + if (!version || !artifactsDir) { + throw new Error("NIGHTLY_VERSION and ARTIFACTS_DIR are required"); + } + const files = readdirSync(artifactsDir).filter((name) => + name.endsWith(".gz"), + ); + + const { token } = await getJson( + `https://ghcr.io/token?scope=repository:${REPOSITORY}:pull`, + ); + let failed = false; + for (const tag of ["nightly", `nightly-${version}`]) { + const manifest = await getJson( + `https://ghcr.io/v2/${REPOSITORY}/manifests/${tag}`, + { + Authorization: `Bearer ${token}`, + Accept: "application/vnd.oci.image.manifest.v1+json", + }, + ); + for (const problem of checkNightlyManifest(manifest, { version, files })) { + console.error(`::error::${tag}: ${problem}`); + failed = true; + } + } + if (failed) { + process.exit(1); + } + console.log(`nightly and nightly-${version} list ${files.length} binaries`); +} + +if ( + process.argv[1] && + import.meta.url === pathToFileURL(process.argv[1]).href +) { + await main(); +} diff --git a/scripts/cli-nightly-verify.test.mjs b/scripts/cli-nightly-verify.test.mjs new file mode 100644 index 0000000000..58f0a55843 --- /dev/null +++ b/scripts/cli-nightly-verify.test.mjs @@ -0,0 +1,56 @@ +import assert from "node:assert/strict"; +import { describe, test } from "node:test"; +import { checkNightlyManifest } from "./cli-nightly-verify.mjs"; + +const VERSION = "4.0.0-dev.1795000000"; +const FILES = ["sentry-linux-x64.gz", "sentry-linux-x64-musl.gz"]; + +function manifest({ + version = VERSION, + source = "https://github.com/getsentry/toolkit", + titles = FILES, +} = {}) { + return { + annotations: { version, "org.opencontainers.image.source": source }, + layers: titles.map((title) => ({ + annotations: { "org.opencontainers.image.title": title }, + })), + }; +} + +describe("checkNightlyManifest", () => { + test("accepts a manifest with one layer per built binary, in any order", () => { + assert.deepEqual( + checkNightlyManifest(manifest({ titles: [...FILES].reverse() }), { + version: VERSION, + files: FILES, + }), + [], + ); + }); + + test("reports a binary missing from the manifest", () => { + assert.deepEqual( + checkNightlyManifest(manifest({ titles: ["sentry-linux-x64.gz"] }), { + version: VERSION, + files: FILES, + }), + [ + "layers are sentry-linux-x64.gz, expected sentry-linux-x64-musl.gz, sentry-linux-x64.gz", + ], + ); + }); + + test("reports another version or source", () => { + assert.deepEqual( + checkNightlyManifest( + manifest({ version: "4.0.0-dev.1", source: "https://example.com" }), + { version: VERSION, files: FILES }, + ), + [ + `version is "4.0.0-dev.1", expected ${VERSION}`, + 'source is "https://example.com", expected https://github.com/getsentry/toolkit', + ], + ); + }); +});