Files
solution-erp/scripts/setup-gitea-runner.ps1
pqhuy1987 169e268b28
Some checks failed
Deploy SOLUTION_ERP / build-backend (push) Failing after 9s
Deploy SOLUTION_ERP / build-fe-admin (push) Has been cancelled
Deploy SOLUTION_ERP / build-fe-user (push) Has been cancelled
Deploy SOLUTION_ERP / deploy-iis (push) Has been cancelled
[CLAUDE] Scripts: rewrite 4 deploy PS1 ASCII-only for PS 5.1 compat
PowerShell 5.1 reads .ps1 files as locale codepage (not UTF-8 no BOM),
which corrupts multi-byte Vietnamese chars and breaks parsing. Rewrote
setup-iis-sites.ps1, setup-ssl.ps1, setup-gitea-runner.ps1, deploy-all.ps1
as ASCII-only. Also renamed $Host param to $HostName in Ensure-Site to
avoid collision with PowerShell built-in $Host automatic variable.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-21 14:17:36 +07:00

79 lines
3.0 KiB
PowerShell

# Register Gitea Actions runner on VPS Windows Server.
# Can be shared with VIETREPORT (runner serves multiple repos via labels).
#
# Usage (admin PowerShell):
# .\setup-gitea-runner.ps1 -RegistrationToken 'xxxx' -RunnerName 'vps-win-01'
#
# Get RegistrationToken from:
# https://git.baocaogiaoduc.vn/-/admin/actions/runners (admin only)
# or per-repo: https://git.baocaogiaoduc.vn/vietreport-admin/solution-erp/settings/actions/runners
param(
[Parameter(Mandatory=$true)] [string]$RegistrationToken,
[string]$RunnerName = "vps-win-$(Get-Date -Format 'yyyyMMdd')",
[string]$InstallDir = "C:\gitea-runner",
[string]$GiteaUrl = "https://git.baocaogiaoduc.vn",
[string]$Labels = "windows-latest,self-hosted,windows,x64"
)
$ErrorActionPreference = 'Stop'
# ===================== 1. Download runner =====================
$RunnerExe = Join-Path $InstallDir "act_runner.exe"
if (-not (Test-Path $RunnerExe)) {
Write-Host "==> Download Gitea act_runner" -ForegroundColor Cyan
if (-not (Test-Path $InstallDir)) { New-Item -ItemType Directory -Force -Path $InstallDir | Out-Null }
# Latest release from Gitea CDN
$url = "https://dl.gitea.com/act_runner/act_runner-windows-amd64.exe"
Invoke-WebRequest -Uri $url -OutFile $RunnerExe -UseBasicParsing
Write-Host " Downloaded $RunnerExe"
}
# ===================== 2. Register =====================
Set-Location $InstallDir
if (-not (Test-Path (Join-Path $InstallDir ".runner"))) {
Write-Host ""
Write-Host "==> Register with Gitea $GiteaUrl" -ForegroundColor Cyan
& $RunnerExe register `
--no-interactive `
--instance $GiteaUrl `
--token $RegistrationToken `
--name $RunnerName `
--labels $Labels
if ($LASTEXITCODE -ne 0) {
Write-Error "Register fail. Check: token correct? GiteaUrl reachable? Runner name '$RunnerName' already used?"
exit 1
}
Write-Host " Registered as '$RunnerName'"
} else {
Write-Host " Runner already registered (.runner file exists)"
}
# ===================== 3. Install as Windows service =====================
$ServiceName = "gitea-runner"
$svc = Get-Service -Name $ServiceName -ErrorAction SilentlyContinue
if (-not $svc) {
Write-Host ""
Write-Host "==> Install Windows service" -ForegroundColor Cyan
# act_runner has no built-in service install - use sc.exe
sc.exe create $ServiceName binPath= "`"$RunnerExe`" daemon --config `"$InstallDir\config.yml`"" start= auto DisplayName= "Gitea Actions Runner"
Start-Service $ServiceName
Write-Host " Service '$ServiceName' installed + started"
} else {
if ($svc.Status -ne 'Running') {
Start-Service $ServiceName
Write-Host " Service started"
} else {
Write-Host " Service already running"
}
}
Write-Host ""
Write-Host "[OK] Runner setup DONE" -ForegroundColor Green
Write-Host " Check on Gitea: $GiteaUrl/-/admin/actions/runners (admin) or repo settings > Actions > Runners"
Write-Host " Labels: $Labels"
Write-Host " Log: Get-Content '$InstallDir\log.txt' -Tail 50 -Wait"