From e5e63f4757e800541727c44aa37f0ec4de7f80bf Mon Sep 17 00:00:00 2001 From: Ian Duffy Date: Wed, 18 Nov 2026 12:18:02 +0000 Subject: [PATCH 1/3] feat(ENG-15913): accept a major version for --version --version 1 (-Version 1 in PowerShell) installs the latest 1.x release from the cloudsmith-cli-v1-manifest- manifest. The installer fails when the manifest is outside the requested major version. Co-Authored-By: Claude Opus 5.5 --- CHANGELOG.md | 6 ++++++ README.md | 10 +++++++++- install.ps1 | 13 +++++++++++-- install.sh | 27 ++++++++++++++++++++++++--- tests/Install.Tests.ps1 | 30 ++++++++++++++++++++++++++++++ tests/install.bats | 26 ++++++++++++++++++++++++++ 6 files changed, 106 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b39aa14..b48ed8a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Added + +- `--version` (`-Version` in PowerShell) accepts a major version, such as + `1`. The installer then installs the latest release of that major version, + from the `cloudsmith-cli-v-manifest-` manifest. + ## [0.1.2] - 2026-07-30 ### Fixed diff --git a/README.md b/README.md index d07c327..0ddc3d6 100644 --- a/README.md +++ b/README.md @@ -81,6 +81,14 @@ where `` is `cli.sh`, `cli.ps1`, or `SHA256SUMS`, then run it with `--version X.Y.Z` (`-Version X.Y.Z` in PowerShell). Use pinned, verified downloads in CI. +Download the script and `SHA256SUMS` from the same `` path. The +`latest` path resolves each file separately, so for a short time after a +release the two files can come from different releases. + +To stay on one major version, set `--version` to that major version, for +example `--version 1` (`-Version 1` in PowerShell). The installer then +installs the latest 1.x release, and never a 2.x release. + ## How installation works ```mermaid @@ -111,7 +119,7 @@ Command-line options take precedence over environment variables. | Shell option | PowerShell parameter | Environment variable | Default | | --- | --- | --- | --- | -| `--version` | `-Version` | `CLOUDSMITH_CLI_VERSION` | `latest` | +| `--version` | `-Version` | `CLOUDSMITH_CLI_VERSION` | `latest`. Also accepts `X.Y.Z` or a major version such as `1` | | `--install-root` | `-InstallRoot` | `CLOUDSMITH_CLI_INSTALL_ROOT` | Shell: `$XDG_DATA_HOME/cloudsmith-cli` or `~/.local/share/cloudsmith-cli`
PowerShell: `%LOCALAPPDATA%\Cloudsmith\CLI` | | `--target` | `-Target` | `CLOUDSMITH_CLI_TARGET` | Automatically detected | | `--output-file` | `-OutputFile` | `CLOUDSMITH_CLI_OUTPUT_FILE` | Standard output | diff --git a/install.ps1 b/install.ps1 index f0f2c9d..91fec71 100644 --- a/install.ps1 +++ b/install.ps1 @@ -389,8 +389,13 @@ try { [void][System.IO.Directory]::CreateDirectory($script:WorkDir) $manifestFile = Join-Path $script:WorkDir "manifest.txt" + $isMajorVersion = $Version -match '^[0-9]+\z' if (-not $ManifestUrl) { - $ManifestUrl = "$DownloadBaseUrl/$Repository/raw/names/$ManifestNamePrefix-$resolvedTarget/versions/$Version/manifest.txt" + if ($isMajorVersion) { + $ManifestUrl = "$DownloadBaseUrl/$Repository/raw/names/cloudsmith-cli-v$Version-manifest-$resolvedTarget/versions/latest/manifest.txt" + } else { + $ManifestUrl = "$DownloadBaseUrl/$Repository/raw/names/$ManifestNamePrefix-$resolvedTarget/versions/$Version/manifest.txt" + } } Write-InstallerLog "fetching release manifest" @@ -412,7 +417,11 @@ try { if ($manifestTarget -ne $resolvedTarget) { throw "install.ps1: manifest target '$manifestTarget' does not match '$resolvedTarget'" } - if ($Version -ne 'latest' -and $Version -ne $resolvedVersion) { + if ($isMajorVersion) { + if (-not $resolvedVersion.StartsWith("$Version.")) { + throw "install.ps1: manifest resolved '$resolvedVersion', expected a $Version.x release" + } + } elseif ($Version -ne 'latest' -and $Version -ne $resolvedVersion) { throw "install.ps1: manifest resolved '$resolvedVersion', expected '$Version'" } if (-not $archiveName -or $archiveName -match '[/\\]') { diff --git a/install.sh b/install.sh index d36a8af..54c1c7a 100755 --- a/install.sh +++ b/install.sh @@ -33,7 +33,7 @@ usage() { cat <<'USAGE' Usage: install.sh [options] - --version VERSION CLI version, or "latest" + --version VERSION CLI version, major version such as "1", or "latest" --install-root DIR Versioned installation root --target TARGET Override target detection --output-file FILE Write key=value installation results @@ -218,10 +218,31 @@ detect_target() { esac } +is_major_version() { + case "$1" in ''|*[!0-9]*) return 1 ;; esac +} + +check_resolved_version() { + if [ "$REQUESTED_VERSION" = latest ]; then + return 0 + fi + if is_major_version "$REQUESTED_VERSION"; then + case "$RESOLVED_VERSION" in + "$REQUESTED_VERSION".*) return 0 ;; + esac + die "manifest resolved '$RESOLVED_VERSION', expected a $REQUESTED_VERSION.x release" + fi + [ "$REQUESTED_VERSION" = "$RESOLVED_VERSION" ] || die "manifest resolved '$RESOLVED_VERSION', expected '$REQUESTED_VERSION'" +} + fetch_manifest() { MANIFEST_FILE="$WORK_DIR/manifest.txt" if [ -z "$MANIFEST_URL" ]; then - MANIFEST_URL="$DOWNLOAD_BASE_URL/$REPOSITORY/raw/names/$MANIFEST_NAME_PREFIX-$TARGET/versions/$REQUESTED_VERSION/manifest.txt" + if is_major_version "$REQUESTED_VERSION"; then + MANIFEST_URL="$DOWNLOAD_BASE_URL/$REPOSITORY/raw/names/cloudsmith-cli-v$REQUESTED_VERSION-manifest-$TARGET/versions/latest/manifest.txt" + else + MANIFEST_URL="$DOWNLOAD_BASE_URL/$REPOSITORY/raw/names/$MANIFEST_NAME_PREFIX-$TARGET/versions/$REQUESTED_VERSION/manifest.txt" + fi fi require_https "$MANIFEST_URL" "manifest URL" log "fetching release manifest" @@ -239,7 +260,7 @@ validate_manifest() { [ "$SCHEMA" = 1 ] || die "unsupported manifest schema: ${SCHEMA:-missing}" case "$RESOLVED_VERSION" in ''|.|..|*[!A-Za-z0-9._+-]*) die "manifest contains an invalid version" ;; esac [ "$MANIFEST_TARGET" = "$TARGET" ] || die "manifest target '$MANIFEST_TARGET' does not match '$TARGET'" - [ "$REQUESTED_VERSION" = latest ] || [ "$REQUESTED_VERSION" = "$RESOLVED_VERSION" ] || die "manifest resolved '$RESOLVED_VERSION', expected '$REQUESTED_VERSION'" + check_resolved_version case "$ARCHIVE_NAME" in ''|*/*|*\\*) die "manifest contains an invalid archive name" ;; esac [ -n "$ARCHIVE_URL" ] || die "manifest is missing url" case "$EXPECTED_SHA256" in ''|*[!0-9a-f]*) die "manifest contains an invalid SHA-256" ;; esac diff --git a/tests/Install.Tests.ps1 b/tests/Install.Tests.ps1 index 2826b49..774f3de 100644 --- a/tests/Install.Tests.ps1 +++ b/tests/Install.Tests.ps1 @@ -339,6 +339,36 @@ Describe 'Cloudsmith CLI installer (install.ps1)' -Tag 'Windows' -Skip:(-not $sc $result.StdOut[0] | Should -Be 'version=2.4.6' } + It 'installs the release of the requested major version' { + $installRoot = Join-Path $TestDrive ("root-" + [Guid]::NewGuid().ToString('N')) + $fixture = New-CloudsmithFixture -Directory $script:FixtureDir -Version '1.19.0' -Target $script:DefaultTarget -BaseUrl $script:Server.Url + + $result = Invoke-Installer -HostExe $currentHostExe -ScriptArguments @( + '-Version', '1', + '-InstallRoot', $installRoot, + '-Target', $script:DefaultTarget, + '-ManifestUrl', $fixture.ManifestUrl + ) + + $result.ExitCode | Should -Be 0 -Because "stderr: $($result.StdErr)" + $result.StdOut[0] | Should -Be 'version=1.19.0' + } + + It 'fails when the manifest is outside the requested major version' { + $installRoot = Join-Path $TestDrive ("root-" + [Guid]::NewGuid().ToString('N')) + $fixture = New-CloudsmithFixture -Directory $script:FixtureDir -Version '10.0.0' -Target $script:DefaultTarget -BaseUrl $script:Server.Url + + $result = Invoke-Installer -HostExe $currentHostExe -ScriptArguments @( + '-Version', '1', + '-InstallRoot', $installRoot, + '-Target', $script:DefaultTarget, + '-ManifestUrl', $fixture.ManifestUrl + ) + + $result.ExitCode | Should -Not -Be 0 + $result.StdErr | Should -Match "manifest resolved '10\.0\.0', expected a 1\.x release" + } + It 'writes exactly four lines to -OutputFile (UTF-8, no BOM) and leaves stdout empty' { $installRoot = Join-Path $TestDrive ("root-" + [Guid]::NewGuid().ToString('N')) $outputFile = Join-Path $TestDrive ("out-" + [Guid]::NewGuid().ToString('N') + '.txt') diff --git a/tests/install.bats b/tests/install.bats index 6f0d797..b13637a 100644 --- a/tests/install.bats +++ b/tests/install.bats @@ -183,6 +183,32 @@ executable=$bin_dir/cloudsmith" [ -x "$bin_dir/cloudsmith" ] } +@test "major channel: --version 1 installs the 1.x release in the manifest" { + build_fixture "$FIXTURE_DIR" "1.19.0" "$TEST_TARGET" + + run --separate-stderr "$INSTALL_SH" \ + --version 1 \ + --target "$TEST_TARGET" \ + --install-root "$INSTALL_ROOT" \ + --manifest-url "$FIXTURE_URL/manifest.txt" + + [ "$status" -eq 0 ] + [ "${lines[0]}" = "version=1.19.0" ] +} + +@test "major channel: a manifest outside the requested major version fails" { + build_fixture "$FIXTURE_DIR" "10.0.0" "$TEST_TARGET" + + run --separate-stderr "$INSTALL_SH" \ + --version 1 \ + --target "$TEST_TARGET" \ + --install-root "$INSTALL_ROOT" \ + --manifest-url "$FIXTURE_URL/manifest.txt" + + [ "$status" -ne 0 ] + [[ "$stderr" == *"manifest resolved '10.0.0', expected a 1.x release"* ]] +} + @test "--output-file writes the four result lines to a file and stdout stays empty" { build_fixture "$FIXTURE_DIR" "1.19.0" "$TEST_TARGET" local out_file="$BATS_TEST_TMPDIR/result.txt" From 88551f547e76b02bc3bc0d32ad7e67367d0660ba Mon Sep 17 00:00:00 2001 From: Ian Duffy Date: Wed, 18 Nov 2026 12:24:09 +0000 Subject: [PATCH 2/3] test(ENG-15913): check the default manifest URL of a major version The bats test records the URL that curl gets. The Pester tests call the new Get-DefaultManifestUrl function, which now builds the default manifest URL in install.ps1. Co-Authored-By: Claude Opus 5.5 --- install.ps1 | 18 +++++++++++++----- tests/Install.Tests.ps1 | 41 +++++++++++++++++++++++++++++++++++++++++ tests/install.bats | 20 ++++++++++++++++++++ 3 files changed, 74 insertions(+), 5 deletions(-) diff --git a/install.ps1 b/install.ps1 index 91fec71..12df492 100644 --- a/install.ps1 +++ b/install.ps1 @@ -197,6 +197,18 @@ function Invoke-HttpsDownload { } } +function Get-DefaultManifestUrl { + param( + [Parameter(Mandatory = $true)][string]$RequestedVersion, + [Parameter(Mandatory = $true)][string]$Target + ) + + if ($RequestedVersion -match '^[0-9]+\z') { + return "$DownloadBaseUrl/$Repository/raw/names/cloudsmith-cli-v$RequestedVersion-manifest-$Target/versions/latest/manifest.txt" + } + return "$DownloadBaseUrl/$Repository/raw/names/$ManifestNamePrefix-$Target/versions/$RequestedVersion/manifest.txt" +} + function Invoke-Download { param( [Parameter(Mandatory = $true)][string]$Uri, @@ -391,11 +403,7 @@ try { $manifestFile = Join-Path $script:WorkDir "manifest.txt" $isMajorVersion = $Version -match '^[0-9]+\z' if (-not $ManifestUrl) { - if ($isMajorVersion) { - $ManifestUrl = "$DownloadBaseUrl/$Repository/raw/names/cloudsmith-cli-v$Version-manifest-$resolvedTarget/versions/latest/manifest.txt" - } else { - $ManifestUrl = "$DownloadBaseUrl/$Repository/raw/names/$ManifestNamePrefix-$resolvedTarget/versions/$Version/manifest.txt" - } + $ManifestUrl = Get-DefaultManifestUrl -RequestedVersion $Version -Target $resolvedTarget } Write-InstallerLog "fetching release manifest" diff --git a/tests/Install.Tests.ps1 b/tests/Install.Tests.ps1 index 774f3de..17181e2 100644 --- a/tests/Install.Tests.ps1 +++ b/tests/Install.Tests.ps1 @@ -46,6 +46,47 @@ Describe 'Cloudsmith CLI installer request metadata' { } } +Describe 'Cloudsmith CLI installer manifest URL' { + + BeforeAll { + $installScriptPath = (Resolve-Path (Join-Path (Join-Path $PSScriptRoot '..') 'install.ps1')).ProviderPath + $tokens = $null + $errors = $null + $ast = [System.Management.Automation.Language.Parser]::ParseFile( + $installScriptPath, + [ref]$tokens, + [ref]$errors + ) + if ($errors.Count -gt 0) { + throw 'install.ps1 has parse errors' + } + + $urlFunction = $ast.Find({ + param($node) + $node -is [System.Management.Automation.Language.FunctionDefinitionAst] -and + $node.Name -eq 'Get-DefaultManifestUrl' + }, $true) + if (-not $urlFunction) { + throw 'unable to find Get-DefaultManifestUrl' + } + + $script:DownloadBaseUrl = 'https://dl.cloudsmith.io/public' + $script:ManifestNamePrefix = 'cloudsmith-cli-manifest' + $script:Repository = 'cloudsmith/cli' + . ([scriptblock]::Create($urlFunction.Extent.Text)) + } + + It 'uses the manifest of the major version channel for a major version' { + Get-DefaultManifestUrl -RequestedVersion '1' -Target 'windows-x86_64' | + Should -Be 'https://dl.cloudsmith.io/public/cloudsmith/cli/raw/names/cloudsmith-cli-v1-manifest-windows-x86_64/versions/latest/manifest.txt' + } + + It 'uses the version path of the latest channel for an exact version' { + Get-DefaultManifestUrl -RequestedVersion '1.2.3' -Target 'windows-x86_64' | + Should -Be 'https://dl.cloudsmith.io/public/cloudsmith/cli/raw/names/cloudsmith-cli-manifest-windows-x86_64/versions/1.2.3/manifest.txt' + } +} + Describe 'Cloudsmith CLI installer activation retry' { BeforeAll { diff --git a/tests/install.bats b/tests/install.bats index b13637a..0db8fb2 100644 --- a/tests/install.bats +++ b/tests/install.bats @@ -209,6 +209,26 @@ executable=$bin_dir/cloudsmith" [[ "$stderr" == *"manifest resolved '10.0.0', expected a 1.x release"* ]] } +@test "major channel: --version 1 requests the manifest of the 1.x channel" { + local stub_bin="$BATS_TEST_TMPDIR/bin" + mkdir -p "$stub_bin" + cat > "$stub_bin/curl" <<'STUB' +#!/usr/bin/env bash +for arg; do :; done +printf '%s\n' "$arg" > "$BATS_TEST_TMPDIR/requested-url" +exit 22 +STUB + chmod +x "$stub_bin/curl" + + run --separate-stderr env PATH="$stub_bin:$PATH" BATS_TEST_TMPDIR="$BATS_TEST_TMPDIR" "$INSTALL_SH" \ + --version 1 \ + --target "$TEST_TARGET" \ + --install-root "$INSTALL_ROOT" + + [ "$status" -ne 0 ] + [ "$(cat "$BATS_TEST_TMPDIR/requested-url")" = "https://dl.cloudsmith.io/public/cloudsmith/cli/raw/names/cloudsmith-cli-v1-manifest-$TEST_TARGET/versions/latest/manifest.txt" ] +} + @test "--output-file writes the four result lines to a file and stdout stays empty" { build_fixture "$FIXTURE_DIR" "1.19.0" "$TEST_TARGET" local out_file="$BATS_TEST_TMPDIR/result.txt" From b7d4f502c31161673efdfd29576df7220a088278 Mon Sep 17 00:00:00 2001 From: Ian Duffy Date: Wed, 18 Nov 2026 12:28:11 +0000 Subject: [PATCH 3/3] test(ENG-15913): match a short part of the major-version error Windows PowerShell wraps the error text of a native command, so the full message can break across lines. Co-Authored-By: Claude Opus 5.5 --- tests/Install.Tests.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Install.Tests.ps1 b/tests/Install.Tests.ps1 index 17181e2..348922f 100644 --- a/tests/Install.Tests.ps1 +++ b/tests/Install.Tests.ps1 @@ -407,7 +407,7 @@ Describe 'Cloudsmith CLI installer (install.ps1)' -Tag 'Windows' -Skip:(-not $sc ) $result.ExitCode | Should -Not -Be 0 - $result.StdErr | Should -Match "manifest resolved '10\.0\.0', expected a 1\.x release" + $result.StdErr | Should -Match 'expected a 1\.x release' } It 'writes exactly four lines to -OutputFile (UTF-8, no BOM) and leaves stdout empty' {