From a80012b48e894bb33cb743a8711fc56cd7bf61db Mon Sep 17 00:00:00 2001 From: Tingluo Huang Date: Wed, 11 Oct 2023 13:31:13 -0400 Subject: [PATCH] [Ubuntu] cache most used GitHub actions --- .../installers/action-archive-cache.sh | 26 +++++++++++++++++++ .../tests/ActionArchiveCache.Tests.ps1 | 15 +++++++++++ images/linux/ubuntu2004.json | 1 + images/linux/ubuntu2204.pkr.hcl | 1 + 4 files changed, 43 insertions(+) create mode 100755 images/linux/scripts/installers/action-archive-cache.sh create mode 100644 images/linux/scripts/tests/ActionArchiveCache.Tests.ps1 diff --git a/images/linux/scripts/installers/action-archive-cache.sh b/images/linux/scripts/installers/action-archive-cache.sh new file mode 100755 index 00000000..c54c7d06 --- /dev/null +++ b/images/linux/scripts/installers/action-archive-cache.sh @@ -0,0 +1,26 @@ +#!/bin/bash -e +################################################################################ +## File: action-archive-cache.sh +## Desc: Download latest release from https://github.com/actions/action-verions +## and un-tar to /opt/actionarchivecache +## Maintainer: #actions-runtime and @TingluoHuang +################################################################################ + +# Source the helpers for use with the script +source $HELPER_SCRIPTS/install.sh +source $HELPER_SCRIPTS/etc-environment.sh + +# Prepare directory and env variable for ACTIONS_RUNNER_ACTION_ARCHIVE_CACHE +ACTION_ARCHIVE_CACHE_DIR=/opt/actionarchivecache +mkdir -p $ACTION_ARCHIVE_CACHE_DIR +chmod -R 777 $ACTION_ARCHIVE_CACHE_DIR +echo "Setting up ACTIONS_RUNNER_ACTION_ARCHIVE_CACHE variable to ${ACTION_ARCHIVE_CACHE_DIR}" +addEtcEnvironmentVariable ACTIONS_RUNNER_ACTION_ARCHIVE_CACHE ${ACTION_ARCHIVE_CACHE_DIR} + +# Download latest release from github.com/actions/action-versions and untar to /opt/actionarchivecache +downloadUrl=$(get_github_package_download_url "actions/action-versions" "contains(\"action-versions.tar.gz\")") +echo "Downloading action-versions $downloadUrl" +download_with_retries "$downloadUrl" "/tmp" action-versions.tar.gz +tar -xzf /tmp/action-versions.tar.gz -C $ACTION_ARCHIVE_CACHE_DIR + +invoke_tests "ActionArchiveCache" diff --git a/images/linux/scripts/tests/ActionArchiveCache.Tests.ps1 b/images/linux/scripts/tests/ActionArchiveCache.Tests.ps1 new file mode 100644 index 00000000..6da1eb93 --- /dev/null +++ b/images/linux/scripts/tests/ActionArchiveCache.Tests.ps1 @@ -0,0 +1,15 @@ +Describe "ActionArchiveCache" { + Context "Action archive cache directory not empty" { + It "/opt/actionarchivecache not empty" { + (Get-ChildItem -Path "/opt/actionarchivecache/*.tar.gz" -Recurse).Count | Should -BeGreaterThan 0 + } + } + + Context "Action tarball not empty" { + $testCases = Get-ChildItem -Path "/opt/actionarchivecache/*.tar.gz" -Recurse | ForEach-Object { @{ ActionTarball = $_.FullName } } + It "" -TestCases $testCases { + param ([string] $ActionTarball) + (Get-Item "$ActionTarball").Length | Should -BeGreaterThan 0 + } + } +} diff --git a/images/linux/ubuntu2004.json b/images/linux/ubuntu2004.json index 5fc6d909..5e66c9bb 100644 --- a/images/linux/ubuntu2004.json +++ b/images/linux/ubuntu2004.json @@ -196,6 +196,7 @@ { "type": "shell", "scripts": [ + "{{template_dir}}/scripts/installers/action-archive-cache.sh", "{{template_dir}}/scripts/installers/apt-common.sh", "{{template_dir}}/scripts/installers/azcopy.sh", "{{template_dir}}/scripts/installers/azure-cli.sh", diff --git a/images/linux/ubuntu2204.pkr.hcl b/images/linux/ubuntu2204.pkr.hcl index 1f06f821..c4376169 100644 --- a/images/linux/ubuntu2204.pkr.hcl +++ b/images/linux/ubuntu2204.pkr.hcl @@ -280,6 +280,7 @@ build { environment_vars = ["HELPER_SCRIPTS=${var.helper_script_folder}", "INSTALLER_SCRIPT_FOLDER=${var.installer_script_folder}", "DEBIAN_FRONTEND=noninteractive"] execute_command = "sudo sh -c '{{ .Vars }} {{ .Path }}'" scripts = [ + "${path.root}/scripts/installers/action-archive-cache.sh", "${path.root}/scripts/installers/apt-common.sh", "${path.root}/scripts/installers/azcopy.sh", "${path.root}/scripts/installers/azure-cli.sh",