From e5a9854ee155c6bc9fe7e5a179486241f1197e51 Mon Sep 17 00:00:00 2001 From: awalsh128 Date: Thu, 21 Oct 2021 20:57:52 -0700 Subject: [PATCH 01/22] Consolidate steps, and make reporting less verbose. --- README.md | 2 +- action.yml | 35 +++++++----------------- create_cache_key.sh | 23 ---------------- install_and_cache_pkgs.sh | 34 ++++++++++++------------ post_cache_action.sh | 41 ++++++++++++++++++++++++++++ pre_cache_action.sh | 56 +++++++++++++++++++++++++++++++++++++++ restore_pkgs.sh | 18 ++++++------- validate_pkgs.sh | 29 -------------------- 8 files changed, 132 insertions(+), 106 deletions(-) delete mode 100755 create_cache_key.sh create mode 100755 post_cache_action.sh create mode 100755 pre_cache_action.sh delete mode 100755 validate_pkgs.sh diff --git a/README.md b/README.md index 650f81d..941bf8f 100644 --- a/README.md +++ b/README.md @@ -25,7 +25,7 @@ Create a workflow `.yml` file in your repositories `.github/workflows` directory ### Outputs * `cache-hit` - A boolean value to indicate a cache was found for the packages requested. -* `package_version_list` - The packages and versions that are installed as a comma delimited list with colon delimit on the package version (i.e. \:,\:\,...). +* `package-version-list` - The packages and versions that are installed as a comma delimited list with colon delimit on the package version (i.e. \:,\:\,...). ### Cache scopes diff --git a/action.yml b/action.yml index 999ccb7..1903152 100644 --- a/action.yml +++ b/action.yml @@ -25,44 +25,27 @@ outputs: # This compound expression is needed because lhs can be empty. # Need to output true and false instead of true and nothing. value: ${{ steps.load-cache.outputs.cache-hit || false }} - package_version_list: + package-version-list: description: 'The packages and versions that are installed as a comma delimited list with colon delimit on the package version (i.e. ::).' - value: ${{ steps.get-package-versions.outputs.package_version_list }} + value: ${{ steps.post-cache.outputs.package-version-list }} runs: using: "composite" steps: - - name: Validate Packages - run: ${{ github.action_path }}/validate_pkgs.sh "${{ inputs.version }}" ${{ inputs.packages }} - shell: bash - - - name: Create Cache Key + - id: pre-cache run: | - ${{ github.action_path }}/create_cache_key.sh "${{ inputs.version }})" ${{ inputs.packages }} + ${{ github.action_path }}/pre_cache_action.sh ~/cache-apt-pkgs "${{ inputs.version }}" ${{ inputs.packages }} + echo "CACHE_KEY=$(cat ~/cache-apt-pkgs/cache_key.md5)" >> $GITHUB_ENV shell: bash - - name: Load Package Cache - id: load-cache + - id: load-cache uses: actions/cache@v2 with: path: ~/cache-apt-pkgs key: cache-apt-pkgs_${{ env.CACHE_KEY }} - - name: Load Packages + - id: post-cache run: | - if [ ! ${{ steps.load-cache.outputs.cache-hit }} ] || [ ${{ inputs.refresh }} ]; then - ${{ github.action_path }}/install_and_cache_pkgs.sh ~/cache-apt-pkgs ${{ inputs.packages }} - else - ${{ github.action_path }}/restore_pkgs.sh ~/cache-apt-pkgs / - fi - shell: bash - - - name: Get Package Versions - id: get-package-versions - run: | - output= - for package in ${{ inputs.packages }}; do - output=$output,$package:$(dpkg -s $package | grep Version | awk '{print $2}') - done - echo '::set-output name=package_version_list::output' + ${{ github.action_path }}/pre_cache_action.sh ~/cache-apt-pkgs "${{ inputs.version }}" ${{ inputs.packages }} + echo "::set-output name=package-version-list::$(cat ~/cache-apt-pkgs/manifest.log)" shell: bash diff --git a/create_cache_key.sh b/create_cache_key.sh deleted file mode 100755 index 3fd0536..0000000 --- a/create_cache_key.sh +++ /dev/null @@ -1,23 +0,0 @@ -#!/bin/bash - -# Fail on any error. -set -e - -version=$1 -packages=${@:2} - -echo "::group::Create Cache Key" - -# Remove package delimiters, sort (requires newline) and then convert back to inline list. -normalized_list=$(echo $packages | sed 's/[\s,]+/ /g' | tr ' ' '\n' | sort | tr '\n' ' ') -echo "::debug::Normalized package list is '$normalized_list'." - -value=$(echo $normalized_list @ $version) -echo "::debug::Value to hash is '$value'." - -key=$(echo $value | md5sum | /bin/cut -f1 -d' ') -echo "::debug::Value hashed as '$key'." - -echo "::endgroup::" - -echo "CACHE_KEY=$key" >> $GITHUB_ENV \ No newline at end of file diff --git a/install_and_cache_pkgs.sh b/install_and_cache_pkgs.sh index d5a7979..b6653cc 100755 --- a/install_and_cache_pkgs.sh +++ b/install_and_cache_pkgs.sh @@ -5,39 +5,39 @@ set -e # Directory that holds the cached packages. cache_dir=$1 + # List of the packages to use. packages="${@:2}" package_count=$(echo $packages | wc -w) -echo "::debug::Clean installing $package_count packages..." +echo "Clean installing and caching $package_count package(s).\n" +echo "Package list:" for package in $packages; do - echo "::debug::- $package" + echo "- $package" done -echo "::endgroup::" +echo "" mkdir -p $cache_dir -echo "::group::Update APT Package List" -sudo apt-get update -echo "::endgroup::" +echo -n "Updating APT package list..." +sudo apt-get update > /dev/null +echo "done." for package in $packages; do cache_filepath=$cache_dir/$package.tar.gz - echo "::group::Clean install $package" - sudo apt-get --yes install $package - echo "::endgroup::" + echo -n "Clean installing $package..." + sudo apt-get --yes install $package > /dev/null + echo "done." - echo "::group::Caching $package to $cache_filepath" + echo -n "Caching $package to $cache_filepath..." # Pipe all package files (no folders) to Tar. dpkg -L $package | - while IFS= read -r f; do - if test -f $f; then echo $f; fi; + while IFS= read -r f; do + if test -f $f; then echo ${f:1}; fi; #${f:1} removes the leading slash that Tar disallows done | - xargs tar -czf $cache_filepath -C / - echo "::endgroup::" + xargs tar -czf $cache_filepath -C / + echo "done." done -echo "::group::Finished" -echo "::debug::$(echo $packages | wc -w) package(s) installed and cached." -echo "::endgroup::" +echo "$(echo $packages | wc -w) package(s) installed and cached." diff --git a/post_cache_action.sh b/post_cache_action.sh new file mode 100755 index 0000000..f3d126a --- /dev/null +++ b/post_cache_action.sh @@ -0,0 +1,41 @@ +#!/bin/bash + +# Fail on any error. +set -e + +# Directory that holds the cached packages. +cache_dir=$1 + +# Root directory to untar the cached packages to. +# Typically filesystem root '/' but can be changed for testing. +cache_restore_root=$2 + +# Indicates that the cache was found. +cache_hit=$3 + +# Indicates that a refresh of the packages in the cache is required. +refresh=$4 + +# List of the packages to use. +packages="${@:5}" + +if [ ! $cache_hit ] || [ $refresh ]; then + ./install_and_cache_pkgs.sh ~/cache-apt-pkgs $packages +else + ./restore_pkgs.sh ~/cache-apt-pkgs $cache_restore_root +fi +echo "" + +echo "Creating package manifest..." +manifest= +for package in $packages; do + item=$package:$(dpkg -s $package | grep Version | awk '{print $2}') + echo "- $item" + manifest=$manifest$item, +done +# Remove trailing comma. +manifest=${manifest:0:-1} + +manifest_filepath="$cache_dir/manifest.log" +echo $manifest > $manifest_filepath +echo "Manifest written to $manifest_filepath" \ No newline at end of file diff --git a/pre_cache_action.sh b/pre_cache_action.sh new file mode 100755 index 0000000..13018c4 --- /dev/null +++ b/pre_cache_action.sh @@ -0,0 +1,56 @@ +#!/bin/bash + +# Directory that holds the cached packages. +cache_dir=$1 + +# Version of the cache to create or load. +version=$2 + +# List of the packages to use. +packages=${@:3} + +echo -n "Validating action arguments (version='$version', packages='$packages')..."; +echo $version | grep -o " " > /dev/null +if [ $? -eq 0 ]; then + echo "aborted." + echo "Version value '$version' cannot contain spaces." >&2 + exit 1 +fi +if [ "$packages" == "" ]; then + echo "aborted." + echo "Packages argument cannot be empty." >&2 + exit 2 +fi +echo "done." + +echo -n "Verifying packages..." +for package in $packages; do + apt-cache search ^$package$ | grep $package > /dev/null + if [ $? -ne 0 ]; then + echo "aborted." + echo "Package '$package' not found." >&2 + exit 3 + fi +done +echo "done." + +# Abort on any failure at this point. +set -e + +echo "Creating cache key..." + +# Remove package delimiters, sort (requires newline) and then convert back to inline list. +normalized_list=$(echo $packages | sed 's/[\s,]+/ /g' | tr ' ' '\n' | sort | tr '\n' ' ') +echo "- Normalized package list is '$normalized_list'." + +value=$(echo $normalized_list @ $version) +echo "- Value to hash is '$value'." + +key=$(echo $value | md5sum | /bin/cut -f1 -d' ') +echo "- Value hashed as '$key'." + +echo "done." + +key_filepath="$cache_dir/cache_key.md5" +echo $key > $key_filepath +echo "Hash value written to $key_filepath" diff --git a/restore_pkgs.sh b/restore_pkgs.sh index 0c5994c..762f19b 100755 --- a/restore_pkgs.sh +++ b/restore_pkgs.sh @@ -5,29 +5,27 @@ set -e # Directory that holds the cached packages. cache_dir=$1 + # Root directory to untar the cached packages to. # Typically filesystem root '/' but can be changed for testing. cache_restore_root=$2 + # List of the packages to use. packages="${@:3}" cache_filenames=$(ls -1 $cache_dir | sort) cache_filename_count=$(echo $cache_filenames | wc -w) -echo "::group::Found $cache_filename_count files in cache." +echo "Found $cache_filename_count packages in cache." for cache_filename in $cache_filenames; do - echo "::debug::$cache_filename" + echo "- $cache_filename" done -echo "::endgroup::" -echo "::group::Package Restore" +echo "Restoring cached packages..." for package in $packages; do cache_filepath=$cache_dir/$package.tar.gz - echo "::debug::Restoring package $package ($cache_filepath) from cache... " - sudo tar -xf $cache_filepath -C $cache_restore_root + echo "- $package ($cache_filepath)" + sudo tar -xf $cache_filepath -C $cache_restore_root > /dev/null done -echo "::endgroup::" -echo "::group::Finished" -echo "::debug::Action complete. $cache_filename_count package(s) restored." -echo "::endgroup::" \ No newline at end of file +echo "$cache_filename_count package(s) restored." \ No newline at end of file diff --git a/validate_pkgs.sh b/validate_pkgs.sh deleted file mode 100755 index 0b24b79..0000000 --- a/validate_pkgs.sh +++ /dev/null @@ -1,29 +0,0 @@ -#!/bin/bash - -version=$1 -packages=${@:2} - -echo "::group::Validate Action Arguments"; - -echo $version | grep -o " " > /dev/null -if [ $? -eq 0 ]; then - echo "::error::Aborted. Version value '$version' cannot contain spaces." >&2 - exit 1 -fi -echo "::debug::Version '$version' is valid." - -if [ "$packages" == "" ]; then - echo "::error::Aborted. Packages argument cannot be empty." >&2 - exit 2 -fi - -for package in $packages; do - apt-cache search ^$package$ | grep $package > /dev/null - if [ $? -ne 0 ]; then - echo "::error::Aborted. Package '$package' not found." >&2 - exit 3 - fi -done -echo "::debug::Packages '$packages' are valid." - -echo "::endgroup::" From 63a7ea6f1cb068b1787c1a6c0575bf69a1d6ba9d Mon Sep 17 00:00:00 2001 From: awalsh128 Date: Thu, 21 Oct 2021 21:03:30 -0700 Subject: [PATCH 02/22] Fix post cache action args. --- action.yml | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/action.yml b/action.yml index 1903152..25ccd90 100644 --- a/action.yml +++ b/action.yml @@ -46,6 +46,11 @@ runs: - id: post-cache run: | - ${{ github.action_path }}/pre_cache_action.sh ~/cache-apt-pkgs "${{ inputs.version }}" ${{ inputs.packages }} + ${{ github.action_path }}/post_cache_action.sh \ + ~/cache-apt-pkgs / \ + "${{ steps.load-cache.outputs.cache-hit }}" \ + "${{ inputs.refresh }}" \ + "${{ inputs.version }}" \ + ${{ inputs.packages }} echo "::set-output name=package-version-list::$(cat ~/cache-apt-pkgs/manifest.log)" shell: bash From 911023297bf00f8b6adf4a438aaaabd3334c16ee Mon Sep 17 00:00:00 2001 From: awalsh128 Date: Thu, 21 Oct 2021 21:12:42 -0700 Subject: [PATCH 03/22] Make cache directory first thing. --- pre_cache_action.sh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pre_cache_action.sh b/pre_cache_action.sh index 13018c4..51a5b78 100755 --- a/pre_cache_action.sh +++ b/pre_cache_action.sh @@ -9,6 +9,9 @@ version=$2 # List of the packages to use. packages=${@:3} +# Create cache directory so artifacts can be saved. +mkdir -p $cache_dir + echo -n "Validating action arguments (version='$version', packages='$packages')..."; echo $version | grep -o " " > /dev/null if [ $? -eq 0 ]; then From 38009341b056992405609bef47e22e7f58b8bb57 Mon Sep 17 00:00:00 2001 From: awalsh128 Date: Thu, 21 Oct 2021 21:13:01 -0700 Subject: [PATCH 04/22] Multiline pre cache for greater readability. --- action.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/action.yml b/action.yml index 25ccd90..e93785d 100644 --- a/action.yml +++ b/action.yml @@ -34,7 +34,10 @@ runs: steps: - id: pre-cache run: | - ${{ github.action_path }}/pre_cache_action.sh ~/cache-apt-pkgs "${{ inputs.version }}" ${{ inputs.packages }} + ${{ github.action_path }}/pre_cache_action.sh \ + ~/cache-apt-pkgs \ + "${{ inputs.version }}" \ + ${{ inputs.packages }} echo "CACHE_KEY=$(cat ~/cache-apt-pkgs/cache_key.md5)" >> $GITHUB_ENV shell: bash From 3742bed6feb8a16c71e101e95d047ef119d63a93 Mon Sep 17 00:00:00 2001 From: awalsh128 Date: Thu, 21 Oct 2021 21:13:23 -0700 Subject: [PATCH 05/22] Remove cache directory create now that it is done in pre cache. --- install_and_cache_pkgs.sh | 2 -- 1 file changed, 2 deletions(-) diff --git a/install_and_cache_pkgs.sh b/install_and_cache_pkgs.sh index b6653cc..b4a2481 100755 --- a/install_and_cache_pkgs.sh +++ b/install_and_cache_pkgs.sh @@ -17,8 +17,6 @@ for package in $packages; do done echo "" -mkdir -p $cache_dir - echo -n "Updating APT package list..." sudo apt-get update > /dev/null echo "done." From d6b942619734de6a44f72094f58f08898dd2dd3f Mon Sep 17 00:00:00 2001 From: awalsh128 Date: Thu, 21 Oct 2021 21:22:07 -0700 Subject: [PATCH 06/22] Update relative script directory. --- post_cache_action.sh | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/post_cache_action.sh b/post_cache_action.sh index f3d126a..f4e8caf 100755 --- a/post_cache_action.sh +++ b/post_cache_action.sh @@ -19,10 +19,12 @@ refresh=$4 # List of the packages to use. packages="${@:5}" +script_dir=$(dirname $0) + if [ ! $cache_hit ] || [ $refresh ]; then - ./install_and_cache_pkgs.sh ~/cache-apt-pkgs $packages + $script_dir/install_and_cache_pkgs.sh ~/cache-apt-pkgs $packages else - ./restore_pkgs.sh ~/cache-apt-pkgs $cache_restore_root + $script_dir/restore_pkgs.sh ~/cache-apt-pkgs $cache_restore_root fi echo "" @@ -33,9 +35,10 @@ for package in $packages; do echo "- $item" manifest=$manifest$item, done -# Remove trailing comma. -manifest=${manifest:0:-1} +echo "done." manifest_filepath="$cache_dir/manifest.log" -echo $manifest > $manifest_filepath -echo "Manifest written to $manifest_filepath" \ No newline at end of file +echo -n "Writing manifest to $manifest_filepath..." +# Remove trailing comma. +echo ${manifest:0:-1} > $manifest_filepath +echo "done." \ No newline at end of file From 95b1f6f538acc73bdeea452a6acc8c91c577df59 Mon Sep 17 00:00:00 2001 From: awalsh128 Date: Thu, 21 Oct 2021 21:30:33 -0700 Subject: [PATCH 07/22] Remove extraneous arg. --- action.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/action.yml b/action.yml index e93785d..6eccab2 100644 --- a/action.yml +++ b/action.yml @@ -50,10 +50,10 @@ runs: - id: post-cache run: | ${{ github.action_path }}/post_cache_action.sh \ - ~/cache-apt-pkgs / \ + ~/cache-apt-pkgs \ + / \ "${{ steps.load-cache.outputs.cache-hit }}" \ "${{ inputs.refresh }}" \ - "${{ inputs.version }}" \ ${{ inputs.packages }} echo "::set-output name=package-version-list::$(cat ~/cache-apt-pkgs/manifest.log)" shell: bash From dec2761421883772a6aade025cddf4b9c106d3b0 Mon Sep 17 00:00:00 2001 From: awalsh128 Date: Thu, 21 Oct 2021 21:30:49 -0700 Subject: [PATCH 08/22] Remove blank line on reporting. --- install_and_cache_pkgs.sh | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/install_and_cache_pkgs.sh b/install_and_cache_pkgs.sh index b4a2481..4ca95ba 100755 --- a/install_and_cache_pkgs.sh +++ b/install_and_cache_pkgs.sh @@ -10,12 +10,11 @@ cache_dir=$1 packages="${@:2}" package_count=$(echo $packages | wc -w) -echo "Clean installing and caching $package_count package(s).\n" +echo "Clean installing and caching $package_count package(s)." echo "Package list:" for package in $packages; do echo "- $package" done -echo "" echo -n "Updating APT package list..." sudo apt-get update > /dev/null From 4e7f5ac971fd5216688f28c0f2555f9acfaf2513 Mon Sep 17 00:00:00 2001 From: awalsh128 Date: Thu, 21 Oct 2021 21:39:47 -0700 Subject: [PATCH 09/22] Fix conditionals for install and restore. --- post_cache_action.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/post_cache_action.sh b/post_cache_action.sh index f4e8caf..898441f 100755 --- a/post_cache_action.sh +++ b/post_cache_action.sh @@ -21,7 +21,7 @@ packages="${@:5}" script_dir=$(dirname $0) -if [ ! $cache_hit ] || [ $refresh ]; then +if [ "$cache_hit" == false ] || [ "$refresh" == true ]; then $script_dir/install_and_cache_pkgs.sh ~/cache-apt-pkgs $packages else $script_dir/restore_pkgs.sh ~/cache-apt-pkgs $cache_restore_root From 2516d0fc192457ba817d74bcc04ec4b57950d1c1 Mon Sep 17 00:00:00 2001 From: awalsh128 Date: Thu, 21 Oct 2021 21:43:24 -0700 Subject: [PATCH 10/22] Minor edit to reporting. --- restore_pkgs.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/restore_pkgs.sh b/restore_pkgs.sh index 762f19b..338a1b1 100755 --- a/restore_pkgs.sh +++ b/restore_pkgs.sh @@ -21,11 +21,12 @@ for cache_filename in $cache_filenames; do echo "- $cache_filename" done -echo "Restoring cached packages..." +echo -n "Restoring cached packages..." for package in $packages; do cache_filepath=$cache_dir/$package.tar.gz echo "- $package ($cache_filepath)" sudo tar -xf $cache_filepath -C $cache_restore_root > /dev/null done +echo "done." echo "$cache_filename_count package(s) restored." \ No newline at end of file From b67439fdd60a4fae20f32dcc7ddab146669c254c Mon Sep 17 00:00:00 2001 From: awalsh128 Date: Thu, 21 Oct 2021 21:45:37 -0700 Subject: [PATCH 11/22] Only search for archives in cache directory. --- restore_pkgs.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/restore_pkgs.sh b/restore_pkgs.sh index 338a1b1..c78b232 100755 --- a/restore_pkgs.sh +++ b/restore_pkgs.sh @@ -13,7 +13,8 @@ cache_restore_root=$2 # List of the packages to use. packages="${@:3}" -cache_filenames=$(ls -1 $cache_dir | sort) +# Only search for archived results. Manifest and cache key also live here. +cache_filenames=$(ls -1 $cache_dir | grep .tar.gz | sort) cache_filename_count=$(echo $cache_filenames | wc -w) echo "Found $cache_filename_count packages in cache." From 6d2730c8bf51ad1cce6a5683a89e26a624652da7 Mon Sep 17 00:00:00 2001 From: awalsh128 Date: Thu, 21 Oct 2021 22:01:57 -0700 Subject: [PATCH 12/22] Fix manifest location. --- install_and_cache_pkgs.sh | 13 ++++++++++--- post_cache_action.sh | 6 ------ restore_pkgs.sh | 9 +-------- 3 files changed, 11 insertions(+), 17 deletions(-) diff --git a/install_and_cache_pkgs.sh b/install_and_cache_pkgs.sh index 4ca95ba..18d6ce0 100755 --- a/install_and_cache_pkgs.sh +++ b/install_and_cache_pkgs.sh @@ -20,14 +20,16 @@ echo -n "Updating APT package list..." sudo apt-get update > /dev/null echo "done." +echo "Clean installing and caching $(echo $packages | wc -w) packages..." for package in $packages; do cache_filepath=$cache_dir/$package.tar.gz - echo -n "Clean installing $package..." + echo "- $package" + echo -n " Installing..." sudo apt-get --yes install $package > /dev/null echo "done." - echo -n "Caching $package to $cache_filepath..." + echo -n " Caching to $cache_filepath..." # Pipe all package files (no folders) to Tar. dpkg -L $package | while IFS= read -r f; do @@ -36,5 +38,10 @@ for package in $packages; do xargs tar -czf $cache_filepath -C / echo "done." done +echo "done." -echo "$(echo $packages | wc -w) package(s) installed and cached." +manifest_filepath="$cache_dir/manifest.log" +echo -n "Writing package manifest to $manifest_filepath..." +# Remove trailing comma. +echo ${manifest:0:-1} > $manifest_filepath +echo "done." \ No newline at end of file diff --git a/post_cache_action.sh b/post_cache_action.sh index 898441f..6f2c8b2 100755 --- a/post_cache_action.sh +++ b/post_cache_action.sh @@ -36,9 +36,3 @@ for package in $packages; do manifest=$manifest$item, done echo "done." - -manifest_filepath="$cache_dir/manifest.log" -echo -n "Writing manifest to $manifest_filepath..." -# Remove trailing comma. -echo ${manifest:0:-1} > $manifest_filepath -echo "done." \ No newline at end of file diff --git a/restore_pkgs.sh b/restore_pkgs.sh index c78b232..ad9e223 100755 --- a/restore_pkgs.sh +++ b/restore_pkgs.sh @@ -17,17 +17,10 @@ packages="${@:3}" cache_filenames=$(ls -1 $cache_dir | grep .tar.gz | sort) cache_filename_count=$(echo $cache_filenames | wc -w) -echo "Found $cache_filename_count packages in cache." +echo -n "Restoring $cache_filename_count packages from cache..." for cache_filename in $cache_filenames; do - echo "- $cache_filename" -done - -echo -n "Restoring cached packages..." -for package in $packages; do cache_filepath=$cache_dir/$package.tar.gz echo "- $package ($cache_filepath)" sudo tar -xf $cache_filepath -C $cache_restore_root > /dev/null done echo "done." - -echo "$cache_filename_count package(s) restored." \ No newline at end of file From 9ca1c60417b9c8c4b75c9f4412d01104318a2874 Mon Sep 17 00:00:00 2001 From: awalsh128 Date: Thu, 21 Oct 2021 22:15:05 -0700 Subject: [PATCH 13/22] Add more reporting to restore phase. --- restore_pkgs.sh | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/restore_pkgs.sh b/restore_pkgs.sh index ad9e223..8b83b91 100755 --- a/restore_pkgs.sh +++ b/restore_pkgs.sh @@ -13,14 +13,23 @@ cache_restore_root=$2 # List of the packages to use. packages="${@:3}" -# Only search for archived results. Manifest and cache key also live here. -cache_filenames=$(ls -1 $cache_dir | grep .tar.gz | sort) -cache_filename_count=$(echo $cache_filenames | wc -w) - -echo -n "Restoring $cache_filename_count packages from cache..." +cache_filenames=$(ls -1 $cache_dir | sort) +echo "Found $(echo $cache_filenames | wc -w) files in the cache." for cache_filename in $cache_filenames; do - cache_filepath=$cache_dir/$package.tar.gz - echo "- $package ($cache_filepath)" - sudo tar -xf $cache_filepath -C $cache_restore_root > /dev/null + echo "- $(basename $cache_filename)" +done + +# Only search for archived results. Manifest and cache key also live here. +cache_pkg_filenames=$(ls -1 $cache_dir/*.tar.gz | sort) +echo "Found $(echo $cache_filenames | wc -w) packages in the cache." +for cache_pkg_filename in $cache_pkg_filenames; do + echo "- $(basename $cache_pkg_filename)" +done + +echo "Restoring $cache_filename_count packages from cache..." +for cache_pkg_filename in $cache_pkg_filenames; do + cache_pkg_filepath=$cache_dir/$package.tar.gz + echo "- $package ($(basename $cache_pkg_filepath))" + sudo tar -xf $cache_pkg_filepath -C $cache_restore_root > /dev/null done echo "done." From 13b8ebb8f746d1858e3dd7799214f1e23c6d4927 Mon Sep 17 00:00:00 2001 From: awalsh128 Date: Thu, 21 Oct 2021 22:16:49 -0700 Subject: [PATCH 14/22] Fix package number reported. --- restore_pkgs.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/restore_pkgs.sh b/restore_pkgs.sh index 8b83b91..f687441 100755 --- a/restore_pkgs.sh +++ b/restore_pkgs.sh @@ -21,7 +21,7 @@ done # Only search for archived results. Manifest and cache key also live here. cache_pkg_filenames=$(ls -1 $cache_dir/*.tar.gz | sort) -echo "Found $(echo $cache_filenames | wc -w) packages in the cache." +echo "Found $(echo $cache_pkg_filenames | wc -w) packages in the cache." for cache_pkg_filename in $cache_pkg_filenames; do echo "- $(basename $cache_pkg_filename)" done From 1decb12863a97bfbd6cacbac26342b4bdfafb61b Mon Sep 17 00:00:00 2001 From: awalsh128 Date: Thu, 21 Oct 2021 22:27:23 -0700 Subject: [PATCH 15/22] Filter packages correctly. --- restore_pkgs.sh | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/restore_pkgs.sh b/restore_pkgs.sh index f687441..0aca493 100755 --- a/restore_pkgs.sh +++ b/restore_pkgs.sh @@ -10,26 +10,24 @@ cache_dir=$1 # Typically filesystem root '/' but can be changed for testing. cache_restore_root=$2 -# List of the packages to use. -packages="${@:3}" - -cache_filenames=$(ls -1 $cache_dir | sort) -echo "Found $(echo $cache_filenames | wc -w) files in the cache." -for cache_filename in $cache_filenames; do - echo "- $(basename $cache_filename)" +cache_filepaths=$(ls -1 $cache_dir | sort) +echo "Found $(echo $cache_filepaths | wc -w) files in the cache." +for cache_filepath in $cache_filepaths; do + echo "- $(basename $cache_filepath)" done # Only search for archived results. Manifest and cache key also live here. -cache_pkg_filenames=$(ls -1 $cache_dir/*.tar.gz | sort) -echo "Found $(echo $cache_pkg_filenames | wc -w) packages in the cache." -for cache_pkg_filename in $cache_pkg_filenames; do - echo "- $(basename $cache_pkg_filename)" +cache_pkg_filepaths=$(ls -1 $cache_dir/*.tar.gz | sort) +cache_pkg_filecount=$(echo $cache_pkg_filepaths | wc -w) +echo "Found $cache_pkg_filecount packages in the cache." +for cache_pkg_filepath in $cache_pkg_filepaths; do + echo "- $(basename $cache_pkg_filepath)" done -echo "Restoring $cache_filename_count packages from cache..." -for cache_pkg_filename in $cache_pkg_filenames; do - cache_pkg_filepath=$cache_dir/$package.tar.gz - echo "- $package ($(basename $cache_pkg_filepath))" +echo "Restoring $cache_pkg_filecount packages from cache..." +for cache_pkg_filepath in $cache_pkg_filepaths; do + package=$(basename $cache_pkg_filepath | awk -F. '{print $1}') + echo "- $package" sudo tar -xf $cache_pkg_filepath -C $cache_restore_root > /dev/null done echo "done." From 125244158b10b56a41917ca3c75b05eeb6349c86 Mon Sep 17 00:00:00 2001 From: awalsh128 Date: Thu, 21 Oct 2021 22:29:23 -0700 Subject: [PATCH 16/22] Remove package manifest write for restores. --- post_cache_action.sh | 9 --------- 1 file changed, 9 deletions(-) diff --git a/post_cache_action.sh b/post_cache_action.sh index 6f2c8b2..f12db41 100755 --- a/post_cache_action.sh +++ b/post_cache_action.sh @@ -27,12 +27,3 @@ else $script_dir/restore_pkgs.sh ~/cache-apt-pkgs $cache_restore_root fi echo "" - -echo "Creating package manifest..." -manifest= -for package in $packages; do - item=$package:$(dpkg -s $package | grep Version | awk '{print $2}') - echo "- $item" - manifest=$manifest$item, -done -echo "done." From dca3d33521d77babff5049d12cf48101e77b80ff Mon Sep 17 00:00:00 2001 From: awalsh128 Date: Thu, 21 Oct 2021 22:42:51 -0700 Subject: [PATCH 17/22] Get rid of package variables. --- restore_pkgs.sh | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/restore_pkgs.sh b/restore_pkgs.sh index 0aca493..63b342d 100755 --- a/restore_pkgs.sh +++ b/restore_pkgs.sh @@ -16,18 +16,18 @@ for cache_filepath in $cache_filepaths; do echo "- $(basename $cache_filepath)" done +echo "Reading from manifest..." +for logline in $(cat $cache_dir/manifest.log | tr ',' '\n' ); do + echo "- $(echo $logline | tr ',' ' ')" +done + # Only search for archived results. Manifest and cache key also live here. cache_pkg_filepaths=$(ls -1 $cache_dir/*.tar.gz | sort) cache_pkg_filecount=$(echo $cache_pkg_filepaths | wc -w) -echo "Found $cache_pkg_filecount packages in the cache." -for cache_pkg_filepath in $cache_pkg_filepaths; do - echo "- $(basename $cache_pkg_filepath)" -done - echo "Restoring $cache_pkg_filecount packages from cache..." -for cache_pkg_filepath in $cache_pkg_filepaths; do - package=$(basename $cache_pkg_filepath | awk -F. '{print $1}') - echo "- $package" +for cache_pkg_filepath in $cache_pkg_filepaths; do + echo -n "- $(basename $cache_pkg_filepath) restoring..." sudo tar -xf $cache_pkg_filepath -C $cache_restore_root > /dev/null + echo "done." done echo "done." From db1f7473f649372d05eee645d6ae41666ccadedc Mon Sep 17 00:00:00 2001 From: awalsh128 Date: Thu, 21 Oct 2021 22:44:51 -0700 Subject: [PATCH 18/22] Separate out version on manifest reporting. --- restore_pkgs.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/restore_pkgs.sh b/restore_pkgs.sh index 63b342d..6d273c1 100755 --- a/restore_pkgs.sh +++ b/restore_pkgs.sh @@ -18,7 +18,7 @@ done echo "Reading from manifest..." for logline in $(cat $cache_dir/manifest.log | tr ',' '\n' ); do - echo "- $(echo $logline | tr ',' ' ')" + echo "- $(echo $logline | tr ':' ' ')" done # Only search for archived results. Manifest and cache key also live here. From 8f2c275875df45814637564fe0e50a0e1bff5ad3 Mon Sep 17 00:00:00 2001 From: awalsh128 Date: Thu, 21 Oct 2021 23:04:42 -0700 Subject: [PATCH 19/22] Remove refresh feature. --- README.md | 1 - action.yml | 1 - post_cache_action.sh | 7 ++----- 3 files changed, 2 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 941bf8f..927e93a 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,6 @@ Create a workflow `.yml` file in your repositories `.github/workflows` directory * `packages` - Space delimited list of packages to install. * `version` - Version of cache to load. Each version will have its own cache. Note, all characters except spaces are allowed. -* `refresh` - Refresh / upgrade the packages in the same cache. ### Outputs diff --git a/action.yml b/action.yml index 6eccab2..e717de5 100644 --- a/action.yml +++ b/action.yml @@ -53,7 +53,6 @@ runs: ~/cache-apt-pkgs \ / \ "${{ steps.load-cache.outputs.cache-hit }}" \ - "${{ inputs.refresh }}" \ ${{ inputs.packages }} echo "::set-output name=package-version-list::$(cat ~/cache-apt-pkgs/manifest.log)" shell: bash diff --git a/post_cache_action.sh b/post_cache_action.sh index f12db41..54d7cec 100755 --- a/post_cache_action.sh +++ b/post_cache_action.sh @@ -13,15 +13,12 @@ cache_restore_root=$2 # Indicates that the cache was found. cache_hit=$3 -# Indicates that a refresh of the packages in the cache is required. -refresh=$4 - # List of the packages to use. -packages="${@:5}" +packages="${@:4}" script_dir=$(dirname $0) -if [ "$cache_hit" == false ] || [ "$refresh" == true ]; then +if [ "$cache_hit" == false ]; then $script_dir/install_and_cache_pkgs.sh ~/cache-apt-pkgs $packages else $script_dir/restore_pkgs.sh ~/cache-apt-pkgs $cache_restore_root From edd1138fdda09dd2a1ca9ed0a67fa354f3f3724b Mon Sep 17 00:00:00 2001 From: awalsh128 Date: Thu, 21 Oct 2021 23:28:06 -0700 Subject: [PATCH 20/22] Write out manifest. --- install_and_cache_pkgs.sh | 4 ++++ restore_pkgs.sh | 1 + 2 files changed, 5 insertions(+) diff --git a/install_and_cache_pkgs.sh b/install_and_cache_pkgs.sh index 18d6ce0..d402901 100755 --- a/install_and_cache_pkgs.sh +++ b/install_and_cache_pkgs.sh @@ -42,6 +42,10 @@ echo "done." manifest_filepath="$cache_dir/manifest.log" echo -n "Writing package manifest to $manifest_filepath..." +manifest= +for package in $packages; do + manifest=$manifest,$package:$(dpkg -s $package | grep Version | awk '{print $2}') +done # Remove trailing comma. echo ${manifest:0:-1} > $manifest_filepath echo "done." \ No newline at end of file diff --git a/restore_pkgs.sh b/restore_pkgs.sh index 6d273c1..ab87879 100755 --- a/restore_pkgs.sh +++ b/restore_pkgs.sh @@ -20,6 +20,7 @@ echo "Reading from manifest..." for logline in $(cat $cache_dir/manifest.log | tr ',' '\n' ); do echo "- $(echo $logline | tr ':' ' ')" done +echo "done." # Only search for archived results. Manifest and cache key also live here. cache_pkg_filepaths=$(ls -1 $cache_dir/*.tar.gz | sort) From 58be009328c3bac429557a4fe194b94ddd1c13cc Mon Sep 17 00:00:00 2001 From: awalsh128 Date: Fri, 22 Oct 2021 00:12:56 -0700 Subject: [PATCH 21/22] Work around cache-hit bug in cache action. --- post_cache_action.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/post_cache_action.sh b/post_cache_action.sh index 54d7cec..5503013 100755 --- a/post_cache_action.sh +++ b/post_cache_action.sh @@ -18,9 +18,9 @@ packages="${@:4}" script_dir=$(dirname $0) -if [ "$cache_hit" == false ]; then - $script_dir/install_and_cache_pkgs.sh ~/cache-apt-pkgs $packages -else +if [ "$cache_hit" == true ]; then $script_dir/restore_pkgs.sh ~/cache-apt-pkgs $cache_restore_root +else + $script_dir/install_and_cache_pkgs.sh ~/cache-apt-pkgs $packages fi echo "" From b80ada032932cd3828bec7659ef3ff158484ebe2 Mon Sep 17 00:00:00 2001 From: awalsh128 Date: Fri, 22 Oct 2021 00:16:17 -0700 Subject: [PATCH 22/22] Move trailing comma for manifest list. --- install_and_cache_pkgs.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/install_and_cache_pkgs.sh b/install_and_cache_pkgs.sh index d402901..bbf54dc 100755 --- a/install_and_cache_pkgs.sh +++ b/install_and_cache_pkgs.sh @@ -44,7 +44,7 @@ manifest_filepath="$cache_dir/manifest.log" echo -n "Writing package manifest to $manifest_filepath..." manifest= for package in $packages; do - manifest=$manifest,$package:$(dpkg -s $package | grep Version | awk '{print $2}') + manifest=$manifest$package:$(dpkg -s $package | grep Version | awk '{print $2}'), done # Remove trailing comma. echo ${manifest:0:-1} > $manifest_filepath