#!/usr/bin/env pwsh # Update act_runner to latest release from Gitea # Usage: ./update_act_runner.ps1 [-Force] param( [switch]$Force, [string]$Arch = "windows-amd64", [string]$ExeName = "act_runner.exe" ) $ErrorActionPreference = 'Stop' $API = "https://gitea.com/api/v1/repos/gitea/act_runner/releases/latest" $ExePath = Join-Path $PSScriptRoot $ExeName function Get-CurrentVersion { if (-not (Test-Path $ExePath)) { return $null } $out = & $ExePath --version 2>&1 | Select-Object -First 1 if ($out -match '(\d+\.\d+\.\d+)') { return $matches[1] } return $null } # Fetch latest release info Write-Host "Fetching latest release info..." -ForegroundColor Cyan $release = Invoke-RestMethod -Uri $API $tag = $release.tag_name -replace '^v', '' $currentVersion = Get-CurrentVersion Write-Host "Latest: $tag | Current: $($currentVersion ?? 'not installed')" if ($currentVersion -eq $tag -and -not $Force) { Write-Host "Already up to date." -ForegroundColor Green exit 0 } # Find the right asset $pattern = "act_runner-.*-$Arch\.exe$" $asset = $release.assets | Where-Object { $_.name -match $pattern } | Select-Object -First 1 if (-not $asset) { Write-Error "No asset found matching pattern: $pattern" exit 1 } $downloadUrl = $asset.browser_download_url Write-Host "Downloading $($asset.name)..." -ForegroundColor Cyan # Download to temp then move $tmpFile = Join-Path $PSScriptRoot "act_runner.tmp.exe" Invoke-WebRequest -Uri $downloadUrl -OutFile $tmpFile -UseBasicParsing # Stop running instance if any $running = Get-Process | Where-Object { $_.Path -eq $ExePath } | Select-Object -First 1 if ($running) { Write-Host "Stopping running act_runner (PID $($running.Id))..." -ForegroundColor Yellow Stop-Process -Id $running.Id -Force Start-Sleep -Milliseconds 500 } # Replace Move-Item -Path $tmpFile -Destination $ExePath -Force Write-Host "Updated to $tag" -ForegroundColor Green