Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save aixxe/1f28ca00c3270695b2be939f202a5a65 to your computer and use it in GitHub Desktop.
Save aixxe/1f28ca00c3270695b2be939f202a5a65 to your computer and use it in GitHub Desktop.
Add-Type -Assembly "System.IO.Compression.Filesystem" # https://github.com/PowerShell/Microsoft.PowerShell.Archive/issues/32
# Download the latest version of Go
$version = Invoke-WebRequest -Uri "https://go.dev/VERSION?m=text" -UseBasicParsing
$version = $version.Content -split "`n" | Select-Object -First 1
Invoke-WebRequest -Uri "https://go.dev/dl/$version.windows-amd64.zip" -OutFile "go.zip"
[System.IO.Compression.ZipFile]::ExtractToDirectory("$PWD\go.zip", "$PWD")
# Download the latest release of Gitlab Runner
$response = Invoke-WebRequest -Uri "https://gitlab.com/api/v4/projects/250833/releases" -UseBasicParsing
$response = $response.Content | ConvertFrom-Json
$latestTag = $response[0].tag_name
$latestZipUrl = $response.assets[0].sources | Where-Object { $_.format -eq 'zip' } | Select-Object -First 1
Invoke-WebRequest -Uri $latestZipUrl.url -OutFile "gitlab-runner.zip"
[System.IO.Compression.ZipFile]::ExtractToDirectory("$PWD\gitlab-runner.zip", "$PWD")
# Append the custom list of versions to the supported list
$serverCoreVersion = "V21H2"
$osVersion = [System.Environment]::OSVersion.Version
$targetPath = "gitlab-runner-$latestTag/helpers/container/windows/version.go"
$targetBody = Get-Content -Path $targetPath
$targetSubstr = ($targetBody | Select-String -Pattern "var supportedWindowsBuilds =" | Select-Object -First 1)
$targetVersion = "`n`t`"" + $osVersion.Major + "." + $osVersion.Minor + "." + $osVersion.Build + "`": $serverCoreVersion,"
$targetBody[$targetSubstr.LineNumber - 1] += $targetVersion
$targetBody | Set-Content -Path $targetPath
# Rebuild from source and move to "C:\Gitlab-Runner\gitlab-runner.exe"
Set-Location -Path "gitlab-runner-$latestTag"
../go/bin/go.exe build -ldflags '-s' .
Move-Item -Path "gitlab-runner.exe" -Destination "C:\Gitlab-Runner\gitlab-runner.exe" -Force
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment