From e5ab96be47fc1d9f03428e5dd67928f3c010b968 Mon Sep 17 00:00:00 2001 From: Andrew Walsh Date: Fri, 15 Jul 2022 12:56:06 -0700 Subject: [PATCH 1/4] Update to v3 cache action. --- action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/action.yml b/action.yml index c20f70a..9cd2164 100644 --- a/action.yml +++ b/action.yml @@ -45,7 +45,7 @@ runs: shell: bash - id: load-cache - uses: actions/cache@v2 + uses: actions/cache@v3 with: path: ~/cache-apt-pkgs key: cache-apt-pkgs_${{ env.CACHE_KEY }} From f7b89333d6f265bcd37cf611cc4a61824c626226 Mon Sep 17 00:00:00 2001 From: awalsh128 Date: Tue, 19 Jul 2022 20:02:22 -0700 Subject: [PATCH 2/4] Copy from master to staging. --- action.yml | 2 +- install_and_cache_pkgs.sh | 17 +++++++++-------- lib.sh | 10 +++++++++- 3 files changed, 19 insertions(+), 10 deletions(-) diff --git a/action.yml b/action.yml index c20f70a..9cd2164 100644 --- a/action.yml +++ b/action.yml @@ -45,7 +45,7 @@ runs: shell: bash - id: load-cache - uses: actions/cache@v2 + uses: actions/cache@v3 with: path: ~/cache-apt-pkgs key: cache-apt-pkgs_${{ env.CACHE_KEY }} diff --git a/install_and_cache_pkgs.sh b/install_and_cache_pkgs.sh index 2c22fb2..1d420b2 100755 --- a/install_and_cache_pkgs.sh +++ b/install_and_cache_pkgs.sh @@ -39,21 +39,22 @@ for package in ${normalized_packages}; do # 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="$(echo ${all_packages} | grep -v "${package_name}" | tr '\n' ,)" - if "${dep_packages}" == ","; then - dep_packages="none"; + read dep_packages < <(get_dep_packages "${package_name}") + if test -z "${dep_packages}"; then + dep_packages_text="none"; + else + dep_packages_text="${dep_packages}" fi log "- ${package_name}" log " * Version: ${package_ver}" - log " * Dependencies: ${dep_packages}" + log " * Dependencies: ${dep_packages_text}" log " * Installing..." # 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_name}" > /dev/null echo "done." - for cache_package in ${all_packages}; do + for cache_package in ${package_name}:${package_ver} ${dep_packages}; do cache_filepath="${cache_dir}/${cache_package}.tar.gz" if test ! -f "${cache_filepath}"; then @@ -65,7 +66,7 @@ for package in ${normalized_packages}; do if test -f $f || test -L $f; then echo "${f:1}"; fi; #${f:1} removes the leading slash that Tar disallows done | xargs tar -czf "${cache_filepath}" -C / - log "done (compressed size $(du -k "${cache_filepath}" | cut -f1))." + log "done (compressed size $(du -h "${cache_filepath}" | cut -f1))." fi # Comma delimited name:ver pairs in the all packages manifest. diff --git a/lib.sh b/lib.sh index f3757c9..fc8eb1e 100755 --- a/lib.sh +++ b/lib.sh @@ -9,9 +9,17 @@ function normalize_package_list { echo "${sorted}" } +# Gets a package list of dependencies as common delimited pairs +# :,... +function get_dep_packages { + echo $(apt-get install --dry-run --yes "${1}" | \ + grep "^Inst" | sort | awk '{print $2 $3}' | \ + tr '(' ':' | grep -v "${1}:") +} + # Split fully qualified package into name and version function get_package_name_ver { - IFS=\= read name ver <<< "${1}" + IFS=\: read name ver <<< "${1}" # If version not found in the fully qualified package value. if test -z "${ver}"; then ver="$(grep "Version:" <<< "$(apt show ${name})" | awk '{print $2}')" From a85a2de3b3bdb8a2ab3bcc5a3dbe297f9b22dd7c Mon Sep 17 00:00:00 2001 From: Andrew Walsh Date: Thu, 14 Jul 2022 21:23:42 -0700 Subject: [PATCH 3/4] Update installation to consider symlinks as well. Addresses problem raised in #25 --- action.yml | 5 +++-- install_and_cache_pkgs.sh | 13 ++----------- lib.sh | 9 ++++++++- 3 files changed, 13 insertions(+), 14 deletions(-) diff --git a/action.yml b/action.yml index 9cd2164..ee46a33 100644 --- a/action.yml +++ b/action.yml @@ -57,6 +57,7 @@ runs: / \ "${{ steps.load-cache.outputs.cache-hit }}" \ ${{ inputs.packages }} - 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)" + function create_list { local list=$(cat ~/cache-apt-pkgs/manifest_${1}.log | tr '\n' ','); echo ${list:0:-1}; }; + echo "::set-output name=package-version-list::$(create_list main)" + echo "::set-output name=all-package-version-list::$(create_list all)" shell: bash diff --git a/install_and_cache_pkgs.sh b/install_and_cache_pkgs.sh index 1d420b2..1049d9b 100755 --- a/install_and_cache_pkgs.sh +++ b/install_and_cache_pkgs.sh @@ -75,14 +75,5 @@ for package in ${normalized_packages}; do done log "done." -manifest_all_filepath="${cache_dir}/manifest_all.log" -log "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}" -log "done." - -manifest_main_filepath="${cache_dir}/manifest_main.log" -log "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}" -log "done." +write_manifest "all" "${manifest_all}" "${cache_dir}/manifest_all.log" +write_manifest "main" "${manifest_main}" "${cache_dir}/manifest_main.log" diff --git a/lib.sh b/lib.sh index fc8eb1e..74255ca 100755 --- a/lib.sh +++ b/lib.sh @@ -27,4 +27,11 @@ function get_package_name_ver { echo "${name}" "${ver}" } -function log { echo "$(date +%H:%M:%S)" "${@}"; } \ No newline at end of file +function log { echo "$(date +%H:%M:%S)" "${@}"; } + +function write_manifest { + log "Writing ${1} packages manifest to ${3}..." + # 0:-1 to remove trailing comma, delimit by newline and sort + echo "${2:0:-1}" | tr ',' '\n' | sort > ${3} + log "done." +} \ No newline at end of file From d3470979cfae1c59f7cb9fb238fe1a8b3329fcd8 Mon Sep 17 00:00:00 2001 From: awalsh128 Date: Tue, 19 Jul 2022 21:01:08 -0700 Subject: [PATCH 4/4] Fix all-package-version-list output bug. --- action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/action.yml b/action.yml index ee46a33..9a5ce3d 100644 --- a/action.yml +++ b/action.yml @@ -30,7 +30,7 @@ outputs: 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. ::).' - value: ${{ steps.post-cache.outputs.package-version-list }} + value: ${{ steps.post-cache.outputs.all-package-version-list }} runs: using: "composite"