Skip to content
Open
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
9 changes: 9 additions & 0 deletions .github/workflows/release-build-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ on:
- ".goreleaser.yml"
- "Makefile"
- "scripts/verify-package-render.sh"
- "scripts/test-chocolatey-install.ps1"
- "packaging/**"
- ".github/workflows/auto-release.yml"
- ".github/workflows/release.yml"
Expand Down Expand Up @@ -39,3 +40,11 @@ jobs:
run: goreleaser check
- name: Build and verify release snapshot
run: make snapshot

chocolatey-architecture-check:
runs-on: windows-latest
steps:
- uses: actions/checkout@v4
- name: Test Chocolatey architecture bindings
shell: pwsh
run: ./scripts/test-chocolatey-install.ps1
13 changes: 6 additions & 7 deletions packaging/chocolatey/tools/chocolateyInstall.ps1
Original file line number Diff line number Diff line change
@@ -1,27 +1,26 @@
$ErrorActionPreference = 'Stop'

$version = $env:ChocolateyPackageVersion
$toolsDir = Split-Path -Parent $MyInvocation.MyCommand.Definition

# Checksums injected by the release workflow - DO NOT EDIT MANUALLY
# URLs and checksums injected by the release workflow - DO NOT EDIT MANUALLY
$urlAmd64 = 'URL_AMD64_PLACEHOLDER'
$urlArm64 = 'URL_ARM64_PLACEHOLDER'
$checksumAmd64 = 'CHECKSUM_AMD64_PLACEHOLDER'
$checksumArm64 = 'CHECKSUM_ARM64_PLACEHOLDER'

if ($env:PROCESSOR_ARCHITECTURE -eq 'ARM64') {
$arch = 'arm64'
$url = $urlArm64
$checksum = $checksumArm64
} elseif ([Environment]::Is64BitOperatingSystem) {
$arch = 'amd64'
$url = $urlAmd64
$checksum = $checksumAmd64
} else {
throw "32-bit Windows is not supported. sptfy requires 64-bit Windows."
}

$baseUrl = "https://github.com/open-cli-collective/spotify-cli/releases/download/v${version}"
$zipFile = "sptfy_v${version}_windows_${arch}.zip"
$url = "${baseUrl}/${zipFile}"

Write-Host "Installing sptfy ${version} for Windows ${arch}..."
Write-Host "Installing sptfy for Windows ${arch}..."
Install-ChocolateyZipPackage -PackageName $env:ChocolateyPackageName `
-Url $url `
-UnzipLocation $toolsDir `
Expand Down
66 changes: 66 additions & 0 deletions scripts/test-chocolatey-install.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
$ErrorActionPreference = 'Stop'

$templatePath = Join-Path $PSScriptRoot '..\packaging\chocolatey\tools\chocolateyInstall.ps1'
$tempRoot = $env:RUNNER_TEMP
if (-not $tempRoot) { $tempRoot = [IO.Path]::GetTempPath() }
$renderedPath = Join-Path $tempRoot "spotify-chocolatey-$([guid]::NewGuid()).ps1"

$amd64Url = 'https://example.invalid/sptfy-amd64.zip'
$arm64Url = 'https://example.invalid/sptfy-arm64.zip'
$amd64Checksum = '0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef'
$arm64Checksum = 'fedcba9876543210fedcba9876543210fedcba9876543210fedcba9876543210'
$rendered = Get-Content $templatePath -Raw
$rendered = $rendered.Replace('URL_AMD64_PLACEHOLDER', $amd64Url)
$rendered = $rendered.Replace('URL_ARM64_PLACEHOLDER', $arm64Url)
$rendered = $rendered.Replace('CHECKSUM_AMD64_PLACEHOLDER', $amd64Checksum)
$rendered = $rendered.Replace('CHECKSUM_ARM64_PLACEHOLDER', $arm64Checksum)

if ($rendered -match 'URL_.*_PLACEHOLDER|CHECKSUM_.*_PLACEHOLDER') {
throw 'Rendered Chocolatey installer still contains a placeholder'
}
Set-Content $renderedPath $rendered

function Install-ChocolateyZipPackage {
param(
[string]$PackageName,
[string]$Url,
[string]$UnzipLocation,
[string]$Checksum,
[string]$ChecksumType
)
$global:capturedInstall = [pscustomobject]@{
Url = $Url
Checksum = $Checksum
ChecksumType = $ChecksumType
}
}

$env:ChocolateyPackageName = 'spotify-cli'
$architectures = @(
[pscustomobject]@{ Name = 'AMD64'; Environment = 'AMD64'; Url = $amd64Url; Checksum = $amd64Checksum },
[pscustomobject]@{ Name = 'ARM64'; Environment = 'ARM64'; Url = $arm64Url; Checksum = $arm64Checksum }
)

foreach ($architecture in $architectures) {
$previousArchitecture = $env:PROCESSOR_ARCHITECTURE
try {
$env:PROCESSOR_ARCHITECTURE = $architecture.Environment
$global:capturedInstall = $null
. $renderedPath
} finally {
$env:PROCESSOR_ARCHITECTURE = $previousArchitecture
}

if (-not $global:capturedInstall) { throw "$($architecture.Name) did not call Install-ChocolateyZipPackage" }
if ($global:capturedInstall.Url -ne $architecture.Url) {
throw "$($architecture.Name) selected URL '$($global:capturedInstall.Url)', expected '$($architecture.Url)'"
}
if ($global:capturedInstall.Checksum -ne $architecture.Checksum) {
throw "$($architecture.Name) selected checksum '$($global:capturedInstall.Checksum)', expected '$($architecture.Checksum)'"
}
if ($global:capturedInstall.ChecksumType -ne 'sha256') {
throw "$($architecture.Name) selected checksum type '$($global:capturedInstall.ChecksumType)', expected 'sha256'"
}
}

Write-Host 'Chocolatey AMD64/ARM64 URL and checksum bindings passed.'
4 changes: 2 additions & 2 deletions scripts/verify-package-render.sh
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ require_text "sptfy_v0.0.0_windows_arm64.zip" packaging/winget/OpenCLICollective
require_file packaging/chocolatey/spotify-cli.nuspec
require_file packaging/chocolatey/tools/chocolateyInstall.ps1
require_text "<id>spotify-cli</id>" packaging/chocolatey/spotify-cli.nuspec
require_text 'releases/download/v${version}' packaging/chocolatey/tools/chocolateyInstall.ps1
require_text 'sptfy_v${version}_windows_${arch}.zip' packaging/chocolatey/tools/chocolateyInstall.ps1
require_text 'URL_AMD64_PLACEHOLDER' packaging/chocolatey/tools/chocolateyInstall.ps1
require_text 'URL_ARM64_PLACEHOLDER' packaging/chocolatey/tools/chocolateyInstall.ps1

require_text 'homebrew-tap-token: ${{ secrets.TAP_GITHUB_TOKEN }}' .github/workflows/release.yml
require_text 'chocolatey-api-key: ${{ secrets.CHOCOLATEY_API_KEY }}' .github/workflows/release.yml
Expand Down
Loading