|
1 | 1 | $ErrorActionPreference = "Stop" |
2 | 2 |
|
3 | | -# Configuration |
4 | 3 | $Repo = "MichaelCurrin/auto-commit-msg" |
5 | 4 | $Binaries = @("acm", "gacm", "auto_commit_msg") |
6 | 5 | $InstallDir = "$HOME\AppData\Local\bin" |
7 | 6 |
|
8 | | -$ReleasesApiUrl = "https://api.github.com/repos/$Repo/releases" |
9 | | -$LatestRelease = Invoke-RestMethod -Uri $ReleasesApiUrl -UseBasicParsing | Select-Object -First 1 |
10 | | -if (-not $LatestRelease -or -not $LatestRelease.tag_name) { |
11 | | - throw "Could not determine latest release tag from $ReleasesApiUrl" |
12 | | -} |
13 | | - |
14 | | -$Tag = $LatestRelease.tag_name |
15 | | -Write-Host "Found latest tag: '$Tag'." |
16 | | -$RepoUrl = "https://github.com/$Repo/releases/download/$Tag" |
| 7 | +$RepoUrl = "https://github.com/$Repo/releases/latest/download" |
17 | 8 |
|
18 | | -# Ensure install directory exists |
| 9 | +# Ensure install directory exists. |
19 | 10 | if (!(Test-Path $InstallDir)) { |
20 | 11 | New-Item -ItemType Directory -Path $InstallDir | Out-Null |
21 | 12 | } |
22 | 13 |
|
23 | | -# Create a temporary workspace |
| 14 | +# Create a temporary workspace. |
24 | 15 | $TempDir = Join-Path $env:TEMP ([Guid]::NewGuid().ToString()) |
25 | 16 | New-Item -ItemType Directory -Path $TempDir | Out-Null |
26 | 17 |
|
|
40 | 31 | Move-Item -Path $TempPath -Destination $DestPath -Force |
41 | 32 | } |
42 | 33 |
|
43 | | - # Verify PATH |
| 34 | + # Verify PATH. |
44 | 35 | $UserPath = [Environment]::GetEnvironmentVariable("Path", "User") |
45 | 36 | if ($UserPath -notlike "*$InstallDir*") { |
46 | 37 | Write-Host "Adding $InstallDir to User PATH..." -ForegroundColor Cyan |
|
52 | 43 | Write-Host "Please restart your terminal to refresh the PATH." -ForegroundColor Yellow |
53 | 44 | } |
54 | 45 | finally { |
55 | | - # Cleanup |
| 46 | + # Cleanup. |
56 | 47 | if (Test-Path $TempDir) { |
57 | 48 | Remove-Item -Path $TempDir -Recurse -Force |
58 | 49 | } |
|
0 commit comments