From f73ebd2a6fba6e5465289aaab46c30925a5adfa0 Mon Sep 17 00:00:00 2001 From: Braden Hilton Date: Sat, 25 May 2024 16:39:01 +0100 Subject: [PATCH 1/2] fix: fix error when determining GOARCH in install.ps1 --- assets/scripts/install.ps1 | 67 ++++++++++++++++++++------------------ 1 file changed, 36 insertions(+), 31 deletions(-) diff --git a/assets/scripts/install.ps1 b/assets/scripts/install.ps1 index 7f22989e2ef..e66da29dc06 100644 --- a/assets/scripts/install.ps1 +++ b/assets/scripts/install.ps1 @@ -45,9 +45,14 @@ param ( $ChezmoiArgs ) -function Write-DebugVariable ($variable) { - $debugVariable = Get-Variable -Name $variable - Write-Debug "$( $debugVariable.Name ): $( $debugVariable.Value )" +function Write-DebugVariable { + param ( + [string[]]$variables + ) + foreach ($variable in $variables) { + $debugVariable = Get-Variable -Name $variable + Write-Debug "$( $debugVariable.Name ): $( $debugVariable.Value )" + } } function Invoke-CleanUp ($directory) { @@ -83,29 +88,38 @@ function Get-GoOS { if ($isOSPlatform.Invoke($osPlatform::Windows)) { return 'windows' } if ($isOSPlatform.Invoke($osPlatform::Linux)) { return 'linux' } if ($isOSPlatform.Invoke($osPlatform::OSX)) { return 'darwin' } + + Write-Error 'unable to determine GOOS' } function Get-GoArch { $goArch = @{ - 'Arm' = 'arm' - 'Arm64' = 'arm64' - 'X86' = 'i386' - 'X64' = 'amd64' + '32-bit' = 'i386' + '64-bit' = 'amd64' + 'Arm' = 'arm' + 'Arm64' = 'arm64' + 'X86' = 'i386' + 'X64' = 'amd64' } - $arch = [System.Runtime.InteropServices.RuntimeInformation]::OSArchitecture.ToString() + $arch = $null - if ((-not $arch) -and [System.Environment]::Is64BitOperatingSystem) { - $arch = 'X64' + if ($PSVersionTable.PSEdition -eq 'Desktop') { + $arch = (Get-CimInstance -Class Win32_OperatingSystem).OSArchitecture + } else { + $arch = [System.Runtime.InteropServices.RuntimeInformation]::OSArchitecture.ToString() + + if ([string]::IsNullOrEmpty($arch)) { + $arch = if ([System.Environment]::Is64BitOperatingSystem) { + 'X64' + } else { + 'X86' + } + } } - if (-not $arch) { - $cimArch = (Get-CimInstance -Class Win32_OperatingSystem).OSArchitecture - if ($cimArch.StartsWith('32')) { - $arch = 'X86' - } else { - $arch = 'X64' - } + if ([string]::IsNullOrEmpty($arch)) { + Write-Error 'unable to determine GOARCH' } return $goArch[$arch] @@ -175,8 +189,7 @@ function Expand-ChezmoiArchive ($path) { } } -# some functions require fetching of non-existent properties to not error -Set-StrictMode -Off +Set-StrictMode -Version 3.0 [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls12 @@ -202,9 +215,7 @@ do { } while (Test-Path -Path $tempDir) New-Item -ItemType Directory -Path $tempDir | Out-Null -foreach ($variableName in @('BinDir', 'Tag', 'ChezmoiArgs', 'tempDir')) { - Write-DebugVariable $variableName -} +Write-DebugVariable 'BinDir', 'Tag', 'ChezmoiArgs', 'tempDir' $goOS = Get-GoOS $goArch = Get-GoArch @@ -230,15 +241,11 @@ switch ($goOS) { break } } -foreach ($variableName in @('binarySuffix', 'archiveFormat', 'goOSExtra')) { - Write-DebugVariable $variableName -} +Write-DebugVariable 'binarySuffix', 'archiveFormat', 'goOSExtra' $archiveFilename = "chezmoi_${version}_${goOS}${goOSExtra}_${goArch}.${archiveFormat}" $tempArchivePath = Join-Path -Path $tempDir -ChildPath $archiveFilename -foreach ($variableName in @('archiveFilename', 'tempArchivePath')) { - Write-DebugVariable $variableName -} +Write-DebugVariable 'archiveFilename', 'tempArchivePath' Invoke-FileDownload "${BaseUrl}/download/${realTag}/${archiveFilename}" $tempArchivePath $checksums = Get-Checksums $realTag $version @@ -248,9 +255,7 @@ Expand-ChezmoiArchive $tempArchivePath $binaryFilename = "chezmoi${binarySuffix}" $tempBinaryPath = Join-Path -Path $tempDir -ChildPath $binaryFilename -foreach ($variableName in @('binaryFilename', 'tempBinaryPath')) { - Write-DebugVariable $variableName -} +Write-DebugVariable 'binaryFilename', 'tempBinaryPath' [System.IO.Directory]::CreateDirectory($BinDir) | Out-Null $binary = Join-Path -Path $BinDir -ChildPath $binaryFilename Write-DebugVariable 'binary' From 24dfb01b0e127086a23f56ae661eec0b20e9763b Mon Sep 17 00:00:00 2001 From: Braden Hilton Date: Sat, 25 May 2024 16:41:53 +0100 Subject: [PATCH 2/2] chore: run install.ps1 on both powershell and pwsh --- .github/workflows/installer.yml | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/.github/workflows/installer.yml b/.github/workflows/installer.yml index 50a18cdcee0..161fde163ca 100644 --- a/.github/workflows/installer.yml +++ b/.github/workflows/installer.yml @@ -75,15 +75,29 @@ jobs: BINARY: ${{ matrix.os == 'windows-2022' && 'bin/chezmoi.exe' || 'bin/chezmoi' }} steps: - uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 - - name: test-${{ matrix.os }}-local + - name: test-${{ matrix.os }}-local-pwsh shell: pwsh run: | if (Test-Path -Path ${{ env.BINARY }}) { Remove-Item -Force ${{ env.BINARY }} } assets/scripts/install.ps1 -d ${{ env.BINARY }} --version - - name: test-${{ matrix.os }}-url + - name: test-${{ matrix.os }}-local-powershell + if: matrix.os == 'windows-2022' + shell: powershell + run: | + if (Test-Path -Path ${{ env.BINARY }}) { Remove-Item -Force ${{ env.BINARY }} } + assets/scripts/install.ps1 -d + ${{ env.BINARY }} --version + - name: test-${{ matrix.os }}-url-pwsh shell: pwsh run: | if (Test-Path -Path ${{ env.BINARY }}) { Remove-Item -Force ${{ env.BINARY }} } iex "&{$(irm 'https://raw.githubusercontent.com/twpayne/chezmoi/${{ env.SHA }}/assets/scripts/install.ps1')} -d" ${{ env.BINARY }} --version + - name: test-${{ matrix.os }}-url-powershell + if: matrix.os == 'windows-2022' + shell: powershell + run: | + if (Test-Path -Path ${{ env.BINARY }}) { Remove-Item -Force ${{ env.BINARY }} } + iex "&{$(irm 'https://raw.githubusercontent.com/twpayne/chezmoi/${{ env.SHA }}/assets/scripts/install.ps1')} -d" + ${{ env.BINARY }} --version