diff --git a/.goreleaser.yml b/.goreleaser.yml index 0654193..290d214 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -16,6 +16,7 @@ builds: goos: - linux - darwin # macOS + - windows goarch: - amd64 # For Intel/AMD processors - arm64 # For Apple Silicon and other ARM processors @@ -29,4 +30,14 @@ archives: # Files to include in the archive along with the binary. files: - LICENSE - - README.md \ No newline at end of file + - README.md + + # zip format to support installation for windows + - format: zip + name_template: >- + {{ .ProjectName }}_{{ .Version }}_{{ .Os }}_{{ .Arch }} + files: + - LICENSE + - README.md + replacements: + windows: windows \ No newline at end of file diff --git a/install.ps1 b/install.ps1 new file mode 100644 index 0000000..20c6d6c --- /dev/null +++ b/install.ps1 @@ -0,0 +1,59 @@ +# GitX Windows Installer Script +# Usage: Invoke-WebRequest -Uri "https://raw.githubusercontent.com/gitxtui/gitx/master/install.ps1" -OutFile "install.ps1"; .\install.ps1 + +$repo = "gitxtui/gitx" +$installDir = "$env:ProgramFiles\gitx" + +function Get-Arch { + switch ($env:PROCESSOR_ARCHITECTURE) { + "AMD64" { return "amd64" } + "ARM64" { return "arm64" } + default { Write-Error "Unsupported architecture: $($env:PROCESSOR_ARCHITECTURE)"; exit 1 } + } +} + +function Get-LatestRelease { + $apiUrl = "https://api.github.com/repos/$repo/releases" + $response = Invoke-RestMethod -Uri $apiUrl + if ($response -is [System.Collections.IEnumerable] -and $response.Count -gt 0) { + return $response[0].tag_name + } else { + Write-Error "Could not find any release version for $repo." + exit 1 + } +} + +function Main { + $os = "windows" + $arch = Get-Arch + $version = Get-LatestRelease + $versionNum = $version -replace "^v", "" + $filename = "gitx_${versionNum}_${os}_${arch}.zip" + $downloadUrl = "https://github.com/$repo/releases/download/$version/$filename" + + Write-Host "Downloading gitx $version for $os/$arch..." + $tempDir = New-TemporaryFile | Split-Path + $zipPath = Join-Path $tempDir $filename + Invoke-WebRequest -Uri $downloadUrl -OutFile $zipPath + + Write-Host "Extracting..." + Expand-Archive -Path $zipPath -DestinationPath $tempDir + + if (!(Test-Path $installDir)) { + New-Item -ItemType Directory -Path $installDir | Out-Null + } + + $gitxExe = Get-ChildItem -Path $tempDir -Filter "gitx.exe" -Recurse | Select-Object -First 1 + if ($null -eq $gitxExe) { + Write-Error "gitx.exe not found in the archive." + exit 1 + } + + Copy-Item -Path $gitxExe.FullName -Destination (Join-Path $installDir "gitx.exe") -Force + + Write-Host "`ngitx has been installed to $installDir" + Write-Host "Add $installDir to your PATH if not already present." + Write-Host "Run 'gitx.exe' to get started." +} + +Main \ No newline at end of file