diff --git a/images/win/scripts/Installers/Install-ActionArchiveCache.ps1 b/images/win/scripts/Installers/Install-ActionArchiveCache.ps1 new file mode 100644 index 000000000..4f4bc00b5 --- /dev/null +++ b/images/win/scripts/Installers/Install-ActionArchiveCache.ps1 @@ -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" diff --git a/images/win/scripts/Installers/Update-ImageData.ps1 b/images/win/scripts/Installers/Update-ImageData.ps1 index 0afa2bdd2..f27b5c7e4 100644 --- a/images/win/scripts/Installers/Update-ImageData.ps1 +++ b/images/win/scripts/Installers/Update-ImageData.ps1 @@ -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 \ No newline at end of file +setx AGENT_TOOLSDIRECTORY $env:AGENT_TOOLSDIRECTORY /m +setx ACTIONS_RUNNER_ACTION_ARCHIVE_CACHE $env:ACTIONS_RUNNER_ACTION_ARCHIVE_CACHE /m diff --git a/images/win/scripts/Tests/ActionArchiveCache.Tests.ps1 b/images/win/scripts/Tests/ActionArchiveCache.Tests.ps1 new file mode 100644 index 000000000..e0bb71172 --- /dev/null +++ b/images/win/scripts/Tests/ActionArchiveCache.Tests.ps1 @@ -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 "" -TestCases $testCases { + param ([string] $ActionZipball) + (Get-Item "$ActionZipball").Length | Should -BeGreaterThan 0 + } + } +} diff --git a/images/win/windows2019.json b/images/win/windows2019.json index 07d3a6f02..834a0c3c5 100644 --- a/images/win/windows2019.json +++ b/images/win/windows2019.json @@ -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": [ @@ -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", @@ -362,4 +364,4 @@ ] } ] -} \ No newline at end of file +} diff --git a/images/win/windows2022.json b/images/win/windows2022.json index db4a671f3..bccf2df30 100644 --- a/images/win/windows2022.json +++ b/images/win/windows2022.json @@ -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": [ @@ -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",