Skip to content

Commit

Permalink
[Windows] cache most used GitHub actions
Browse files Browse the repository at this point in the history
* Download actions/action_versions latest release on Windows and set ACTIONS_RUNNER_ACTION_ARCHIVE_CACHE.

* feedback

* fix get latest package on Windows.

* invoke test
  • Loading branch information
TingluoHuang authored Oct 12, 2023
1 parent a80012b commit c7517ab
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 2 deletions.
21 changes: 21 additions & 0 deletions images/win/scripts/Installers/Install-ActionArchiveCache.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
################################################################################
## File: Install-ActionArchiveCache.ps1
## Desc: Download latest release from https://github.com/actions/action-versions
## and un-zip to C:\actionarchivecache
## Maintainer: #actions-runtime and @TingluoHuang
################################################################################

if (-not (Test-Path $env:ACTIONS_RUNNER_ACTION_ARCHIVE_CACHE))
{
Write-Host "Creating action archive cache folder"
New-Item -ItemType Directory -Path $env:ACTIONS_RUNNER_ACTION_ARCHIVE_CACHE | Out-Null
}

$downloadUrl = Get-GitHubPackageDownloadUrl -RepoOwner "actions" -RepoName "action-versions" -Version "latest" -UrlFilter "*/v{Version}/action-versions.zip"
Write-Host "Download Latest action-versions archive from $downloadUrl"
$actionVersionsArchivePath = Start-DownloadWithRetry -Url $downloadUrl -Name "action-versions.zip"

Write-Host "Expand action-versions archive"
Extract-7Zip -Path $actionVersionsArchivePath -DestinationPath $env:ACTIONS_RUNNER_ACTION_ARCHIVE_CACHE

Invoke-PesterTests -TestFile "ActionArchiveCache"
3 changes: 2 additions & 1 deletion images/win/scripts/Installers/Update-ImageData.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,5 @@ $json | Out-File -FilePath $imageDataFile
# Set static env vars
setx ImageVersion $env:IMAGE_VERSION /m
setx ImageOS $env:IMAGE_OS /m
setx AGENT_TOOLSDIRECTORY $env:AGENT_TOOLSDIRECTORY /m
setx AGENT_TOOLSDIRECTORY $env:AGENT_TOOLSDIRECTORY /m
setx ACTIONS_RUNNER_ACTION_ARCHIVE_CACHE $env:ACTIONS_RUNNER_ACTION_ARCHIVE_CACHE /m
15 changes: 15 additions & 0 deletions images/win/scripts/Tests/ActionArchiveCache.Tests.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
Describe "ActionArchiveCache" {
Context "Action archive cache directory not empty" {
It "C:\actionarchivecache not empty" {
(Get-ChildItem -Path "C:\actionarchivecache\*.zip" -Recurse).Count | Should -BeGreaterThan 0
}
}

Context "Action zipball not empty" {
$testCases = Get-ChildItem -Path "C:\actionarchivecache\*.zip" -Recurse | ForEach-Object { @{ ActionZipball = $_.FullName } }
It "<ActionZipball>" -TestCases $testCases {
param ([string] $ActionZipball)
(Get-Item "$ActionZipball").Length | Should -BeGreaterThan 0
}
}
}
4 changes: 3 additions & 1 deletion images/win/windows2019.json
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@
"IMAGE_VERSION={{user `image_version`}}",
"IMAGE_OS={{user `image_os`}}",
"AGENT_TOOLSDIRECTORY={{user `agent_tools_directory`}}",
"ACTIONS_RUNNER_ACTION_ARCHIVE_CACHE=C:\\actionarchivecache\\",
"IMAGEDATA_FILE={{user `imagedata_file`}}"
],
"scripts": [
Expand Down Expand Up @@ -225,6 +226,7 @@
{
"type": "powershell",
"scripts": [
"{{ template_dir }}/scripts/Installers/Install-ActionArchiveCache.ps1",
"{{ template_dir }}/scripts/Installers/Install-Ruby.ps1",
"{{ template_dir }}/scripts/Installers/Install-PyPy.ps1",
"{{ template_dir }}/scripts/Installers/Install-Toolset.ps1",
Expand Down Expand Up @@ -362,4 +364,4 @@
]
}
]
}
}
2 changes: 2 additions & 0 deletions images/win/windows2022.json
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@
"IMAGE_VERSION={{user `image_version`}}",
"IMAGE_OS={{user `image_os`}}",
"AGENT_TOOLSDIRECTORY={{user `agent_tools_directory`}}",
"ACTIONS_RUNNER_ACTION_ARCHIVE_CACHE=C:\\actionarchivecache\\",
"IMAGEDATA_FILE={{user `imagedata_file`}}"
],
"scripts": [
Expand Down Expand Up @@ -215,6 +216,7 @@
{
"type": "powershell",
"scripts": [
"{{ template_dir }}/scripts/Installers/Install-ActionArchiveCache.ps1",
"{{ template_dir }}/scripts/Installers/Install-Ruby.ps1",
"{{ template_dir }}/scripts/Installers/Install-PyPy.ps1",
"{{ template_dir }}/scripts/Installers/Install-Toolset.ps1",
Expand Down

0 comments on commit c7517ab

Please sign in to comment.