ci: add Gitea Actions Windows runner provisioning + initial docs
This commit is contained in:
@@ -0,0 +1,158 @@
|
||||
# Provisions a Windows Server 2022 host as a Gitea Actions runner for RustDesk
|
||||
# desktop builds (flutter x64 + sciter x86). Idempotent: safe to re-run.
|
||||
#
|
||||
# Versions are pinned to .github/workflows/flutter-build.yml. Bump them there
|
||||
# and here together.
|
||||
#
|
||||
# Usage (Administrator PowerShell):
|
||||
# Set-ExecutionPolicy -Scope Process Bypass -Force
|
||||
# .\provision.ps1 -GiteaUrl https://gitea.example.com -RunnerToken <token>
|
||||
|
||||
[CmdletBinding()]
|
||||
param(
|
||||
[Parameter(Mandatory = $true)] [string] $GiteaUrl,
|
||||
[Parameter(Mandatory = $true)] [string] $RunnerToken,
|
||||
[string] $RunnerName = "$env:COMPUTERNAME-rustdesk",
|
||||
[string] $RunnerLabels = "windows-10,self-hosted,X64",
|
||||
[string] $RunnerVersion = "0.2.11"
|
||||
)
|
||||
|
||||
$ErrorActionPreference = 'Stop'
|
||||
$ProgressPreference = 'SilentlyContinue'
|
||||
|
||||
# --- pinned versions (mirror flutter-build.yml env block) ---
|
||||
$RUST_VERSION = '1.75.0'
|
||||
$RUST_NIGHTLY = 'nightly-2023-10-13'
|
||||
$LLVM_VERSION = '15.0.6'
|
||||
$FLUTTER_VERSION = '3.24.5'
|
||||
$VCPKG_COMMIT = '120deac3062162151622ca4860575a33844ba10b'
|
||||
|
||||
$ToolsRoot = 'C:\tools'
|
||||
New-Item -ItemType Directory -Force -Path $ToolsRoot | Out-Null
|
||||
|
||||
function Add-MachinePath([string]$Dir) {
|
||||
$cur = [Environment]::GetEnvironmentVariable('Path', 'Machine')
|
||||
if ($cur -notlike "*$Dir*") {
|
||||
[Environment]::SetEnvironmentVariable('Path', "$cur;$Dir", 'Machine')
|
||||
}
|
||||
if ($env:Path -notlike "*$Dir*") { $env:Path = "$env:Path;$Dir" }
|
||||
}
|
||||
|
||||
# --- 1. Chocolatey (used for git, python, nuget, 7zip) ---
|
||||
if (-not (Get-Command choco -ErrorAction SilentlyContinue)) {
|
||||
Write-Host '==> Installing Chocolatey'
|
||||
Set-ExecutionPolicy Bypass -Scope Process -Force
|
||||
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
|
||||
Invoke-Expression ((New-Object Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1'))
|
||||
}
|
||||
|
||||
Write-Host '==> Installing base packages'
|
||||
choco install -y --no-progress git python311 nuget.commandline 7zip cmake ninja
|
||||
Add-MachinePath 'C:\Program Files\Git\cmd'
|
||||
Add-MachinePath 'C:\Python311'
|
||||
Add-MachinePath 'C:\Python311\Scripts'
|
||||
|
||||
# --- 2. Visual Studio 2022 Build Tools (MSVC v143 + Win10 SDK) ---
|
||||
$vsInstaller = "$env:ProgramFiles(x86)\Microsoft Visual Studio\Installer\vswhere.exe"
|
||||
$vsPresent = (Test-Path $vsInstaller) -and ((& $vsInstaller -products '*' -requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64 -property installationPath) -ne $null)
|
||||
if (-not $vsPresent) {
|
||||
Write-Host '==> Installing VS 2022 Build Tools (this takes a while)'
|
||||
$vsBootstrapper = "$env:TEMP\vs_buildtools.exe"
|
||||
Invoke-WebRequest -Uri 'https://aka.ms/vs/17/release/vs_buildtools.exe' -OutFile $vsBootstrapper
|
||||
$args = @(
|
||||
'--quiet','--wait','--norestart','--nocache',
|
||||
'--add','Microsoft.VisualStudio.Workload.VCTools',
|
||||
'--add','Microsoft.VisualStudio.Component.VC.Tools.x86.x64',
|
||||
'--add','Microsoft.VisualStudio.Component.VC.ATL',
|
||||
'--add','Microsoft.VisualStudio.Component.Windows10SDK.20348',
|
||||
'--add','Microsoft.VisualStudio.Component.VC.CMake.Project',
|
||||
'--includeRecommended'
|
||||
)
|
||||
$p = Start-Process -FilePath $vsBootstrapper -ArgumentList $args -Wait -PassThru
|
||||
if ($p.ExitCode -notin 0,3010) { throw "VS Build Tools installer exit $($p.ExitCode)" }
|
||||
}
|
||||
|
||||
# --- 3. Rust (stable 1.75 + nightly-2023-10-13 with i686 target) ---
|
||||
if (-not (Get-Command rustup -ErrorAction SilentlyContinue)) {
|
||||
Write-Host '==> Installing rustup'
|
||||
Invoke-WebRequest -Uri 'https://win.rustup.rs/x86_64' -OutFile "$env:TEMP\rustup-init.exe"
|
||||
& "$env:TEMP\rustup-init.exe" -y --default-toolchain none --profile minimal
|
||||
Add-MachinePath "$env:USERPROFILE\.cargo\bin"
|
||||
}
|
||||
rustup toolchain install $RUST_VERSION --profile minimal --component rustfmt
|
||||
rustup target add --toolchain $RUST_VERSION x86_64-pc-windows-msvc
|
||||
rustup toolchain install $RUST_NIGHTLY --profile minimal --component rustfmt
|
||||
rustup target add --toolchain $RUST_NIGHTLY i686-pc-windows-msvc
|
||||
rustup default $RUST_VERSION
|
||||
|
||||
# --- 4. LLVM/Clang 15.0.6 (matches KyleMayes/install-llvm-action) ---
|
||||
$llvmDir = "$ToolsRoot\llvm-$LLVM_VERSION"
|
||||
if (-not (Test-Path "$llvmDir\bin\clang.exe")) {
|
||||
Write-Host "==> Installing LLVM $LLVM_VERSION"
|
||||
$llvmExe = "$env:TEMP\LLVM-$LLVM_VERSION-win64.exe"
|
||||
Invoke-WebRequest -Uri "https://github.com/llvm/llvm-project/releases/download/llvmorg-$LLVM_VERSION/LLVM-$LLVM_VERSION-win64.exe" -OutFile $llvmExe
|
||||
& $llvmExe /S "/D=$llvmDir" | Out-Null
|
||||
}
|
||||
[Environment]::SetEnvironmentVariable('LIBCLANG_PATH', "$llvmDir\bin", 'Machine')
|
||||
Add-MachinePath "$llvmDir\bin"
|
||||
|
||||
# --- 5. Flutter 3.24.5 (stable channel, with windows precache) ---
|
||||
$flutterDir = "$ToolsRoot\flutter"
|
||||
if (-not (Test-Path "$flutterDir\bin\flutter.bat")) {
|
||||
Write-Host "==> Installing Flutter $FLUTTER_VERSION"
|
||||
$flutterZip = "$env:TEMP\flutter.zip"
|
||||
Invoke-WebRequest -Uri "https://storage.googleapis.com/flutter_infra_release/releases/stable/windows/flutter_windows_$FLUTTER_VERSION-stable.zip" -OutFile $flutterZip
|
||||
Expand-Archive -Force -Path $flutterZip -DestinationPath $ToolsRoot
|
||||
}
|
||||
Add-MachinePath "$flutterDir\bin"
|
||||
& "$flutterDir\bin\flutter.bat" config --no-analytics | Out-Null
|
||||
& "$flutterDir\bin\flutter.bat" precache --windows | Out-Null
|
||||
|
||||
# --- 6. vcpkg pinned to commit ---
|
||||
$vcpkgDir = 'C:\vcpkg'
|
||||
if (-not (Test-Path "$vcpkgDir\.git")) {
|
||||
Write-Host '==> Cloning vcpkg'
|
||||
git clone https://github.com/microsoft/vcpkg.git $vcpkgDir
|
||||
}
|
||||
Push-Location $vcpkgDir
|
||||
git fetch --tags origin
|
||||
git -c advice.detachedHead=false checkout $VCPKG_COMMIT
|
||||
if (-not (Test-Path "$vcpkgDir\vcpkg.exe")) { & "$vcpkgDir\bootstrap-vcpkg.bat" -disableMetrics }
|
||||
Pop-Location
|
||||
[Environment]::SetEnvironmentVariable('VCPKG_ROOT', $vcpkgDir, 'Machine')
|
||||
Add-MachinePath $vcpkgDir
|
||||
|
||||
# --- 7. Gitea act_runner ---
|
||||
$runnerDir = 'C:\actions-runner'
|
||||
New-Item -ItemType Directory -Force -Path $runnerDir | Out-Null
|
||||
$runnerExe = "$runnerDir\act_runner.exe"
|
||||
if (-not (Test-Path $runnerExe)) {
|
||||
Write-Host "==> Downloading act_runner $RunnerVersion"
|
||||
Invoke-WebRequest -Uri "https://gitea.com/gitea/act_runner/releases/download/v$RunnerVersion/act_runner-$RunnerVersion-windows-amd64.exe" -OutFile $runnerExe
|
||||
}
|
||||
|
||||
Push-Location $runnerDir
|
||||
if (-not (Test-Path "$runnerDir\.runner")) {
|
||||
Write-Host '==> Registering runner'
|
||||
& $runnerExe register --no-interactive `
|
||||
--instance $GiteaUrl `
|
||||
--token $RunnerToken `
|
||||
--name $RunnerName `
|
||||
--labels $RunnerLabels
|
||||
}
|
||||
if (-not (Get-Service -Name 'gitea-act-runner' -ErrorAction SilentlyContinue)) {
|
||||
Write-Host '==> Installing runner as Windows service'
|
||||
# nssm is the cleanest way to host a console exe as a service on Windows.
|
||||
choco install -y --no-progress nssm
|
||||
nssm install gitea-act-runner $runnerExe daemon
|
||||
nssm set gitea-act-runner AppDirectory $runnerDir
|
||||
nssm set gitea-act-runner Start SERVICE_AUTO_START
|
||||
nssm set gitea-act-runner AppStdout "$runnerDir\runner.log"
|
||||
nssm set gitea-act-runner AppStderr "$runnerDir\runner.log"
|
||||
}
|
||||
Start-Service gitea-act-runner
|
||||
Pop-Location
|
||||
|
||||
Write-Host ''
|
||||
Write-Host '==> Done. Reboot recommended so PATH/env changes take effect for the runner service.'
|
||||
Write-Host ' After reboot, verify the runner shows up green in Gitea > Site Admin > Actions > Runners.'
|
||||
Reference in New Issue
Block a user