2021-10-13 21:11:27 -07:00
name : 'Cache APT Packages'
description : 'Install APT based packages and cache them for future runs.'
author : awalsh128
2021-10-13 22:16:32 -07:00
branding :
icon : 'hard-drive'
color : 'green'
2021-10-13 21:11:27 -07:00
inputs :
packages :
2023-03-24 04:50:32 -07:00
description : 'Space delimited list of packages to install. Version can be specified optionally using APT command syntax of <name>=<version> (e.g. xdot=1.2-2).'
2021-10-13 21:11:27 -07:00
required : true
default : ''
2021-10-16 11:34:03 -07:00
version :
2022-11-23 22:24:00 -08:00
description : 'Version of cache to load. Each version will have its own cache. Note, all characters except spaces are allowed.'
2021-10-16 11:34:03 -07:00
required : false
2022-11-23 22:24:00 -08:00
default : ''
execute_install_scripts :
description : 'Execute Debian package pre and post install script upon restore. See README.md caveats for more information.'
required : false
default : 'false'
2021-10-21 15:44:19 -07:00
refresh :
2023-02-04 20:30:40 -08:00
description: 'OBSOLETE : Refresh is not used by the action, use version instead.'
deprecationMessage : 'Refresh is not used by the action, use version instead.'
2022-11-23 22:24:00 -08:00
debug :
description : 'Enable debugging when there are issues with action. Minor performance penalty.'
2021-10-21 15:44:19 -07:00
required : false
default : 'false'
2021-10-13 21:11:27 -07:00
outputs :
cache-hit :
description : 'A boolean value to indicate a cache was found for the packages requested.'
2021-10-16 21:17:41 -07:00
# This compound expression is needed because lhs can be empty.
# Need to output true and false instead of true and nothing.
2021-10-16 13:16:36 -07:00
value : ${{ steps.load-cache.outputs.cache-hit || false }}
2021-10-21 20:57:52 -07:00
package-version-list :
2023-03-24 04:50:32 -07:00
description : 'The main requested packages and versions that are installed. Represented as a comma delimited list with equals delimit on the package version (i.e. <package>:<version,<package>:<version>).'
2022-07-19 20:42:48 -07:00
value : ${{ steps.post-cache.outputs.package-version-list }}
all-package-version-list :
2023-03-24 04:50:32 -07:00
description : 'All the pulled in packages and versions, including dependencies, that are installed. Represented as a comma delimited list with equals delimit on the package version (i.e. <package>:<version,<package>:<version>).'
2022-07-15 16:14:30 -07:00
value : ${{ steps.post-cache.outputs.all-package-version-list }}
2021-10-13 21:11:27 -07:00
runs :
using : "composite"
steps :
2021-10-21 20:57:52 -07:00
- id : pre-cache
2021-10-16 22:02:56 -07:00
run : |
2022-12-07 22:11:01 -08:00
${GITHUB_ACTION_PATH}/pre_cache_action.sh \
2021-10-21 21:13:01 -07:00
~/cache-apt-pkgs \
2023-02-03 23:16:50 -08:00
"$VERSION" \
"$EXEC_INSTALL_SCRIPTS" \
"$DEBUG" \
"$PACKAGES"
2021-10-21 20:57:52 -07:00
echo "CACHE_KEY=$(cat ~/cache-apt-pkgs/cache_key.md5)" >> $GITHUB_ENV
2021-10-13 21:11:27 -07:00
shell : bash
2023-02-03 23:16:50 -08:00
env :
VERSION : "${{ inputs.version }}"
EXEC_INSTALL_SCRIPTS : "${{ inputs.execute_install_scripts }}"
DEBUG : "${{ inputs.debug }}"
PACKAGES : "${{ inputs.packages }}"
2021-10-13 21:11:27 -07:00
2021-10-21 20:57:52 -07:00
- id : load-cache
2024-02-01 13:13:10 -08:00
uses : actions/cache/restore@v4
2021-10-13 21:11:27 -07:00
with :
path : ~/cache-apt-pkgs
2021-10-16 22:02:56 -07:00
key : cache-apt-pkgs_${{ env.CACHE_KEY }}
2021-10-13 21:11:27 -07:00
2021-10-21 20:57:52 -07:00
- id : post-cache
2023-03-24 04:50:32 -07:00
run : |
2022-12-07 22:11:01 -08:00
${GITHUB_ACTION_PATH}/post_cache_action.sh \
2021-10-21 21:30:33 -07:00
~/cache-apt-pkgs \
/ \
2023-02-03 23:16:50 -08:00
"$CACHE_HIT" \
"$EXEC_INSTALL_SCRIPTS" \
"$DEBUG" \
"$PACKAGES"
2022-07-19 20:42:48 -07:00
function create_list { local list=$(cat ~/cache-apt-pkgs/manifest_${1}.log | tr '\n' ','); echo ${list:0:-1}; };
2022-10-30 11:49:55 -07:00
echo "package-version-list=$(create_list main)" >> $GITHUB_OUTPUT
echo "all-package-version-list=$(create_list all)" >> $GITHUB_OUTPUT
2021-10-21 15:44:19 -07:00
shell : bash
2023-02-03 23:16:50 -08:00
env :
CACHE_HIT : "${{ steps.load-cache.outputs.cache-hit }}"
EXEC_INSTALL_SCRIPTS : "${{ inputs.execute_install_scripts }}"
DEBUG : "${{ inputs.debug }}"
PACKAGES : "${{ inputs.packages }}"
2022-11-23 22:24:00 -08:00
2023-10-30 11:12:50 -07:00
- id : upload-logs
if : ${{ inputs.debug == 'true' }}
uses : actions/upload-artifact@v3
with :
name : cache-apt-pkgs-logs_${{ env.CACHE_KEY }}
path : ~/cache-apt-pkgs/*.log
2023-03-06 06:56:37 -08:00
- id : save-cache
if : ${{ ! steps.load-cache.outputs.cache-hit }}
uses : actions/cache/save@v3
with :
path : ~/cache-apt-pkgs
key : ${{ steps.load-cache.outputs.cache-primary-key }}
- id : clean-cache
run : |
rm -rf ~/cache-apt-pkgs
shell : bash