Debug feature.

This commit is contained in:
awalsh128 2022-11-19 18:53:52 -08:00
parent aa86a37b2d
commit 63736e2a81
6 changed files with 59 additions and 18 deletions

View file

@ -47,6 +47,7 @@ runs:
~/cache-apt-pkgs \
"${{ inputs.version }}" \
"${{ inputs.execute_install_scripts }}" \
"${{ inputs.debug }}" \
${{ inputs.packages }}
echo "CACHE_KEY=$(cat ~/cache-apt-pkgs/cache_key.md5)" >> $GITHUB_ENV
shell: bash
@ -64,6 +65,7 @@ runs:
/ \
"${{ steps.load-cache.outputs.cache-hit }}" \
"${{ inputs.execute_install_scripts }}" \
"${{ inputs.debug }}" \
${{ inputs.packages }}
function create_list { local list=$(cat ~/cache-apt-pkgs/manifest_${1}.log | tr '\n' ','); echo ${list:0:-1}; };
echo "name=package-version-list::$(create_list main)" >> $GITHUB_OUTPUT
@ -74,5 +76,5 @@ runs:
if: ${{ inputs.debug }} == "true"
uses: actions/upload-artifact@v3
with:
name: ${{ inputs.packages }}%${{ inputs.version }}
name: cache-apt-pkgs-logs%${{ inputs.packages }}%${{ inputs.version }}
path: ~/cache-apt-pkgs/*.log

View file

@ -3,6 +3,11 @@
# Fail on any error.
set -e
# Debug mode for diagnosing issues.
# Setup first before other operations.
debug="${2}"
test ${debug} == "true" && set -x
# Include library.
script_dir="$(dirname -- "$(realpath -- "${0}")")"
source "${script_dir}/lib.sh"
@ -11,7 +16,7 @@ source "${script_dir}/lib.sh"
cache_dir="${1}"
# List of the packages to use.
input_packages="${@:2}"
input_packages="${@:3}"
# Trim commas, excess spaces, and sort.
normalized_packages="$(normalize_package_list "${input_packages}")"
@ -33,8 +38,13 @@ write_manifest "main" "${manifest_main}" "${cache_dir}/manifest_main.log"
log_empty_line
log "Updating APT package list..."
sudo apt-fast update > /dev/null
log "done"
last_update_delta_s=$(($(date +%s) - $(date +%s -r /var/cache/apt/pkgcache.bin)))
if test $last_update_delta_s -gt 300; then
sudo apt-fast update > /dev/null
log "done"
else
log "skipped (fresh by ${last_update_delta_s} seconds)"
fi
log_empty_line

17
lib.sh
View file

@ -134,6 +134,23 @@ function normalize_package_list {
echo "${sorted}"
}
###############################################################################
# Validates an argument to be of a boolean value.
# Arguments:
# Argument to validate.
# Variable name of the argument.
# Exit code if validation fails.
# Returns:
# Sorted list of space delimited packages.
###############################################################################
function validate_bool {
if test "${1}" != "true" -a "${1}" != "false"; then
log "aborted"
log "${2} value '${1}' must be either true or false (case sensitive)."
exit ${3}
fi
}
###############################################################################
# Writes the manifest to a specified file.
# Arguments:

View file

@ -21,15 +21,17 @@ cache_hit="${3}"
# Cache and execute post install scripts on restore.
execute_install_scripts="${4}"
# List of the packages to use.
packages="${@:5}"
# Debug mode for diagnosing issues.
debug="${5}"
test ${debug} == "true" && set -x
script_dir="$(dirname -- "$(realpath -- "${0}")")"
# List of the packages to use.
packages="${@:6}"
if [ "$cache_hit" == true ]; then
${script_dir}/restore_pkgs.sh "${cache_dir}" "${cache_restore_root}" "${execute_install_scripts}"
${script_dir}/restore_pkgs.sh "${cache_dir}" "${cache_restore_root}" "${execute_install_scripts}" "${debug}"
else
${script_dir}/install_and_cache_pkgs.sh "${cache_dir}" ${packages}
${script_dir}/install_and_cache_pkgs.sh "${cache_dir}" "${debug}" ${packages}
fi
log_empty_line

View file

@ -1,5 +1,11 @@
#!/bin/bash
# Debug mode for diagnosing issues.
# Setup first before other operations.
debug="${4}"
validate_bool "${debug}" debug 1
test ${debug} == "true" && set -x
# Include library.
script_dir="$(dirname -- "$(realpath -- "${0}")")"
source "${script_dir}/lib.sh"
@ -13,8 +19,11 @@ version="${2}"
# Execute post-installation script.
execute_install_scripts="${3}"
# Debug mode for diagnosing issues.
debug="${4}"
# List of the packages to use.
input_packages="${@:4}"
input_packages="${@:5}"
# Trim commas, excess spaces, and sort.
packages="$(normalize_package_list "${input_packages}")"
@ -26,22 +35,18 @@ log "Validating action arguments (version='${version}', packages='${packages}').
if grep -q " " <<< "${version}"; then
log "aborted"
log "Version value '${version}' cannot contain spaces." >&2
exit 1
exit 2
fi
# Is length of string zero?
if test -z "${packages}"; then
log "aborted"
log "Packages argument cannot be empty." >&2
exit 2
fi
if test "${execute_install_scripts}" != "true" -a "${execute_install_scripts}" != "false"; then
log "aborted"
log "execute_install_scripts value '${execute_install_scripts}' must be either true or false (case sensitive)."
exit 3
fi
validate_bool "${execute_install_scripts}" execute_install_scripts 4
log "done"
log_empty_line
@ -59,7 +64,7 @@ for package in ${packages}; do
if test ! "$(apt-cache show "${package}")"; then
echo "aborted"
log "Package '${package}' not found." >&2
exit 4
exit 5
fi
read package_name package_ver < <(get_package_name_ver "${package}")
versioned_packages=""${versioned_packages}" "${package_name}"="${package_ver}""

View file

@ -3,6 +3,11 @@
# Fail on any error.
set -e
# Debug mode for diagnosing issues.
# Setup first before other operations.
debug="${4}"
test ${debug} == "true" && set -x
# Include library.
script_dir="$(dirname -- "$(realpath -- "${0}")")"
source "${script_dir}/lib.sh"