mirror of
https://github.com/awalsh128/cache-apt-pkgs-action.git
synced 2025-09-03 14:41:04 +00:00
Compare commits
4 commits
Author | SHA1 | Date | |
---|---|---|---|
|
9f7a885e33 | ||
|
a605dbde2a | ||
|
2c09a5e66d | ||
|
9a146f43d1 |
|
@ -35,6 +35,7 @@ There are three kinds of version labels you can use.
|
|||
- `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.
|
||||
- `execute_install_scripts` - Execute Debian package pre and post install script upon restore. See [Caveats / Non-file Dependencies](#non-file-dependencies) for more information.
|
||||
- `empty_packages_behavior` - Desired behavior when the given `packages` is empty. `'error'` (default), `'warn'` or `'ignore'`.
|
||||
|
||||
### Outputs
|
||||
|
||||
|
|
23
action.yml
23
action.yml
|
@ -18,6 +18,16 @@ inputs:
|
|||
description: 'Execute Debian package pre and post install script upon restore. See README.md caveats for more information.'
|
||||
required: false
|
||||
default: 'false'
|
||||
empty_packages_behavior:
|
||||
description: >
|
||||
Desired behavior when the provided package list is empty.
|
||||
|
||||
Available Options:
|
||||
error: Fail the action with an error message
|
||||
warn: Output a warning without failing the action
|
||||
ignore: Proceed silently without warnings or errors
|
||||
required: false
|
||||
default: 'error'
|
||||
refresh:
|
||||
description: 'OBSOLETE: Refresh is not used by the action, use version instead.'
|
||||
deprecationMessage: 'Refresh is not used by the action, use version instead.'
|
||||
|
@ -50,21 +60,28 @@ runs:
|
|||
"$EXEC_INSTALL_SCRIPTS" \
|
||||
"$DEBUG" \
|
||||
"$PACKAGES"
|
||||
echo "CACHE_KEY=$(cat ~/cache-apt-pkgs/cache_key.md5)" >> $GITHUB_ENV
|
||||
if [ -f ~/cache-apt-pkgs/cache_key.md5 ]; then
|
||||
echo "CACHE_KEY=$(cat ~/cache-apt-pkgs/cache_key.md5)" >> $GITHUB_ENV
|
||||
else
|
||||
echo "CACHE_KEY=" >> $GITHUB_ENV
|
||||
fi
|
||||
shell: bash
|
||||
env:
|
||||
VERSION: "${{ inputs.version }}"
|
||||
EXEC_INSTALL_SCRIPTS: "${{ inputs.execute_install_scripts }}"
|
||||
EMPTY_PACKAGES_BEHAVIOR: "${{ inputs.empty_packages_behavior }}"
|
||||
DEBUG: "${{ inputs.debug }}"
|
||||
PACKAGES: "${{ inputs.packages }}"
|
||||
|
||||
- id: load-cache
|
||||
if: ${{ env.CACHE_KEY }}
|
||||
uses: actions/cache/restore@v4
|
||||
with:
|
||||
path: ~/cache-apt-pkgs
|
||||
key: cache-apt-pkgs_${{ env.CACHE_KEY }}
|
||||
|
||||
- id: post-cache
|
||||
if: ${{ env.CACHE_KEY }}
|
||||
run: |
|
||||
${GITHUB_ACTION_PATH}/post_cache_action.sh \
|
||||
~/cache-apt-pkgs \
|
||||
|
@ -84,14 +101,14 @@ runs:
|
|||
PACKAGES: "${{ inputs.packages }}"
|
||||
|
||||
- id: upload-logs
|
||||
if: ${{ inputs.debug == 'true' }}
|
||||
if: ${{ env.CACHE_KEY && inputs.debug == 'true' }}
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: cache-apt-pkgs-logs_${{ env.CACHE_KEY }}
|
||||
path: ~/cache-apt-pkgs/*.log
|
||||
|
||||
- id: save-cache
|
||||
if: ${{ ! steps.load-cache.outputs.cache-hit }}
|
||||
if: ${{ env.CACHE_KEY && ! steps.load-cache.outputs.cache-hit }}
|
||||
uses: actions/cache/save@v4
|
||||
with:
|
||||
path: ~/cache-apt-pkgs
|
||||
|
|
BIN
apt_query-arm64
BIN
apt_query-arm64
Binary file not shown.
BIN
apt_query-x86
BIN
apt_query-x86
Binary file not shown.
|
@ -87,11 +87,23 @@ for installed_package in ${installed_packages}; do
|
|||
read package_name package_ver < <(get_package_name_ver "${installed_package}")
|
||||
log " * Caching ${package_name} to ${cache_filepath}..."
|
||||
|
||||
# Pipe all package files (no folders) and installation control data to Tar.
|
||||
tar -cf "${cache_filepath}" -C / --verbatim-files-from --files-from <( { dpkg -L "${package_name}" &&
|
||||
get_install_script_filepath "" "${package_name}" "preinst" &&
|
||||
get_install_script_filepath "" "${package_name}" "postinst" ;} |
|
||||
while IFS= read -r f; do test -f "${f}" -o -L "${f}" && get_tar_relpath "${f}"; done )
|
||||
# Pipe all package files (no folders), including symlinks, their targets, and installation control data to Tar.
|
||||
tar -cf "${cache_filepath}" -C / --verbatim-files-from --files-from <(
|
||||
{ dpkg -L "${package_name}" &&
|
||||
get_install_script_filepath "" "${package_name}" "preinst" &&
|
||||
get_install_script_filepath "" "${package_name}" "postinst" ; } |
|
||||
while IFS= read -r f; do
|
||||
if test -f "${f}" -o -L "${f}"; then
|
||||
get_tar_relpath "${f}"
|
||||
if [ -L "${f}" ]; then
|
||||
target="$(readlink -f "${f}")"
|
||||
if [ -f "${target}" ]; then
|
||||
get_tar_relpath "${target}"
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
done
|
||||
)
|
||||
|
||||
log " done (compressed size $(du -h "${cache_filepath}" | cut -f1))."
|
||||
fi
|
||||
|
|
|
@ -44,9 +44,20 @@ fi
|
|||
|
||||
# Is length of string zero?
|
||||
if test -z "${packages}"; then
|
||||
log "aborted"
|
||||
log "Packages argument cannot be empty." >&2
|
||||
exit 3
|
||||
case "$EMPTY_PACKAGES_BEHAVIOR" in
|
||||
ignore)
|
||||
exit 0
|
||||
;;
|
||||
warn)
|
||||
echo "::warning::Packages argument is empty."
|
||||
exit 0
|
||||
;;
|
||||
*)
|
||||
log "aborted"
|
||||
log "Packages argument is empty." >&2
|
||||
exit 3
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
|
||||
validate_bool "${execute_install_scripts}" execute_install_scripts 4
|
||||
|
|
|
@ -52,6 +52,10 @@ func getNonVirtualPackage(executor exec.Executor, name string) (pkg *AptPackage,
|
|||
func getPackage(executor exec.Executor, paragraph string) (pkg *AptPackage, err error) {
|
||||
errMsgs := []string{}
|
||||
for _, splitLine := range GetSplitLines(paragraph, ":", 2) {
|
||||
if len(splitLine.Words) < 2 {
|
||||
logging.Debug("Skipping invalid line: %+v\n", splitLine.Line)
|
||||
continue
|
||||
}
|
||||
switch splitLine.Words[0] {
|
||||
case "Package":
|
||||
// Initialize since this will provide the first struct value if present.
|
||||
|
|
Loading…
Reference in a new issue