From d77bb13e9741ebfe3aa859d3313492a8d43990fc Mon Sep 17 00:00:00 2001 From: Tingluo Huang Date: Thu, 12 Oct 2023 04:54:39 -0400 Subject: [PATCH] [macOS] cache most used GitHub actions * Download actions/action_versions latest release on macOS and set ACTIONS_RUNNER_ACTION_ARCHIVE_CACHE. * Feedback. --- .../configuration/environment/bashrc | 1 + .../provision/core/action-archive-cache.sh | 22 +++++++++++++++++++ images/macos/templates/macOS-11.json | 1 + images/macos/templates/macOS-12.anka.pkr.hcl | 1 + images/macos/templates/macOS-12.json | 1 + images/macos/templates/macOS-13.anka.pkr.hcl | 1 + .../templates/macOS-13.arm64.anka.pkr.hcl | 1 + .../macos/tests/ActionArchiveCache.Tests.ps1 | 15 +++++++++++++ 8 files changed, 43 insertions(+) create mode 100755 images/macos/provision/core/action-archive-cache.sh create mode 100644 images/macos/tests/ActionArchiveCache.Tests.ps1 diff --git a/images/macos/provision/configuration/environment/bashrc b/images/macos/provision/configuration/environment/bashrc index aedd17a6..ca021fd7 100644 --- a/images/macos/provision/configuration/environment/bashrc +++ b/images/macos/provision/configuration/environment/bashrc @@ -12,6 +12,7 @@ export NUNIT3_PATH=/Library/Developer/nunit/3.6.0 export AGENT_TOOLSDIRECTORY=$HOME/hostedtoolcache export RUNNER_TOOL_CACHE=$HOME/hostedtoolcache +export ACTIONS_RUNNER_ACTION_ARCHIVE_CACHE=$HOME/actionarchivecache export PATH=/Library/Frameworks/Mono.framework/Versions/Current/Commands:$PATH export PATH=/Library/Frameworks/Python.framework/Versions/Current/bin:$PATH diff --git a/images/macos/provision/core/action-archive-cache.sh b/images/macos/provision/core/action-archive-cache.sh new file mode 100755 index 00000000..99ad6a0c --- /dev/null +++ b/images/macos/provision/core/action-archive-cache.sh @@ -0,0 +1,22 @@ +#!/bin/bash -e -o pipefail + +################################################################################ +## File: action-archive-cache.sh +## Desc: Download latest release from https://github.com/actions/action-verions +## and un-tar to $HOME/actionarchivecache +## Maintainer: #actions-runtime and @TingluoHuang +################################################################################ + +source ~/utils/utils.sh + +echo "Check if ACTIONS_RUNNER_ACTION_ARCHIVE_CACHE folder exist..." +if [ ! -d $ACTIONS_RUNNER_ACTION_ARCHIVE_CACHE ]; then + mkdir -p $ACTIONS_RUNNER_ACTION_ARCHIVE_CACHE +fi + +downloadUrl=$(get_github_package_download_url "actions/action-versions" "contains(\"action-versions.tar.gz\")" "latest") +echo "Downloading action-versions $downloadUrl" +download_with_retries "$downloadUrl" "/tmp" action-versions.tar.gz +tar -xzf /tmp/action-versions.tar.gz -C $ACTIONS_RUNNER_ACTION_ARCHIVE_CACHE + +invoke_tests "ActionArchiveCache" diff --git a/images/macos/templates/macOS-11.json b/images/macos/templates/macOS-11.json index 8572fae0..e7f682c4 100644 --- a/images/macos/templates/macOS-11.json +++ b/images/macos/templates/macOS-11.json @@ -183,6 +183,7 @@ "type": "shell", "execute_command": "chmod +x {{ .Path }}; {{ .Vars }} {{ .Path }}", "scripts": [ + "./provision/core/action-archive-cache.sh", "./provision/core/commonutils.sh", "./provision/core/llvm.sh", "./provision/core/golang.sh", diff --git a/images/macos/templates/macOS-12.anka.pkr.hcl b/images/macos/templates/macOS-12.anka.pkr.hcl index 44bdbe58..c13e60fa 100644 --- a/images/macos/templates/macOS-12.anka.pkr.hcl +++ b/images/macos/templates/macOS-12.anka.pkr.hcl @@ -198,6 +198,7 @@ build { } provisioner "shell" { scripts = [ + "./provision/core/action-archive-cache.sh", "./provision/core/llvm.sh", "./provision/core/golang.sh", "./provision/core/swiftlint.sh", diff --git a/images/macos/templates/macOS-12.json b/images/macos/templates/macOS-12.json index 57d7bc72..42460036 100644 --- a/images/macos/templates/macOS-12.json +++ b/images/macos/templates/macOS-12.json @@ -185,6 +185,7 @@ "type": "shell", "execute_command": "chmod +x {{ .Path }}; {{ .Vars }} {{ .Path }}", "scripts": [ + "./provision/core/action-archive-cache.sh", "./provision/core/llvm.sh", "./provision/core/golang.sh", "./provision/core/swiftlint.sh", diff --git a/images/macos/templates/macOS-13.anka.pkr.hcl b/images/macos/templates/macOS-13.anka.pkr.hcl index 3b8f3649..7b833065 100644 --- a/images/macos/templates/macOS-13.anka.pkr.hcl +++ b/images/macos/templates/macOS-13.anka.pkr.hcl @@ -194,6 +194,7 @@ build { } provisioner "shell" { scripts = [ + "./provision/core/action-archive-cache.sh", "./provision/core/llvm.sh", "./provision/core/swiftlint.sh", "./provision/core/openjdk.sh", diff --git a/images/macos/templates/macOS-13.arm64.anka.pkr.hcl b/images/macos/templates/macOS-13.arm64.anka.pkr.hcl index d022109d..6074f294 100644 --- a/images/macos/templates/macOS-13.arm64.anka.pkr.hcl +++ b/images/macos/templates/macOS-13.arm64.anka.pkr.hcl @@ -194,6 +194,7 @@ build { } provisioner "shell" { scripts = [ + "./provision/core/action-archive-cache.sh", "./provision/core/llvm.sh", "./provision/core/openjdk.sh", "./provision/core/rust.sh", diff --git a/images/macos/tests/ActionArchiveCache.Tests.ps1 b/images/macos/tests/ActionArchiveCache.Tests.ps1 new file mode 100644 index 00000000..d45755db --- /dev/null +++ b/images/macos/tests/ActionArchiveCache.Tests.ps1 @@ -0,0 +1,15 @@ +Describe "ActionArchiveCache" { + Context "Action archive cache directory not empty" { + It "$HOME/actionarchivecache not empty" { + (Get-ChildItem -Path "$env:HOME/actionarchivecache/*.tar.gz" -Recurse).Count | Should -BeGreaterThan 0 + } + } + + Context "Action tarball not empty" { + $testCases = Get-ChildItem -Path "$env:HOME/actionarchivecache/*.tar.gz" -Recurse | ForEach-Object { @{ ActionTarball = $_.FullName } } + It "" -TestCases $testCases { + param ([string] $ActionTarball) + (Get-Item "$ActionTarball").Length | Should -BeGreaterThan 0 + } + } +}