cache-apt-pkgs-action/pre_cache_action.sh

95 lines
2.3 KiB
Bash
Raw Normal View History

#!/bin/bash
set -e
# Include library.
script_dir="$(dirname -- "$(realpath -- "${0}")")"
source "${script_dir}/lib.sh"
Execute installation scripts feature, debug mode, and permission denied fix. (#65) * Execute installation scripts and debug mode features. (#64) * Provide the ability to call Debian package manager installation scripts (i.e. `*.[preinst, postinst]`). * Introduce a debug mode that runs the scripts in verbose mode and uploads the logs for retrieval. * Updated README to reflect new features and provided more info on how to use the action versions. * Dev (#66) * Fix permission denied error. * Fix permission denied error. (#51) * Remove compression from file caching. (#53) * Draft of postinst support from issue #44. * Remove bad option. * Removed extraneous line. * Cover no packages edge case when writing manifest. * Fix postinst bugs and add docs to lib. * Made cache directory variable and more refinements to postinst. * Update deprecated option. https://github.blog/changelog/2022-10-11-github-actions-deprecating-save-state-and-set-output-commands/ * Rollback accidental commit of new postinst feature. * Minor edit ands full install script execution FR. * Fix execute_install_scripts message to show the right param name. * Fix param check. * Minor fix to doc. * Upload action logs for debugging. * Make artifact names unique. * Add debug option. * Update description. * Debug package list issue. * Rollback https://github.com/awalsh128/cache-apt-pkgs-action/commit/76128c60a11c33c0b900402e8068a60c986affd9 * Revert outputs set behavior to see if it fixes outputs issue in dev. * Restore updated outputs behavior. So strange it is working when I revert. * Fix bugs in install script execution. * Add error suppression on file testing. * Debug feature. * Link to the issue that started the postinst troubleshooting. * Describe action version usage. * Fix package outputs command.
2022-11-24 06:24:00 +00:00
# Debug mode for diagnosing issues.
# Setup first before other operations.
debug="${4}"
validate_bool "${debug}" debug 1
test ${debug} == "true" && set -x
# Directory that holds the cached packages.
cache_dir="${1}"
# Version of the cache to create or load.
2022-07-20 03:42:48 +00:00
version="${2}"
Execute installation scripts feature, debug mode, and permission denied fix. (#65) * Execute installation scripts and debug mode features. (#64) * Provide the ability to call Debian package manager installation scripts (i.e. `*.[preinst, postinst]`). * Introduce a debug mode that runs the scripts in verbose mode and uploads the logs for retrieval. * Updated README to reflect new features and provided more info on how to use the action versions. * Dev (#66) * Fix permission denied error. * Fix permission denied error. (#51) * Remove compression from file caching. (#53) * Draft of postinst support from issue #44. * Remove bad option. * Removed extraneous line. * Cover no packages edge case when writing manifest. * Fix postinst bugs and add docs to lib. * Made cache directory variable and more refinements to postinst. * Update deprecated option. https://github.blog/changelog/2022-10-11-github-actions-deprecating-save-state-and-set-output-commands/ * Rollback accidental commit of new postinst feature. * Minor edit ands full install script execution FR. * Fix execute_install_scripts message to show the right param name. * Fix param check. * Minor fix to doc. * Upload action logs for debugging. * Make artifact names unique. * Add debug option. * Update description. * Debug package list issue. * Rollback https://github.com/awalsh128/cache-apt-pkgs-action/commit/76128c60a11c33c0b900402e8068a60c986affd9 * Revert outputs set behavior to see if it fixes outputs issue in dev. * Restore updated outputs behavior. So strange it is working when I revert. * Fix bugs in install script execution. * Add error suppression on file testing. * Debug feature. * Link to the issue that started the postinst troubleshooting. * Describe action version usage. * Fix package outputs command.
2022-11-24 06:24:00 +00:00
# Execute post-installation script.
execute_install_scripts="${3}"
# Debug mode for diagnosing issues.
debug="${4}"
# List of the packages to use.
Execute installation scripts feature, debug mode, and permission denied fix. (#65) * Execute installation scripts and debug mode features. (#64) * Provide the ability to call Debian package manager installation scripts (i.e. `*.[preinst, postinst]`). * Introduce a debug mode that runs the scripts in verbose mode and uploads the logs for retrieval. * Updated README to reflect new features and provided more info on how to use the action versions. * Dev (#66) * Fix permission denied error. * Fix permission denied error. (#51) * Remove compression from file caching. (#53) * Draft of postinst support from issue #44. * Remove bad option. * Removed extraneous line. * Cover no packages edge case when writing manifest. * Fix postinst bugs and add docs to lib. * Made cache directory variable and more refinements to postinst. * Update deprecated option. https://github.blog/changelog/2022-10-11-github-actions-deprecating-save-state-and-set-output-commands/ * Rollback accidental commit of new postinst feature. * Minor edit ands full install script execution FR. * Fix execute_install_scripts message to show the right param name. * Fix param check. * Minor fix to doc. * Upload action logs for debugging. * Make artifact names unique. * Add debug option. * Update description. * Debug package list issue. * Rollback https://github.com/awalsh128/cache-apt-pkgs-action/commit/76128c60a11c33c0b900402e8068a60c986affd9 * Revert outputs set behavior to see if it fixes outputs issue in dev. * Restore updated outputs behavior. So strange it is working when I revert. * Fix bugs in install script execution. * Add error suppression on file testing. * Debug feature. * Link to the issue that started the postinst troubleshooting. * Describe action version usage. * Fix package outputs command.
2022-11-24 06:24:00 +00:00
input_packages="${@:5}"
# Trim commas, excess spaces, and sort.
packages="$(normalize_package_list "${input_packages}")"
2021-10-22 04:12:42 +00:00
# Create cache directory so artifacts can be saved.
2022-07-20 03:42:48 +00:00
mkdir -p ${cache_dir}
2021-10-22 04:12:42 +00:00
log "Validating action arguments (version='${version}', packages='${packages}')...";
2022-07-20 03:42:48 +00:00
if grep -q " " <<< "${version}"; then
log "aborted"
2022-07-20 03:42:48 +00:00
log "Version value '${version}' cannot contain spaces." >&2
Execute installation scripts feature, debug mode, and permission denied fix. (#65) * Execute installation scripts and debug mode features. (#64) * Provide the ability to call Debian package manager installation scripts (i.e. `*.[preinst, postinst]`). * Introduce a debug mode that runs the scripts in verbose mode and uploads the logs for retrieval. * Updated README to reflect new features and provided more info on how to use the action versions. * Dev (#66) * Fix permission denied error. * Fix permission denied error. (#51) * Remove compression from file caching. (#53) * Draft of postinst support from issue #44. * Remove bad option. * Removed extraneous line. * Cover no packages edge case when writing manifest. * Fix postinst bugs and add docs to lib. * Made cache directory variable and more refinements to postinst. * Update deprecated option. https://github.blog/changelog/2022-10-11-github-actions-deprecating-save-state-and-set-output-commands/ * Rollback accidental commit of new postinst feature. * Minor edit ands full install script execution FR. * Fix execute_install_scripts message to show the right param name. * Fix param check. * Minor fix to doc. * Upload action logs for debugging. * Make artifact names unique. * Add debug option. * Update description. * Debug package list issue. * Rollback https://github.com/awalsh128/cache-apt-pkgs-action/commit/76128c60a11c33c0b900402e8068a60c986affd9 * Revert outputs set behavior to see if it fixes outputs issue in dev. * Restore updated outputs behavior. So strange it is working when I revert. * Fix bugs in install script execution. * Add error suppression on file testing. * Debug feature. * Link to the issue that started the postinst troubleshooting. * Describe action version usage. * Fix package outputs command.
2022-11-24 06:24:00 +00:00
exit 2
fi
2022-06-04 04:04:43 +00:00
# Is length of string zero?
if test -z "${packages}"; then
log "aborted"
2022-07-20 03:42:48 +00:00
log "Packages argument cannot be empty." >&2
Execute installation scripts feature, debug mode, and permission denied fix. (#65) * Execute installation scripts and debug mode features. (#64) * Provide the ability to call Debian package manager installation scripts (i.e. `*.[preinst, postinst]`). * Introduce a debug mode that runs the scripts in verbose mode and uploads the logs for retrieval. * Updated README to reflect new features and provided more info on how to use the action versions. * Dev (#66) * Fix permission denied error. * Fix permission denied error. (#51) * Remove compression from file caching. (#53) * Draft of postinst support from issue #44. * Remove bad option. * Removed extraneous line. * Cover no packages edge case when writing manifest. * Fix postinst bugs and add docs to lib. * Made cache directory variable and more refinements to postinst. * Update deprecated option. https://github.blog/changelog/2022-10-11-github-actions-deprecating-save-state-and-set-output-commands/ * Rollback accidental commit of new postinst feature. * Minor edit ands full install script execution FR. * Fix execute_install_scripts message to show the right param name. * Fix param check. * Minor fix to doc. * Upload action logs for debugging. * Make artifact names unique. * Add debug option. * Update description. * Debug package list issue. * Rollback https://github.com/awalsh128/cache-apt-pkgs-action/commit/76128c60a11c33c0b900402e8068a60c986affd9 * Revert outputs set behavior to see if it fixes outputs issue in dev. * Restore updated outputs behavior. So strange it is working when I revert. * Fix bugs in install script execution. * Add error suppression on file testing. * Debug feature. * Link to the issue that started the postinst troubleshooting. * Describe action version usage. * Fix package outputs command.
2022-11-24 06:24:00 +00:00
exit 3
fi
Execute installation scripts feature, debug mode, and permission denied fix. (#65) * Execute installation scripts and debug mode features. (#64) * Provide the ability to call Debian package manager installation scripts (i.e. `*.[preinst, postinst]`). * Introduce a debug mode that runs the scripts in verbose mode and uploads the logs for retrieval. * Updated README to reflect new features and provided more info on how to use the action versions. * Dev (#66) * Fix permission denied error. * Fix permission denied error. (#51) * Remove compression from file caching. (#53) * Draft of postinst support from issue #44. * Remove bad option. * Removed extraneous line. * Cover no packages edge case when writing manifest. * Fix postinst bugs and add docs to lib. * Made cache directory variable and more refinements to postinst. * Update deprecated option. https://github.blog/changelog/2022-10-11-github-actions-deprecating-save-state-and-set-output-commands/ * Rollback accidental commit of new postinst feature. * Minor edit ands full install script execution FR. * Fix execute_install_scripts message to show the right param name. * Fix param check. * Minor fix to doc. * Upload action logs for debugging. * Make artifact names unique. * Add debug option. * Update description. * Debug package list issue. * Rollback https://github.com/awalsh128/cache-apt-pkgs-action/commit/76128c60a11c33c0b900402e8068a60c986affd9 * Revert outputs set behavior to see if it fixes outputs issue in dev. * Restore updated outputs behavior. So strange it is working when I revert. * Fix bugs in install script execution. * Add error suppression on file testing. * Debug feature. * Link to the issue that started the postinst troubleshooting. * Describe action version usage. * Fix package outputs command.
2022-11-24 06:24:00 +00:00
validate_bool "${execute_install_scripts}" execute_install_scripts 4
log "done"
log_empty_line
versioned_packages=""
log "Verifying packages..."
for package in ${packages}; do
if test ! "$(apt-cache show "${package}")"; then
echo "aborted"
2022-07-20 03:42:48 +00:00
log "Package '${package}' not found." >&2
Execute installation scripts feature, debug mode, and permission denied fix. (#65) * Execute installation scripts and debug mode features. (#64) * Provide the ability to call Debian package manager installation scripts (i.e. `*.[preinst, postinst]`). * Introduce a debug mode that runs the scripts in verbose mode and uploads the logs for retrieval. * Updated README to reflect new features and provided more info on how to use the action versions. * Dev (#66) * Fix permission denied error. * Fix permission denied error. (#51) * Remove compression from file caching. (#53) * Draft of postinst support from issue #44. * Remove bad option. * Removed extraneous line. * Cover no packages edge case when writing manifest. * Fix postinst bugs and add docs to lib. * Made cache directory variable and more refinements to postinst. * Update deprecated option. https://github.blog/changelog/2022-10-11-github-actions-deprecating-save-state-and-set-output-commands/ * Rollback accidental commit of new postinst feature. * Minor edit ands full install script execution FR. * Fix execute_install_scripts message to show the right param name. * Fix param check. * Minor fix to doc. * Upload action logs for debugging. * Make artifact names unique. * Add debug option. * Update description. * Debug package list issue. * Rollback https://github.com/awalsh128/cache-apt-pkgs-action/commit/76128c60a11c33c0b900402e8068a60c986affd9 * Revert outputs set behavior to see if it fixes outputs issue in dev. * Restore updated outputs behavior. So strange it is working when I revert. * Fix bugs in install script execution. * Add error suppression on file testing. * Debug feature. * Link to the issue that started the postinst troubleshooting. * Describe action version usage. * Fix package outputs command.
2022-11-24 06:24:00 +00:00
exit 5
fi
2022-07-20 03:42:48 +00:00
read package_name package_ver < <(get_package_name_ver "${package}")
versioned_packages=""${versioned_packages}" "${package_name}"="${package_ver}""
done
log "done"
log_empty_line
# Abort on any failure at this point.
set -e
2022-07-20 03:42:48 +00:00
log "Creating cache key..."
# TODO Can we prove this will happen again?
normalized_versioned_packages="$(normalize_package_list "${versioned_packages}")"
2022-07-20 03:42:48 +00:00
log "- Normalized package list is '${normalized_versioned_packages}'."
# Forces an update in cases where an accidental breaking change was introduced
# and a global cache reset is required.
force_update_inc="0"
value="${normalized_versioned_packages} @ ${version} ${force_update_inc}"
2022-07-20 03:42:48 +00:00
log "- Value to hash is '${value}'."
key="$(echo "${value}" | md5sum | cut -f1 -d' ')"
2022-07-20 03:42:48 +00:00
log "- Value hashed as '${key}'."
log "done"
key_filepath="${cache_dir}/cache_key.md5"
2022-07-20 03:42:48 +00:00
echo ${key} > ${key_filepath}
log "Hash value written to ${key_filepath}"