From d3f2f7ce23aba65a543a1bf23b324ceaf21370c1 Mon Sep 17 00:00:00 2001 From: awalsh128 Date: Sat, 16 Oct 2021 11:15:06 -0700 Subject: [PATCH 01/24] Fix conditionals. --- action.yml | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/action.yml b/action.yml index 1675e0c..fb76c9e 100644 --- a/action.yml +++ b/action.yml @@ -34,12 +34,10 @@ runs: path: ~/cache-apt-pkgs key: cache-apt-pkgs_${{ hashFiles('/tmp/package_list.txt') }} - - name: Install and Cache Packages - if: steps.load-pkg-cache.outputs.cache-hit != 'true' - run: ${{ github.action_path }}/install_and_cache.sh ~/cache-apt-pkgs ${{ inputs.packages }} - shell: bash - - - name: Restore Cached Packages - if: steps.load-pkg-cache.outputs.cache-hit != 'true' - run: ${{ github.action_path }}/run.sh ~/cache-apt-pkgs / + - name: Load Packages + run: | + if [ ${{ steps.load-pkg-cache.outputs.cache-hit }} == "true" ]; then + ${{ github.action_path }}/install_and_cache.sh ~/cache-apt-pkgs ${{ inputs.packages }} + else + ${{ github.action_path }}/run.sh ~/cache-apt-pkgs / shell: bash From 132be8a4507c284e847abd3fbb2f7a35124f8e14 Mon Sep 17 00:00:00 2001 From: awalsh128 Date: Sat, 16 Oct 2021 11:19:36 -0700 Subject: [PATCH 02/24] More fixes. Gotta love not having tests. directly for GitHub actions. --- action.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/action.yml b/action.yml index fb76c9e..b91c667 100644 --- a/action.yml +++ b/action.yml @@ -36,8 +36,9 @@ runs: - name: Load Packages run: | - if [ ${{ steps.load-pkg-cache.outputs.cache-hit }} == "true" ]; then + if [ ${{ steps.load-pkg-cache.outputs.cache-hit }} ]; then ${{ github.action_path }}/install_and_cache.sh ~/cache-apt-pkgs ${{ inputs.packages }} else ${{ github.action_path }}/run.sh ~/cache-apt-pkgs / + fi shell: bash From c29b0d7f9aad4d97f6842f1b6109ad6200623b42 Mon Sep 17 00:00:00 2001 From: awalsh128 Date: Sat, 16 Oct 2021 11:22:48 -0700 Subject: [PATCH 03/24] Fix script reference. --- action.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/action.yml b/action.yml index b91c667..eba9cd5 100644 --- a/action.yml +++ b/action.yml @@ -37,8 +37,8 @@ runs: - name: Load Packages run: | if [ ${{ steps.load-pkg-cache.outputs.cache-hit }} ]; then - ${{ github.action_path }}/install_and_cache.sh ~/cache-apt-pkgs ${{ inputs.packages }} + ${{ github.action_path }}/restore_pkgs.sh ~/cache-apt-pkgs / else - ${{ github.action_path }}/run.sh ~/cache-apt-pkgs / + ${{ github.action_path }}/install_and_cache.sh ~/cache-apt-pkgs ${{ inputs.packages }} fi shell: bash From d88f9cf2093b16f2ac25736be6780c7ccdffcf07 Mon Sep 17 00:00:00 2001 From: awalsh128 Date: Sat, 16 Oct 2021 11:25:42 -0700 Subject: [PATCH 04/24] Another script name fix. :( --- action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/action.yml b/action.yml index eba9cd5..c9ce7f2 100644 --- a/action.yml +++ b/action.yml @@ -39,6 +39,6 @@ runs: if [ ${{ steps.load-pkg-cache.outputs.cache-hit }} ]; then ${{ github.action_path }}/restore_pkgs.sh ~/cache-apt-pkgs / else - ${{ github.action_path }}/install_and_cache.sh ~/cache-apt-pkgs ${{ inputs.packages }} + ${{ github.action_path }}/install_and_cache_pkgs.sh ~/cache-apt-pkgs ${{ inputs.packages }} fi shell: bash From 7dfe2c32f2db53e259b3fd13d058b1f4f5b93e7c Mon Sep 17 00:00:00 2001 From: awalsh128 Date: Sat, 16 Oct 2021 11:34:03 -0700 Subject: [PATCH 05/24] Add versioning. --- action.yml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/action.yml b/action.yml index c9ce7f2..7acc611 100644 --- a/action.yml +++ b/action.yml @@ -10,6 +10,10 @@ inputs: description: 'Space delimited list of packages to install.' required: true default: '' + version: + description: 'Version will create a new cache and install packages.' + required: false + default: '' outputs: cache-hit: @@ -24,7 +28,7 @@ runs: shell: bash - name: Create Cache Key - run: echo ${{ inputs.packages }} | sed 's/[\s,]+/\n/g' | sort > /tmp/package_list.txt + run: echo ${{ inputs.packages }} "cache-apt-pkgs-version:${{ inputs.version }}" | sed 's/[\s,]+/\n/g' | sort > /tmp/package_list.txt shell: bash - name: Load Package Cache From 6dbaadfc1e21049b91dcf31df6b6bbc8e049d0ea Mon Sep 17 00:00:00 2001 From: awalsh128 Date: Sat, 16 Oct 2021 11:34:14 -0700 Subject: [PATCH 06/24] Fix script syntax. --- install_and_cache_pkgs.sh | 2 +- restore_pkgs.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/install_and_cache_pkgs.sh b/install_and_cache_pkgs.sh index e73b978..7f1b90d 100755 --- a/install_and_cache_pkgs.sh +++ b/install_and_cache_pkgs.sh @@ -19,6 +19,6 @@ for package in $packages; do if test -f $f; then echo $f; fi; done | xargs tar -czf $cache_filepath -C / -fi +done echo "Action complete. ${#packages[@]} package(s) installed and cached." diff --git a/restore_pkgs.sh b/restore_pkgs.sh index c83c6ea..4e569d0 100755 --- a/restore_pkgs.sh +++ b/restore_pkgs.sh @@ -10,6 +10,6 @@ for cache_filepath in $(ls $cache_dir); do echo "* Restoring $package from cache $cache_filepath... " sudo tar -xf $cache_filepath -C $cache_restore_root sudo apt-get --yes --only-upgrade install $package -fi +done echo "Action complete. ${#packages[@]} package(s) restored." From 2780a91363b55ad03cf5005981cdfaf141bee8db Mon Sep 17 00:00:00 2001 From: awalsh128 Date: Sat, 16 Oct 2021 12:48:07 -0700 Subject: [PATCH 07/24] Change file pathing to see if hashFiles works. --- action.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/action.yml b/action.yml index 7acc611..0cfa066 100644 --- a/action.yml +++ b/action.yml @@ -28,7 +28,7 @@ runs: shell: bash - name: Create Cache Key - run: echo ${{ inputs.packages }} "cache-apt-pkgs-version:${{ inputs.version }}" | sed 's/[\s,]+/\n/g' | sort > /tmp/package_list.txt + run: echo ${{ inputs.packages }} "cache-apt-pkgs-version:${{ inputs.version }}" | sed 's/[\s,]+/\n/g' | sort > package_list.txt shell: bash - name: Load Package Cache @@ -36,7 +36,7 @@ runs: uses: actions/cache@v2 with: path: ~/cache-apt-pkgs - key: cache-apt-pkgs_${{ hashFiles('/tmp/package_list.txt') }} + key: cache-apt-pkgs_${{ hashFiles('package_list.txt') }} - name: Load Packages run: | From 93efeeaebb9a4730865c1811044ef95707aefe43 Mon Sep 17 00:00:00 2001 From: awalsh128 Date: Sat, 16 Oct 2021 12:58:23 -0700 Subject: [PATCH 08/24] Fix package count reporting. --- restore_pkgs.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/restore_pkgs.sh b/restore_pkgs.sh index 4e569d0..8231b54 100755 --- a/restore_pkgs.sh +++ b/restore_pkgs.sh @@ -7,9 +7,9 @@ cache_dir=$1 cache_restore_root=$2 for cache_filepath in $(ls $cache_dir); do - echo "* Restoring $package from cache $cache_filepath... " + echo "* Restoring $cache_filepath from cache... " sudo tar -xf $cache_filepath -C $cache_restore_root sudo apt-get --yes --only-upgrade install $package done -echo "Action complete. ${#packages[@]} package(s) restored." +echo "Action complete. $(ls -l $cache_dir | wc -l) package(s) restored." From 91e3a981334ab83048081f0b8f0e5a2676fb069e Mon Sep 17 00:00:00 2001 From: awalsh128 Date: Sat, 16 Oct 2021 13:00:45 -0700 Subject: [PATCH 09/24] Update packages after restore. --- restore_pkgs.sh | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/restore_pkgs.sh b/restore_pkgs.sh index 8231b54..c3bfe14 100755 --- a/restore_pkgs.sh +++ b/restore_pkgs.sh @@ -8,8 +8,9 @@ cache_restore_root=$2 for cache_filepath in $(ls $cache_dir); do echo "* Restoring $cache_filepath from cache... " - sudo tar -xf $cache_filepath -C $cache_restore_root - sudo apt-get --yes --only-upgrade install $package + sudo tar -xf $cache_filepath -C $cache_restore_root done +# Update all packages. +sudo apt-get --yes --only-upgrade install echo "Action complete. $(ls -l $cache_dir | wc -l) package(s) restored." From dcae10197c7354bafd8dc6e9c8ddc252fa96ed93 Mon Sep 17 00:00:00 2001 From: awalsh128 Date: Sat, 16 Oct 2021 13:10:59 -0700 Subject: [PATCH 10/24] Update output to emit false. --- action.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/action.yml b/action.yml index 0cfa066..bf2ded5 100644 --- a/action.yml +++ b/action.yml @@ -18,7 +18,7 @@ inputs: outputs: cache-hit: description: 'A boolean value to indicate a cache was found for the packages requested.' - value: ${{ steps.load-pkg-cache.outputs.cache-hit }} + value: ${{ steps.load-cache.outputs.cache-hit || "false" }} runs: using: "composite" @@ -32,7 +32,7 @@ runs: shell: bash - name: Load Package Cache - id: load-pkg-cache + id: load-cache uses: actions/cache@v2 with: path: ~/cache-apt-pkgs @@ -40,7 +40,7 @@ runs: - name: Load Packages run: | - if [ ${{ steps.load-pkg-cache.outputs.cache-hit }} ]; then + if [ ${{ steps.load-cache.outputs.cache-hit }} ]; then ${{ github.action_path }}/restore_pkgs.sh ~/cache-apt-pkgs / else ${{ github.action_path }}/install_and_cache_pkgs.sh ~/cache-apt-pkgs ${{ inputs.packages }} From 2530518f4a97e8e3d62e8a776e33c513f7d09df8 Mon Sep 17 00:00:00 2001 From: awalsh128 Date: Sat, 16 Oct 2021 13:16:36 -0700 Subject: [PATCH 11/24] Try again. --- action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/action.yml b/action.yml index bf2ded5..2b4a3bc 100644 --- a/action.yml +++ b/action.yml @@ -18,7 +18,7 @@ inputs: outputs: cache-hit: description: 'A boolean value to indicate a cache was found for the packages requested.' - value: ${{ steps.load-cache.outputs.cache-hit || "false" }} + value: ${{ steps.load-cache.outputs.cache-hit || false }} runs: using: "composite" From c014946be04b6d0ccd5c8481f48b8c39c9572365 Mon Sep 17 00:00:00 2001 From: awalsh128 Date: Sat, 16 Oct 2021 21:17:41 -0700 Subject: [PATCH 12/24] Added coment to esoteric expression. --- action.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/action.yml b/action.yml index 2b4a3bc..6d87649 100644 --- a/action.yml +++ b/action.yml @@ -18,6 +18,8 @@ inputs: outputs: cache-hit: description: 'A boolean value to indicate a cache was found for the packages requested.' + # 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 }} runs: From 6c13cf414f2f2f5de4b7e3da4dfb9f45de1bbcb2 Mon Sep 17 00:00:00 2001 From: awalsh128 Date: Sat, 16 Oct 2021 21:17:55 -0700 Subject: [PATCH 13/24] Fail script on any error. --- install_and_cache_pkgs.sh | 3 +++ restore_pkgs.sh | 3 +++ validate_pkgs.sh | 3 +++ 3 files changed, 9 insertions(+) diff --git a/install_and_cache_pkgs.sh b/install_and_cache_pkgs.sh index 7f1b90d..37fda4f 100755 --- a/install_and_cache_pkgs.sh +++ b/install_and_cache_pkgs.sh @@ -1,5 +1,8 @@ #!/bin/bash +# Fail on any error. +set -e + # Directory that holds the cached packages. cache_dir=$1 # List of the packages to use. diff --git a/restore_pkgs.sh b/restore_pkgs.sh index c3bfe14..cfd292e 100755 --- a/restore_pkgs.sh +++ b/restore_pkgs.sh @@ -1,5 +1,8 @@ #!/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. diff --git a/validate_pkgs.sh b/validate_pkgs.sh index 09e3e52..3b63a70 100755 --- a/validate_pkgs.sh +++ b/validate_pkgs.sh @@ -1,5 +1,8 @@ #!/bin/bash +# Fail on any error. +set -e + packages=$1 echo -n "* Validating action arguments... "; From e558e74c19c0ef40fd89c3d5fafe36578a903106 Mon Sep 17 00:00:00 2001 From: awalsh128 Date: Sat, 16 Oct 2021 21:23:27 -0700 Subject: [PATCH 14/24] Full qualify paths. --- restore_pkgs.sh | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/restore_pkgs.sh b/restore_pkgs.sh index cfd292e..2e61d70 100755 --- a/restore_pkgs.sh +++ b/restore_pkgs.sh @@ -9,11 +9,16 @@ cache_dir=$1 # Typically filesystem root '/' but can be changed for testing. cache_restore_root=$2 -for cache_filepath in $(ls $cache_dir); do +cache_filenames=$(ls -1 $cache_dir | sort) +echo "* Found ${#cache_filenames[@]} files in cache..." +echo $cache_filenames + +for cache_filename in $cache_filenames; do + cache_filepath=$cache_dir/$cache_filename echo "* Restoring $cache_filepath from cache... " sudo tar -xf $cache_filepath -C $cache_restore_root done # Update all packages. sudo apt-get --yes --only-upgrade install -echo "Action complete. $(ls -l $cache_dir | wc -l) package(s) restored." +echo "Action complete. $(echo $cache_filenames | wc -l) package(s) restored." From 08d1b8537048cab50c1670644de0dc4e6f44ece7 Mon Sep 17 00:00:00 2001 From: awalsh128 Date: Sat, 16 Oct 2021 21:45:24 -0700 Subject: [PATCH 15/24] Add better diagnostics. --- install_and_cache_pkgs.sh | 8 +++++++- restore_pkgs.sh | 24 +++++++++++++++--------- 2 files changed, 22 insertions(+), 10 deletions(-) diff --git a/install_and_cache_pkgs.sh b/install_and_cache_pkgs.sh index 37fda4f..9d68cf8 100755 --- a/install_and_cache_pkgs.sh +++ b/install_and_cache_pkgs.sh @@ -8,6 +8,12 @@ cache_dir=$1 # List of the packages to use. packages="${@:2}" +package_count=$(echo $packages | wc -w) +echo "* Clean installing $package_count packages..." +for package in $packages; do + echo " - $package" +done + mkdir -p $cache_dir for package in $packages; do cache_filepath=$cache_dir/$package.tar.gz @@ -24,4 +30,4 @@ for package in $packages; do xargs tar -czf $cache_filepath -C / done -echo "Action complete. ${#packages[@]} package(s) installed and cached." +echo "Action complete. $(echo $packages | wc -w) package(s) installed and cached." diff --git a/restore_pkgs.sh b/restore_pkgs.sh index 2e61d70..9f151e6 100755 --- a/restore_pkgs.sh +++ b/restore_pkgs.sh @@ -8,17 +8,23 @@ 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) -echo "* Found ${#cache_filenames[@]} files in cache..." -echo $cache_filenames - +cache_filename_count=$(echo $cache_filenames | wc -w) +echo "* Found $cache_filename_count files in cache..." for cache_filename in $cache_filenames; do - cache_filepath=$cache_dir/$cache_filename - echo "* Restoring $cache_filepath from cache... " - sudo tar -xf $cache_filepath -C $cache_restore_root + echo " - $cache_filename" done -# Update all packages. -sudo apt-get --yes --only-upgrade install -echo "Action complete. $(echo $cache_filenames | wc -l) package(s) restored." +for package in $packages; do + cache_filepath=$cache_dir/$package.tar.gz + echo "* Restoring package $package ($cache_filepath) from cache... " + sudo tar -xf $cache_filepath -C $cache_restore_root + # Upgrade the install from last state. + # TODO(awalsh128) Add versioning to cache key creation. + sudo apt-get --yes --only-upgrade install $package +done + +echo "Action complete. $cache_filename_count package(s) restored." From 9c18c92e772e0c6f128c19d988b148a5bff25666 Mon Sep 17 00:00:00 2001 From: awalsh128 Date: Sat, 16 Oct 2021 22:02:56 -0700 Subject: [PATCH 16/24] Hash on content and not on file state. --- action.yml | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/action.yml b/action.yml index 6d87649..bd302e1 100644 --- a/action.yml +++ b/action.yml @@ -30,7 +30,10 @@ runs: shell: bash - name: Create Cache Key - run: echo ${{ inputs.packages }} "cache-apt-pkgs-version:${{ inputs.version }}" | sed 's/[\s,]+/\n/g' | sort > package_list.txt + run: | + normalized_list=$(${{ inputs.packages }} | sed 's/[\s,]+/ /g' | sort) + value=$(echo $normalized_list @ ${{ inputs.version }}) + echo "CACHE_KEY=$(echo value | md5sum | /bin/cut -f1 -d' ')" >> $GITHUB_ENV shell: bash - name: Load Package Cache @@ -38,7 +41,7 @@ runs: uses: actions/cache@v2 with: path: ~/cache-apt-pkgs - key: cache-apt-pkgs_${{ hashFiles('package_list.txt') }} + key: cache-apt-pkgs_${{ env.CACHE_KEY }} - name: Load Packages run: | From 7313869349236bcec3efe712dca144459cbecceb Mon Sep 17 00:00:00 2001 From: awalsh128 Date: Sat, 16 Oct 2021 22:04:08 -0700 Subject: [PATCH 17/24] Fix missing command. --- action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/action.yml b/action.yml index bd302e1..c9e939a 100644 --- a/action.yml +++ b/action.yml @@ -31,7 +31,7 @@ runs: - name: Create Cache Key run: | - normalized_list=$(${{ inputs.packages }} | sed 's/[\s,]+/ /g' | sort) + normalized_list=$(echo ${{ inputs.packages }} | sed 's/[\s,]+/ /g' | sort) value=$(echo $normalized_list @ ${{ inputs.version }}) echo "CACHE_KEY=$(echo value | md5sum | /bin/cut -f1 -d' ')" >> $GITHUB_ENV shell: bash From 3dc9d0c3ae400ff33d1bc5c1ebc6ad698cfba359 Mon Sep 17 00:00:00 2001 From: awalsh128 Date: Sat, 16 Oct 2021 22:10:40 -0700 Subject: [PATCH 18/24] Fix variable reference. --- action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/action.yml b/action.yml index c9e939a..dfa60e5 100644 --- a/action.yml +++ b/action.yml @@ -33,7 +33,7 @@ runs: run: | normalized_list=$(echo ${{ inputs.packages }} | sed 's/[\s,]+/ /g' | sort) value=$(echo $normalized_list @ ${{ inputs.version }}) - echo "CACHE_KEY=$(echo value | md5sum | /bin/cut -f1 -d' ')" >> $GITHUB_ENV + echo "CACHE_KEY=$(echo $value | md5sum | /bin/cut -f1 -d' ')" >> $GITHUB_ENV shell: bash - name: Load Package Cache From 82c659a794224d4e7bb2dfb8a2aa3072f4de5114 Mon Sep 17 00:00:00 2001 From: awalsh128 Date: Sat, 16 Oct 2021 22:37:18 -0700 Subject: [PATCH 19/24] Validate version and break out cache key creation logic. --- README.md | 2 ++ action.yml | 6 ++---- create_cache_key.sh | 21 +++++++++++++++++++++ validate_pkgs.sh | 17 ++++++++++++++--- 4 files changed, 39 insertions(+), 7 deletions(-) create mode 100755 create_cache_key.sh diff --git a/README.md b/README.md index b1762f5..e03856e 100644 --- a/README.md +++ b/README.md @@ -18,6 +18,7 @@ Create a workflow `.yml` file in your repositories `.github/workflows` directory ### Inputs * `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. ### Outputs @@ -44,6 +45,7 @@ jobs: - uses: awalsh128/cache-apt-pkgs-action@v1 with: packages: dia doxygen doxygen-doc doxygen-gui doxygen-latex graphviz mscgen + version: 1.0 - name: Build run: | diff --git a/action.yml b/action.yml index dfa60e5..f53bcd4 100644 --- a/action.yml +++ b/action.yml @@ -26,14 +26,12 @@ runs: using: "composite" steps: - name: Validate Packages - run: ${{ github.action_path }}/validate_pkgs.sh ${{ inputs.packages }} + run: ${{ github.action_path }}/validate_pkgs.sh "${{ inputs.version }}" ${{ inputs.packages }} shell: bash - name: Create Cache Key run: | - normalized_list=$(echo ${{ inputs.packages }} | sed 's/[\s,]+/ /g' | sort) - value=$(echo $normalized_list @ ${{ inputs.version }}) - echo "CACHE_KEY=$(echo $value | md5sum | /bin/cut -f1 -d' ')" >> $GITHUB_ENV + ${{ github.action_path }}/create_cache_key.sh "${{ inputs.version }})"" ${{ inputs.packages }} >> $GITHUB_ENV shell: bash - name: Load Package Cache diff --git a/create_cache_key.sh b/create_cache_key.sh new file mode 100755 index 0000000..679c672 --- /dev/null +++ b/create_cache_key.sh @@ -0,0 +1,21 @@ +#!/bin/bash + +# Fail on any error. +set -e + +version=$1 +packages=${@:2} + +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 "CACHE_KEY=$key" \ No newline at end of file diff --git a/validate_pkgs.sh b/validate_pkgs.sh index 3b63a70..34c9830 100755 --- a/validate_pkgs.sh +++ b/validate_pkgs.sh @@ -3,20 +3,31 @@ # Fail on any error. set -e -packages=$1 +version=$1 +packages=${@:2} echo -n "* Validating action arguments... "; + +echo $version | grep -o " " > /dev/null +if [ $? -ne 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 1 + exit 2 fi + 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 2 + exit 3 fi done + echo "done." From 8df0022f2dbac4f2a29c7e59e7ac1964c5904232 Mon Sep 17 00:00:00 2001 From: awalsh128 Date: Sat, 16 Oct 2021 22:37:51 -0700 Subject: [PATCH 20/24] Extra character. --- action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/action.yml b/action.yml index f53bcd4..0c9fded 100644 --- a/action.yml +++ b/action.yml @@ -31,7 +31,7 @@ runs: - name: Create Cache Key run: | - ${{ github.action_path }}/create_cache_key.sh "${{ inputs.version }})"" ${{ inputs.packages }} >> $GITHUB_ENV + ${{ github.action_path }}/create_cache_key.sh "${{ inputs.version }})" ${{ inputs.packages }} >> $GITHUB_ENV shell: bash - name: Load Package Cache From 40818dacf68327a33984d6877ab5c07df3dccf4b Mon Sep 17 00:00:00 2001 From: awalsh128 Date: Sat, 16 Oct 2021 22:39:43 -0700 Subject: [PATCH 21/24] Fix conditional. --- validate_pkgs.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/validate_pkgs.sh b/validate_pkgs.sh index 34c9830..138f249 100755 --- a/validate_pkgs.sh +++ b/validate_pkgs.sh @@ -9,7 +9,7 @@ packages=${@:2} echo -n "* Validating action arguments... "; echo $version | grep -o " " > /dev/null -if [ $? -ne 0 ]; then +if [ $? -eq 0 ]; then echo "aborted." echo "* Version value '$version' cannot contain spaces." >&2 exit 1 From 412b31cb70777f2ddde1612d7dc53b80d9059e69 Mon Sep 17 00:00:00 2001 From: awalsh128 Date: Sat, 16 Oct 2021 22:41:42 -0700 Subject: [PATCH 22/24] Align indentation. --- validate_pkgs.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/validate_pkgs.sh b/validate_pkgs.sh index 138f249..3d48369 100755 --- a/validate_pkgs.sh +++ b/validate_pkgs.sh @@ -10,10 +10,10 @@ echo -n "* Validating action arguments... "; echo $version | grep -o " " > /dev/null if [ $? -eq 0 ]; then - echo "aborted." - echo "* Version value '$version' cannot contain spaces." >&2 - exit 1 - fi + echo "aborted." + echo "* Version value '$version' cannot contain spaces." >&2 + exit 1 +fi if [ "$packages" == "" ]; then echo "aborted." From ac4bf152a0e658ecabdc39cdff781ea24a6bfdba Mon Sep 17 00:00:00 2001 From: awalsh128 Date: Sat, 16 Oct 2021 22:44:43 -0700 Subject: [PATCH 23/24] Don't fail on error because this is expected. --- validate_pkgs.sh | 3 --- 1 file changed, 3 deletions(-) diff --git a/validate_pkgs.sh b/validate_pkgs.sh index 3d48369..e06e463 100755 --- a/validate_pkgs.sh +++ b/validate_pkgs.sh @@ -1,8 +1,5 @@ #!/bin/bash -# Fail on any error. -set -e - version=$1 packages=${@:2} From 407650fe3b277d0bd650271c99f80c5b4ce83aa7 Mon Sep 17 00:00:00 2001 From: awalsh128 Date: Sat, 16 Oct 2021 22:46:41 -0700 Subject: [PATCH 24/24] Append cache key directly to env. --- action.yml | 2 +- create_cache_key.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/action.yml b/action.yml index 0c9fded..67ebb1c 100644 --- a/action.yml +++ b/action.yml @@ -31,7 +31,7 @@ runs: - name: Create Cache Key run: | - ${{ github.action_path }}/create_cache_key.sh "${{ inputs.version }})" ${{ inputs.packages }} >> $GITHUB_ENV + ${{ github.action_path }}/create_cache_key.sh "${{ inputs.version }})" ${{ inputs.packages }} shell: bash - name: Load Package Cache diff --git a/create_cache_key.sh b/create_cache_key.sh index 679c672..9d5c98f 100755 --- a/create_cache_key.sh +++ b/create_cache_key.sh @@ -18,4 +18,4 @@ echo "* Value to hash is '$value'." key=$(echo $value | md5sum | /bin/cut -f1 -d' ') echo "* Value hashed as '$key'." -echo "CACHE_KEY=$key" \ No newline at end of file +echo "CACHE_KEY=$key" >> $GITHUB_ENV \ No newline at end of file