From 323e1853a672607f5265732aeb8fda14f534b6ae Mon Sep 17 00:00:00 2001 From: Austin Smith Date: Tue, 4 Aug 2026 08:28:27 -0700 Subject: [PATCH] fix windows installer entrypoint --- .github/workflows/release.yml | 26 ++++++++++++++++---------- packaging/standalone/install.ps1 | 6 +++++- test/installer-windows.tests.ps1 | 17 ++++++++++++++++- test/release-workflow.test.ts | 19 +++++++++++++++++++ 4 files changed, 56 insertions(+), 12 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index e60479a..ca36b82 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -479,20 +479,26 @@ jobs: SPOTUIFY_VERSION: ${{ needs.validate.outputs.version }} run: | $env:SPOTUIFY_INSTALL_DIR = Join-Path $env:RUNNER_TEMP 'spotuify' - $installerSource = $null + $installCommand = @' + Invoke-RestMethod -Uri 'https://crapshack.net/spotuify/install.ps1' -UseBasicParsing -TimeoutSec 60 | Invoke-Expression + '@ + $installed = $false for ($attempt = 1; $attempt -le 5; $attempt++) { - try { - $installerSource = Invoke-RestMethod ` - -Uri 'https://crapshack.net/spotuify/install.ps1' ` - -UseBasicParsing ` - -TimeoutSec 60 + & powershell.exe ` + -NoLogo ` + -NoProfile ` + -NonInteractive ` + -ExecutionPolicy Bypass ` + -Command $installCommand + if ($LASTEXITCODE -eq 0) { + $installed = $true break - } catch { - if ($attempt -eq 5) { throw } - Start-Sleep -Seconds (2 * $attempt) } + if ($attempt -lt 5) { Start-Sleep -Seconds (2 * $attempt) } + } + if (-not $installed) { + throw 'Spotuify public installer failed after 5 attempts.' } - $installerSource | Invoke-Expression $binDirectory = Join-Path $env:SPOTUIFY_INSTALL_DIR 'bin' $mainVersion = & (Join-Path $binDirectory 'spotuify.exe') --version $currentRelease = (Get-Content -LiteralPath (Join-Path $env:SPOTUIFY_INSTALL_DIR 'current') -Raw).Trim() diff --git a/packaging/standalone/install.ps1 b/packaging/standalone/install.ps1 index 7f9073a..c3e4fdc 100644 --- a/packaging/standalone/install.ps1 +++ b/packaging/standalone/install.ps1 @@ -1,5 +1,9 @@ #Requires -Version 5.1 +param( + [switch]$LoadOnly +) + Set-StrictMode -Version Latest $ErrorActionPreference = 'Stop' $ProgressPreference = 'SilentlyContinue' @@ -831,7 +835,7 @@ function Install-Spotuify { } } -if ($MyInvocation.InvocationName -ne '.') { +if (-not $LoadOnly) { try { Install-Spotuify } catch { diff --git a/test/installer-windows.tests.ps1 b/test/installer-windows.tests.ps1 index a6a73b0..debf6c8 100644 --- a/test/installer-windows.tests.ps1 +++ b/test/installer-windows.tests.ps1 @@ -6,7 +6,7 @@ $ProgressPreference = 'SilentlyContinue' $repositoryRoot = Split-Path -Parent $PSScriptRoot $installerPath = Join-Path $repositoryRoot 'packaging/standalone/install.ps1' -. $installerPath +. $installerPath -LoadOnly $testRoot = Join-Path ([IO.Path]::GetTempPath()) ("spotuify-installer-tests-$([guid]::NewGuid().ToString('N'))") $script:FixtureManifest = $null @@ -572,6 +572,21 @@ try { } } + Invoke-Test 'runs the entrypoint when evaluated from a dot-sourced scope' { + $installerSource = Get-Content -LiteralPath $installerPath -Raw + $previousVersion = $env:SPOTUIFY_VERSION + try { + $env:SPOTUIFY_VERSION = 'invalid' + Assert-Throws { + . { + $installerSource | Invoke-Expression + } + } 'SPOTUIFY_VERSION must be latest or a stable version' + } finally { + [Environment]::SetEnvironmentVariable('SPOTUIFY_VERSION', $previousVersion, 'Process') + } + } + Write-Host 'All Spotuify Windows installer tests passed.' } catch { $testFailure = $_ diff --git a/test/release-workflow.test.ts b/test/release-workflow.test.ts index 72798d8..d7c105f 100644 --- a/test/release-workflow.test.ts +++ b/test/release-workflow.test.ts @@ -29,6 +29,13 @@ describe("release workflow", () => { test("publishes standalone installers and verifies the crapshack endpoints", async () => { const source = await Bun.file(WORKFLOW_PATH).text(); + const workflow = Bun.YAML.parse(source) as { + jobs?: { + "public-installer-smoke"?: { + steps?: Array<{ if?: string; run?: string }>; + }; + }; + }; expect(source).toContain( "install -m 0755 packaging/standalone/install.sh dist/install.sh", @@ -41,5 +48,17 @@ describe("release workflow", () => { ); expect(source).toContain("https://crapshack.net/spotuify/install.sh"); expect(source).toContain("https://crapshack.net/spotuify/install.ps1"); + + const windowsSmoke = workflow.jobs?.["public-installer-smoke"]?.steps?.find( + (step) => step.if === "matrix.kind == 'windows'", + ); + expect(windowsSmoke?.run).toContain("& powershell.exe"); + expect(windowsSmoke?.run).toContain("-Command $installCommand"); + expect(windowsSmoke?.run).toContain( + "Invoke-RestMethod -Uri 'https://crapshack.net/spotuify/install.ps1' -UseBasicParsing -TimeoutSec 60 | Invoke-Expression", + ); + expect(windowsSmoke?.run).not.toContain( + "$installerSource | Invoke-Expression", + ); }); });