Skip to content

Commit 516150e

Browse files
committed
Add caching for the Windows Runner
1 parent 641d1dd commit 516150e

File tree

1 file changed

+25
-20
lines changed

1 file changed

+25
-20
lines changed

cloudconfig/templates.go

+25-20
Original file line numberDiff line numberDiff line change
@@ -522,27 +522,32 @@ function Install-Runner() {
522522
Import-Certificate -CertificateData $data -StoreName Root -StoreLocation LocalMachine
523523
}
524524
525-
Update-GarmStatus -CallbackURL $CallbackURL -Message "downloading tools from $DownloadURL"
526-
527-
$downloadToken="{{.TempDownloadToken}}"
528-
$DownloadTokenHeaders=@{}
529-
if ($downloadToken.Length -gt 0) {
530-
$DownloadTokenHeaders=@{
531-
"Authorization"="Bearer $downloadToken"
525+
$runnerDir = "C:\actions-runner"
526+
# Check if a cached runner is available
527+
if (-not (Test-Path $runnerDir)) {
528+
# No cached runner found, proceed to download and extract
529+
Update-GarmStatus -CallbackURL $CallbackURL -Message "downloading tools from {{ .DownloadURL }}"
530+
531+
$downloadToken="{{.TempDownloadToken}}"
532+
$DownloadTokenHeaders=@{}
533+
if ($downloadToken.Length -gt 0) {
534+
$DownloadTokenHeaders=@{
535+
"Authorization"="Bearer $downloadToken"
536+
}
532537
}
533-
}
534-
$downloadPath = Join-Path $env:TMP {{.FileName}}
535-
# Download runner with retry
536-
Start-ExecuteWithRetry -ScriptBlock {
537-
Invoke-FastWebRequest -Uri $DownloadURL -OutFile $downloadPath -Headers $DownloadTokenHeaders
538-
} -MaxRetryCount 5 -RetryInterval 5 -RetryMessage "Retrying download of runner..."
539538
540-
$runnerDir = "C:\runner"
541-
mkdir $runnerDir
542-
543-
Update-GarmStatus -CallbackURL $CallbackURL -Message "extracting runner"
544-
Add-Type -AssemblyName System.IO.Compression.FileSystem
545-
[System.IO.Compression.ZipFile]::ExtractToDirectory($downloadPath, "$runnerDir")
539+
$downloadPath = Join-Path $env:TMP "{{ .FileName }}"
540+
Start-ExecuteWithRetry -ScriptBlock {
541+
Invoke-FastWebRequest -Uri "{{ .DownloadURL }}" -OutFile $downloadPath -Headers $DownloadTokenHeaders
542+
} -MaxRetryCount 5 -RetryInterval 5 -RetryMessage "Retrying download of runner..."
543+
544+
mkdir $runnerDir
545+
Update-GarmStatus -CallbackURL $CallbackURL -Message "extracting runner"
546+
Add-Type -AssemblyName System.IO.Compression.FileSystem
547+
[System.IO.Compression.ZipFile]::ExtractToDirectory($downloadPath, "$runnerDir")
548+
} else {
549+
Update-GarmStatus -CallbackURL $CallbackURL -Message "using cached runner found at $runnerDir"
550+
}
546551
547552
Update-GarmStatus -CallbackURL $CallbackURL -Message "configuring and starting runner"
548553
cd $runnerDir
@@ -563,7 +568,7 @@ function Install-Runner() {
563568
564569
Update-GarmStatus -CallbackURL $CallbackURL -Message "Creating system service"
565570
$SVC_NAME=(gc -raw $serviceNameFile)
566-
New-Service -Name "$SVC_NAME" -BinaryPathName "C:\runner\bin\RunnerService.exe" -DisplayName "$SVC_NAME" -Description "GitHub Actions Runner ($SVC_NAME)" -StartupType Automatic
571+
New-Service -Name "$SVC_NAME" -BinaryPathName "C:\actions-runner\bin\RunnerService.exe" -DisplayName "$SVC_NAME" -Description "GitHub Actions Runner ($SVC_NAME)" -StartupType Automatic
567572
Start-Service "$SVC_NAME"
568573
Set-SystemInfo -CallbackURL $CallbackURL -RunnerDir $runnerDir -BearerToken $Token
569574
Update-GarmStatus -Message "runner successfully installed" -CallbackURL $CallbackURL -Status "idle" | Out-Null

0 commit comments

Comments
 (0)