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
* `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

View file

@ -26,7 +26,10 @@ outputs:
# Need to output true and false instead of true and nothing.
value: ${{ steps.load-cache.outputs.cache-hit || false }}
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 }}
runs:
@ -54,5 +57,6 @@ runs:
/ \
"${{ steps.load-cache.outputs.cache-hit }}" \
${{ 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

View file

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