Create a new output for all packages including dependencies.

This commit is contained in:
awalsh128 2022-06-30 06:18:19 -07:00
parent 903a8a32ff
commit a91bf7b286
3 changed files with 41 additions and 21 deletions

View file

@ -24,8 +24,8 @@ Create a workflow `.yml` file in your repositories `.github/workflows` directory
### Outputs ### Outputs
* `cache-hit` - A boolean value to indicate a cache was found for the packages requested. * `cache-hit` - A boolean value to indicate a cache was found for the packages requested.
* `package-version-list` - The packages and versions that are installed as a comma delimited list with colon delimit on the package version (i.e. \<package1>:<version1\>,\<package2>:\<version2>,...). * `package-version-list` - The main requested packages and versions that are installed. Represented as a comma delimited list with colon delimit on the package version (i.e. \<package1>:<version1\>,\<package2>:\<version2>,...).
* `all-package-version-list` - All the pulled in packages and versions, including dependencies, that are installed. Represented as a comma delimited list with colon delimit on the package version (i.e. \<package1>:<version1\>,\<package2>:\<version2>,...).
### Cache scopes ### Cache scopes

View file

@ -26,7 +26,10 @@ outputs:
# Need to output true and false instead of true and nothing. # Need to output true and false instead of true and nothing.
value: ${{ steps.load-cache.outputs.cache-hit || false }} value: ${{ steps.load-cache.outputs.cache-hit || false }}
package-version-list: package-version-list:
description: 'The packages and versions that are installed as a comma delimited list with colon delimit on the package version (i.e. <package>:<version,<package>:<version>).' description: 'The main requested packages and versions that are installed. Represented as a comma delimited list with colon delimit on the package version (i.e. <package>:<version,<package>:<version>).'
value: ${{ steps.post-cache.outputs.package-version-list }}
all-package-version-list:
description: 'All the pulled in packages and versions, including dependencies, that are installed. Represented as a comma delimited list with colon delimit on the package version (i.e. <package>:<version,<package>:<version>).'
value: ${{ steps.post-cache.outputs.package-version-list }} value: ${{ steps.post-cache.outputs.package-version-list }}
runs: runs:
@ -54,5 +57,6 @@ runs:
/ \ / \
"${{ steps.load-cache.outputs.cache-hit }}" \ "${{ steps.load-cache.outputs.cache-hit }}" \
${{ inputs.packages }} ${{ inputs.packages }}
echo "::set-output name=package-version-list::$(cat ~/cache-apt-pkgs/manifest.log)" echo "::set-output name=package-version-list::$(cat ~/cache-apt-pkgs/manifest_main.log)"
echo "::set-output name=all-package-version-list::$(cat ~/cache-apt-pkgs/manifest_all.log)"
shell: bash shell: bash

View file

@ -16,7 +16,7 @@ input_packages="${@:2}"
# Trim commas, excess spaces, and sort. # Trim commas, excess spaces, and sort.
normalized_packages="$(normalize_package_list "${input_packages}")" normalized_packages="$(normalize_package_list "${input_packages}")"
package_count=$(echo "${normalized_packages}" | wc -w) package_count=$(wc -w <<< "${normalized_packages}")
echo "Clean installing and caching ${package_count} package(s)." echo "Clean installing and caching ${package_count} package(s)."
echo "Package list:" echo "Package list:"
for package in ${normalized_packages}; do for package in ${normalized_packages}; do
@ -27,42 +27,58 @@ echo -n "Updating APT package list..."
sudo apt-get update > /dev/null sudo apt-get update > /dev/null
echo "done." echo "done."
manifest="" # Strictly contains the requested packages.
manifest_main=""
# Contains all packages including dependencies.
manifest_all=""
echo "Clean installing and caching ${package_count} packages..." echo "Clean installing and caching ${package_count} packages..."
for package in ${normalized_packages}; do for package in ${normalized_packages}; do
read package_name package_ver < <(get_package_name_ver "${package}") read package_name package_ver < <(get_package_name_ver "${package}")
package_deps="$(apt-get install --dry-run --yes "${package_name}" | grep "^Inst" | awk '{print $2}')"
# Comma delimited name:ver pairs in the main requested packages manifest.
manifest_main="${manifest_main}${package_name}:${package_ver},"
all_packages="$(apt-get install --dry-run --yes "${package_name}" | grep "^Inst" | awk '{print $2}')"
dep_packages="$(grep -v "${package_name}" <<< ${all_packages})"
echo "- ${package_name}" echo "- ${package_name}"
echo " * Version: ${package_ver}" echo " * Version: ${package_ver}"
echo " * Dependencies: ${package_deps}" echo " * Dependencies: ${dep_packages}"
echo -n " * Installing..." echo -n " * Installing..."
# Zero interaction while installing or upgrading the system via apt. # Zero interaction while installing or upgrading the system via apt.
sudo DEBIAN_FRONTEND=noninteractive apt-get --yes install "${package}" > /dev/null sudo DEBIAN_FRONTEND=noninteractive apt-get --yes install "${package}" > /dev/null
echo "done." echo "done."
for cache_package in ${package_deps}; do for cache_package in ${all_packages}; do
cache_filepath="${cache_dir}/${cache_package}.tar.gz" cache_filepath="${cache_dir}/${cache_package}.tar.gz"
if test ! -f "${cache_filepath}"; then if test ! -f "${cache_filepath}"; then
read package_name package_ver < <(get_package_name_ver "${cache_package}") read cache_package_name cache_package_ver < <(get_package_name_ver "${cache_package}")
echo -n " Caching ${package_name} to ${cache_filepath}..." echo -n " Caching ${cache_package_name} to ${cache_filepath}..."
# Pipe all package files (no folders) to Tar. # Pipe all package files (no folders) to Tar.
dpkg -L "${package_name}" | dpkg -L "${cache_package_name}" |
while IFS= read -r f; do while IFS= read -r f; do
if test -f $f; then echo "${f:1}"; fi; #${f:1} removes the leading slash that Tar disallows if test -f $f; then echo "${f:1}"; fi; #${f:1} removes the leading slash that Tar disallows
done | done |
xargs tar -czf "${cache_filepath}" -C / xargs tar -czf "${cache_filepath}" -C /
echo "done." echo "done."
# Add package to manifest
manifest="${manifest}${package_name}:$(dpkg -s "${package_name}" | grep Version | awk '{print $2}'),"
fi fi
done
# Comma delimited name:ver pairs in the all packages manifest.
manifest_all="${manifest_all}${cache_package_name}:${cache_package_ver},"
done
done done
echo "done." echo "done."
manifest_filepath="${cache_dir}/manifest.log" manifest_all_filepath="${cache_dir}/manifest_all.log"
echo -n "Writing package manifest to ${manifest_filepath}..." echo -n "Writing all packages manifest to ${manifest_all_filepath}..."
# Remove trailing comma and write to manifest file. # Remove trailing comma and write to manifest_all file.
echo "${manifest:0:-1}" > "${manifest_filepath}" echo "${manifest_all:0:-1}" > "${manifest_all_filepath}"
echo "done."
manifest_main_filepath="${cache_dir}/manifest_main.log"
echo -n "Writing main requested packages manifest to ${manifest_main_filepath}..."
# Remove trailing comma and write to manifest_main file.
echo "${manifest_main:0:-1}" > "${manifest_main_filepath}"
echo "done." echo "done."