143 lines
7.4 KiB
PowerShell
143 lines
7.4 KiB
PowerShell
# Подготовка Windows-раннера Gitea Actions для сборки BiLauncher.
|
||||
|
|
#
|
|||
|
|
# Qt (C:\Qt\6.11.1\msvc2022_64 с WebEngine), CMake и Ninja (C:\Qt\Tools) ставятся
|
|||
|
|
# заранее через Qt Online Installer — скрипт их не трогает, а докачивает только то,
|
|||
|
|
# чего Qt не даёт: компилятор MSVC, git, Node.js (для actions/checkout), Inno Setup
|
|||
|
|
# и сам gitea-runner. Повторный запуск безопасен: уже установленное пропускается.
|
|||
|
|
#
|
|||
|
|
# Запуск (PowerShell от администратора):
|
|||
|
|
# powershell -ExecutionPolicy Bypass -File setup-runner-windows.ps1 [-Token <токен регистрации>]
|
|||
|
|
|
|||
|
|
param(
|
|||
|
|
[string]$Token = "",
|
|||
|
|
[string]$Instance = "https://projects-live.galeonworx.com",
|
|||
|
|
[string]$RunnerName = "win-vm",
|
|||
|
|
[string]$RunnerVersion = "4.1.0",
|
|||
|
|
[string]$QtRoot = "C:\Qt\6.11.1\msvc2022_64",
|
|||
|
|
[string]$QtTools = "C:\Qt\Tools"
|
|||
|
|
)
|
|||
|
|
|
|||
|
|
$ErrorActionPreference = "Stop"
|
|||
|
|
$ProgressPreference = "SilentlyContinue" # иначе Invoke-WebRequest падает без консоли (по SSH)
|
|||
|
|
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
|
|||
|
|
|
|||
|
|
$dl = "C:\ci-downloads"
|
|||
|
|
New-Item -ItemType Directory -Force -Path $dl | Out-Null
|
|||
|
|
|
|||
|
|
function Fetch($url, $name) {
|
|||
|
|
$out = Join-Path $dl $name
|
|||
|
|
if (-not (Test-Path $out)) {
|
|||
|
|
Write-Host "Скачиваю $url"
|
|||
|
|
Invoke-WebRequest -UseBasicParsing -Uri $url -OutFile $out
|
|||
|
|
}
|
|||
|
|
return $out
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
function Run($exe, $argList) {
|
|||
|
|
$p = Start-Process -FilePath $exe -ArgumentList $argList -Wait -PassThru -NoNewWindow
|
|||
|
|
# 3010 — «успешно, нужна перезагрузка» у установщиков MSI и VS
|
|||
|
|
if ($p.ExitCode -ne 0 -and $p.ExitCode -ne 3010) { throw "$exe завершился с кодом $($p.ExitCode)" }
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
# --- Visual Studio 2022 Build Tools (MSVC x64 + Windows SDK) -----------------
|
|||
|
|
$vswhere = "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.exe"
|
|||
|
|
$haveMsvc = (Test-Path $vswhere) -and
|
|||
|
|
(& $vswhere -products * -requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64 -property installationPath)
|
|||
|
|
if (-not $haveMsvc) {
|
|||
|
|
$vs = Fetch "https://aka.ms/vs/17/release/vs_BuildTools.exe" "vs_BuildTools.exe"
|
|||
|
|
Write-Host "Ставлю VS 2022 Build Tools (20–40 минут)…"
|
|||
|
|
Run $vs @("--quiet", "--wait", "--norestart", "--nocache",
|
|||
|
|
"--add", "Microsoft.VisualStudio.Workload.VCTools", "--includeRecommended")
|
|||
|
|
} else { Write-Host "MSVC уже установлен" }
|
|||
|
|
|
|||
|
|
# --- Git for Windows -----------------------------------------------------------
|
|||
|
|
if (-not (Test-Path "C:\Program Files\Git\cmd\git.exe")) {
|
|||
|
|
$rel = Invoke-RestMethod "https://api.github.com/repos/git-for-windows/git/releases/latest"
|
|||
|
|
$asset = $rel.assets | Where-Object { $_.name -match '^Git-.*-64-bit\.exe$' } | Select-Object -First 1
|
|||
|
|
$git = Fetch $asset.browser_download_url $asset.name
|
|||
|
|
Run $git @("/VERYSILENT", "/NORESTART", "/NOCANCEL", "/SP-", "/COMPONENTS=gitlfs")
|
|||
|
|
} else { Write-Host "Git уже установлен" }
|
|||
|
|
|
|||
|
|
# --- Node.js LTS (нужен JS-экшенам вроде actions/checkout) ---------------------
|
|||
|
|
if (-not (Test-Path "C:\Program Files\nodejs\node.exe")) {
|
|||
|
|
# Скобки вокруг Invoke-RestMethod обязательны: PowerShell 5.1 иначе отдаёт
|
|||
|
|
# JSON-массив в конвейер одним объектом, и фильтр видит все версии сразу.
|
|||
|
|
$lts = ((Invoke-RestMethod "https://nodejs.org/dist/index.json") | Where-Object { $_.lts } | Select-Object -First 1).version
|
|||
|
|
$msi = Fetch "https://nodejs.org/dist/$lts/node-$lts-x64.msi" "node-$lts-x64.msi"
|
|||
|
|
Run "msiexec.exe" @("/i", "`"$msi`"", "/qn", "/norestart")
|
|||
|
|
} else { Write-Host "Node.js уже установлен" }
|
|||
|
|
|
|||
|
|
# --- Inno Setup ----------------------------------------------------------------
|
|||
|
|
$iscc = Get-ChildItem "C:\Program Files*\Inno Setup*\ISCC.exe" -ErrorAction SilentlyContinue | Select-Object -First 1
|
|||
|
|
if (-not $iscc) {
|
|||
|
|
# jrsoftware.org/download.php без браузера отдаёт HTML — берём файл из релизов на GitHub
|
|||
|
|
$rel = Invoke-RestMethod "https://api.github.com/repos/jrsoftware/issrc/releases/latest"
|
|||
|
|
$asset = $rel.assets | Where-Object { $_.name -match '^innosetup-[\d.]+(-x64)?\.exe$' } |
|
|||
|
|
Sort-Object { $_.name -notmatch '-x64' } | Select-Object -First 1
|
|||
|
|
$is = Fetch $asset.browser_download_url $asset.name
|
|||
|
|
Run $is @("/VERYSILENT", "/SUPPRESSMSGBOXES", "/NORESTART", "/ALLUSERS")
|
|||
|
|
$iscc = Get-ChildItem "C:\Program Files*\Inno Setup*\ISCC.exe" | Select-Object -First 1
|
|||
|
|
} else { Write-Host "Inno Setup уже установлен" }
|
|||
|
|
|
|||
|
|
# --- Длинные пути: дерево WebEngine легко вылезает за 260 символов --------------
|
|||
|
|
Set-ItemProperty HKLM:\SYSTEM\CurrentControlSet\Control\FileSystem -Name LongPathsEnabled -Value 1
|
|||
|
|
& "C:\Program Files\Git\cmd\git.exe" config --system core.longpaths true
|
|||
|
|
|
|||
|
|
# --- gitea-runner ----------------------------------------------------------------
|
|||
|
|
$rdir = "C:\act_runner"
|
|||
|
|
New-Item -ItemType Directory -Force -Path $rdir, "C:\r" | Out-Null
|
|||
|
|
$exe = Join-Path $rdir "gitea-runner.exe"
|
|||
|
|
if (-not (Test-Path $exe)) {
|
|||
|
|
$src = Fetch "https://gitea.com/gitea/runner/releases/download/v$RunnerVersion/gitea-runner-$RunnerVersion-windows-amd64.exe" "gitea-runner-$RunnerVersion.exe"
|
|||
|
|
Copy-Item $src $exe
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
# Конфиг: host-режим, рабочая папка с коротким путём, пути к Qt через env.
|
|||
|
|
$isccDir = Split-Path $iscc.FullName
|
|||
|
|
$cfg = @"
|
|||
|
|
log:
|
|||
|
|
level: info
|
|||
|
|
runner:
|
|||
|
|
file: $($rdir -replace '\\','/')/.runner
|
|||
|
|
capacity: 1
|
|||
|
|
timeout: 3h
|
|||
|
|
fetch_timeout: 5s
|
|||
|
|
fetch_interval: 2s
|
|||
|
|
envs:
|
|||
|
|
QT_ROOT: '$QtRoot'
|
|||
|
|
QT_TOOLS: '$QtTools'
|
|||
|
|
ISCC_DIR: '$isccDir'
|
|||
|
|
labels:
|
|||
|
|
- "windows:host"
|
|||
|
|
cache:
|
|||
|
|
enabled: false
|
|||
|
|
host:
|
|||
|
|
workdir_parent: C:/r
|
|||
|
|
"@
|
|||
|
|
Set-Content -Path (Join-Path $rdir "config.yaml") -Value $cfg -Encoding UTF8
|
|||
|
|
|
|||
|
|
if ($Token -and -not (Test-Path (Join-Path $rdir ".runner"))) {
|
|||
|
|
Push-Location $rdir
|
|||
|
|
& $exe register --no-interactive --instance $Instance --token $Token `
|
|||
|
|
--name $RunnerName --labels "windows:host" --config config.yaml
|
|||
|
|
if ($LASTEXITCODE -ne 0) { throw "Регистрация раннера не удалась" }
|
|||
|
|
Pop-Location
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
# Обёртка запуска: PATH дополняется git и node — задача планировщика может
|
|||
|
|
# стартовать раньше, чем сессия получит обновлённый системный PATH.
|
|||
|
|
$cmd = @"
|
|||
|
|
@echo off
|
|||
|
|
set PATH=C:\Program Files\Git\cmd;C:\Program Files\Git\usr\bin;C:\Program Files\nodejs;%PATH%
|
|||
|
|
cd /d $rdir
|
|||
|
|
gitea-runner.exe daemon --config config.yaml >> runner.log 2>&1
|
|||
|
|
"@
|
|||
|
|
Set-Content -Path (Join-Path $rdir "run-runner.cmd") -Value $cmd -Encoding ASCII
|
|||
|
|
|
|||
|
|
# Автозапуск при входе galeon: так задаче не нужен пароль учётной записи.
|
|||
|
|
# Чтобы раннер поднимался и без входа, пересоздайте задачу с /sc onstart /rp *.
|
|||
|
|
schtasks /create /f /tn "Gitea Runner" /sc onlogon /ru $env:USERNAME /it /rl highest `
|
|||
|
|
/tr "powershell.exe -WindowStyle Hidden -NoProfile -Command $rdir\run-runner.cmd" | Out-Null
|
|||
|
|
if (-not (Get-Process gitea-runner -ErrorAction SilentlyContinue)) { schtasks /run /tn "Gitea Runner" | Out-Null }
|
|||
|
|
|
|||
|
|
Write-Host "Готово. MSVC, git, node, Inno Setup и gitea-runner на месте."
|