Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fix error when determining GOARCH in install.ps1 #3751

Merged
merged 2 commits into from
May 25, 2024
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
18 changes: 16 additions & 2 deletions .github/workflows/installer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
67 changes: 36 additions & 31 deletions assets/scripts/install.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -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

Expand All @@ -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
Expand All @@ -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
Expand All @@ -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'
Expand Down
Loading