Skip to content

Commit c7517ab

Browse files
authored
[Windows] cache most used GitHub actions
* Download actions/action_versions latest release on Windows and set ACTIONS_RUNNER_ACTION_ARCHIVE_CACHE. * feedback * fix get latest package on Windows. * invoke test
1 parent a80012b commit c7517ab

File tree

5 files changed

+43
-2
lines changed

5 files changed

+43
-2
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
################################################################################
2+
## File: Install-ActionArchiveCache.ps1
3+
## Desc: Download latest release from https://github.com/actions/action-versions
4+
## and un-zip to C:\actionarchivecache
5+
## Maintainer: #actions-runtime and @TingluoHuang
6+
################################################################################
7+
8+
if (-not (Test-Path $env:ACTIONS_RUNNER_ACTION_ARCHIVE_CACHE))
9+
{
10+
Write-Host "Creating action archive cache folder"
11+
New-Item -ItemType Directory -Path $env:ACTIONS_RUNNER_ACTION_ARCHIVE_CACHE | Out-Null
12+
}
13+
14+
$downloadUrl = Get-GitHubPackageDownloadUrl -RepoOwner "actions" -RepoName "action-versions" -Version "latest" -UrlFilter "*/v{Version}/action-versions.zip"
15+
Write-Host "Download Latest action-versions archive from $downloadUrl"
16+
$actionVersionsArchivePath = Start-DownloadWithRetry -Url $downloadUrl -Name "action-versions.zip"
17+
18+
Write-Host "Expand action-versions archive"
19+
Extract-7Zip -Path $actionVersionsArchivePath -DestinationPath $env:ACTIONS_RUNNER_ACTION_ARCHIVE_CACHE
20+
21+
Invoke-PesterTests -TestFile "ActionArchiveCache"

images/win/scripts/Installers/Update-ImageData.ps1

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,5 @@ $json | Out-File -FilePath $imageDataFile
4141
# Set static env vars
4242
setx ImageVersion $env:IMAGE_VERSION /m
4343
setx ImageOS $env:IMAGE_OS /m
44-
setx AGENT_TOOLSDIRECTORY $env:AGENT_TOOLSDIRECTORY /m
44+
setx AGENT_TOOLSDIRECTORY $env:AGENT_TOOLSDIRECTORY /m
45+
setx ACTIONS_RUNNER_ACTION_ARCHIVE_CACHE $env:ACTIONS_RUNNER_ACTION_ARCHIVE_CACHE /m
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
Describe "ActionArchiveCache" {
2+
Context "Action archive cache directory not empty" {
3+
It "C:\actionarchivecache not empty" {
4+
(Get-ChildItem -Path "C:\actionarchivecache\*.zip" -Recurse).Count | Should -BeGreaterThan 0
5+
}
6+
}
7+
8+
Context "Action zipball not empty" {
9+
$testCases = Get-ChildItem -Path "C:\actionarchivecache\*.zip" -Recurse | ForEach-Object { @{ ActionZipball = $_.FullName } }
10+
It "<ActionZipball>" -TestCases $testCases {
11+
param ([string] $ActionZipball)
12+
(Get-Item "$ActionZipball").Length | Should -BeGreaterThan 0
13+
}
14+
}
15+
}

images/win/windows2019.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@
146146
"IMAGE_VERSION={{user `image_version`}}",
147147
"IMAGE_OS={{user `image_os`}}",
148148
"AGENT_TOOLSDIRECTORY={{user `agent_tools_directory`}}",
149+
"ACTIONS_RUNNER_ACTION_ARCHIVE_CACHE=C:\\actionarchivecache\\",
149150
"IMAGEDATA_FILE={{user `imagedata_file`}}"
150151
],
151152
"scripts": [
@@ -225,6 +226,7 @@
225226
{
226227
"type": "powershell",
227228
"scripts": [
229+
"{{ template_dir }}/scripts/Installers/Install-ActionArchiveCache.ps1",
228230
"{{ template_dir }}/scripts/Installers/Install-Ruby.ps1",
229231
"{{ template_dir }}/scripts/Installers/Install-PyPy.ps1",
230232
"{{ template_dir }}/scripts/Installers/Install-Toolset.ps1",
@@ -362,4 +364,4 @@
362364
]
363365
}
364366
]
365-
}
367+
}

images/win/windows2022.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@
130130
"IMAGE_VERSION={{user `image_version`}}",
131131
"IMAGE_OS={{user `image_os`}}",
132132
"AGENT_TOOLSDIRECTORY={{user `agent_tools_directory`}}",
133+
"ACTIONS_RUNNER_ACTION_ARCHIVE_CACHE=C:\\actionarchivecache\\",
133134
"IMAGEDATA_FILE={{user `imagedata_file`}}"
134135
],
135136
"scripts": [
@@ -215,6 +216,7 @@
215216
{
216217
"type": "powershell",
217218
"scripts": [
219+
"{{ template_dir }}/scripts/Installers/Install-ActionArchiveCache.ps1",
218220
"{{ template_dir }}/scripts/Installers/Install-Ruby.ps1",
219221
"{{ template_dir }}/scripts/Installers/Install-PyPy.ps1",
220222
"{{ template_dir }}/scripts/Installers/Install-Toolset.ps1",

0 commit comments

Comments
 (0)