Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 9 additions & 14 deletions install.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ param(
),
[string]$Target = $env:CLOUDSMITH_CLI_TARGET,
[string]$OutputFile = $env:CLOUDSMITH_CLI_OUTPUT_FILE,
[string]$Repository = $(if ($env:CLOUDSMITH_CLI_REPOSITORY) { $env:CLOUDSMITH_CLI_REPOSITORY } else { "cloudsmith/cli-standalone" }),
# TODO: revert to the production repository before release.
[string]$Repository = $(if ($env:CLOUDSMITH_CLI_REPOSITORY) { $env:CLOUDSMITH_CLI_REPOSITORY } else { "bart-demo-org-terraform/cli-binary-release-test" }),
Comment thread
BartoszBlizniak marked this conversation as resolved.
[string]$ManifestUrl = $env:CLOUDSMITH_CLI_MANIFEST_URL,
[switch]$Force
)
Expand Down Expand Up @@ -265,7 +266,7 @@ function Test-CloudsmithExecutable {
return $true
}

function Test-ZipEntries {
function Test-ZipArchive {
param([Parameter(Mandatory = $true)][string]$Archive)

Add-Type -AssemblyName System.IO.Compression.FileSystem
Expand Down Expand Up @@ -307,7 +308,7 @@ function Write-InstallResult {
if ($OutputFile) {
$parent = Split-Path -Parent $OutputFile
if ($parent) {
New-LiteralDirectory -Path $parent
[void][System.IO.Directory]::CreateDirectory($parent)
}
$utf8WithoutBom = New-Object System.Text.UTF8Encoding($false)
[IO.File]::WriteAllLines($OutputFile, $lines, $utf8WithoutBom)
Expand All @@ -317,12 +318,6 @@ function Write-InstallResult {
}
}

function New-LiteralDirectory {
param([Parameter(Mandatory = $true)][string]$Path)

[void][System.IO.Directory]::CreateDirectory($Path)
}

try {
if ($Version -notmatch '^[A-Za-z0-9._+-]+$' -or $Version -eq '.' -or $Version -eq '..') {
throw "install.ps1: invalid version: $Version"
Expand All @@ -338,9 +333,9 @@ try {
Write-InstallerLog "detected target $resolvedTarget"

$temporaryRoot = Join-Path $InstallRoot ".tmp"
New-LiteralDirectory -Path $temporaryRoot
[void][System.IO.Directory]::CreateDirectory($temporaryRoot)
$script:WorkDir = Join-Path $temporaryRoot ([Guid]::NewGuid().ToString("N"))
New-LiteralDirectory -Path $script:WorkDir
[void][System.IO.Directory]::CreateDirectory($script:WorkDir)

$manifestFile = Join-Path $script:WorkDir "manifest.txt"
if (-not $ManifestUrl) {
Expand Down Expand Up @@ -381,7 +376,7 @@ try {
$binDirectory = Join-Path $finalParent "cloudsmith"
$executable = Join-Path $binDirectory "cloudsmith.exe"
$metadataFile = Join-Path $binDirectory ".cloudsmith-installation"
New-LiteralDirectory -Path $finalParent
[void][System.IO.Directory]::CreateDirectory($finalParent)

$lockPath = Join-Path $finalParent ".install.lock"
$deadline = [DateTime]::UtcNow.AddSeconds(120)
Expand Down Expand Up @@ -426,10 +421,10 @@ try {
if (-not $archiveName.EndsWith('.zip', [StringComparison]::OrdinalIgnoreCase)) {
throw "install.ps1: unsupported archive format: $archiveName"
}
Test-ZipEntries -Archive $archiveFile
Test-ZipArchive -Archive $archiveFile

$extractDirectory = Join-Path $script:WorkDir "extract"
New-LiteralDirectory -Path $extractDirectory
[void][System.IO.Directory]::CreateDirectory($extractDirectory)
[System.IO.Compression.ZipFile]::ExtractToDirectory($archiveFile, $extractDirectory)

$stagedDirectory = Join-Path $extractDirectory "cloudsmith"
Expand Down
3 changes: 2 additions & 1 deletion install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ PROGRAM="install.sh"
# Where releases are downloaded from. Flags and CLOUDSMITH_CLI_* environment
# variables override the defaults; --manifest-url bypasses URL construction.
DOWNLOAD_BASE_URL="https://dl.cloudsmith.io/public"
DEFAULT_REPOSITORY="cloudsmith/cli-standalone"
# TODO: revert to the production repository before release.
DEFAULT_REPOSITORY="bart-demo-org-terraform/cli-binary-release-test"
Comment thread
BartoszBlizniak marked this conversation as resolved.
MANIFEST_NAME_PREFIX="cloudsmith-cli-manifest"

REPOSITORY="${CLOUDSMITH_CLI_REPOSITORY:-$DEFAULT_REPOSITORY}"
Expand Down
5 changes: 5 additions & 0 deletions tests/detect_target.bats
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,11 @@ write_ldd_stub() {
}

@test "linux/x86_64 with glibc (getconf) is detected as linux-x86_64-gnu" {
# The real filesystem probe (/etc/alpine-release, ld-musl) answers before the
# getconf stub can, so this scenario is untestable on a musl host.
if [ -f /etc/alpine-release ] || ls /lib/ld-musl-*.so.1 >/dev/null 2>&1; then
skip "musl host: filesystem probe wins over the getconf stub"
fi
write_uname_stub Linux x86_64
write_getconf_stub gnu

Expand Down
6 changes: 3 additions & 3 deletions tests/install.bats
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ make_path_without_curl() {
mkdir -p "$bin"

local cmd path
for cmd in sh mkdir mktemp rm rmdir awk tr tar chmod mv dirname grep cp sha256sum shasum openssl sleep; do
for cmd in sh mkdir mktemp rm rmdir awk tr tar gzip gunzip cat chmod mv dirname grep cp sha256sum shasum openssl sleep; do
path="$(command -v "$cmd" 2>/dev/null || true)"
if [ -n "$path" ] && [ ! -e "$bin/$cmd" ]; then
ln -s "$path" "$bin/$cmd"
Expand Down Expand Up @@ -92,7 +92,7 @@ executable=$bin_dir/cloudsmith"

run "$bin_dir/cloudsmith" --version
[ "$status" -eq 0 ]
[ "$output" = "cloudsmith 1.19.0" ]
[[ "$output" == *"CLI Package Version: 1.19.0"* ]]
}

@test "--help prints usage with HOME and XDG_DATA_HOME unset" {
Expand Down Expand Up @@ -630,5 +630,5 @@ executable=$bin_dir/cloudsmith"
[ -x "$bin" ]
run "$bin" --version
[ "$status" -eq 0 ]
[ "$output" = "cloudsmith 1.19.0" ]
[[ "$output" == *"CLI Package Version: 1.19.0"* ]]
}
Loading