mirror of
https://github.com/awalsh128/cache-apt-pkgs-action.git
synced 2025-09-21 10:37:06 +00:00
Fix pre-existing dep bug in issue #36.
This commit is contained in:
parent
e9bcc93e33
commit
c0c05ca285
|
@ -52,7 +52,7 @@ for package in ${normalized_packages}; do
|
||||||
manifest_main="${manifest_main}${package_name}:${package_ver},"
|
manifest_main="${manifest_main}${package_name}:${package_ver},"
|
||||||
|
|
||||||
cached_packages="${cached_packages} ${package_name}:${package_version}"
|
cached_packages="${cached_packages} ${package_name}:${package_version}"
|
||||||
read dep_packages < <(get_dep_packages "${package_name}")
|
read dep_packages < <(get_dep_packages "${package_name}") || exit 2
|
||||||
cached_packages="${cached_packages} $(echo ${dep_packages} | tr '\n' ' ')"
|
cached_packages="${cached_packages} $(echo ${dep_packages} | tr '\n' ' ')"
|
||||||
|
|
||||||
if test -z "${dep_packages}"; then
|
if test -z "${dep_packages}"; then
|
||||||
|
|
23
lib.sh
23
lib.sh
|
@ -9,15 +9,23 @@ function normalize_package_list {
|
||||||
echo "${sorted}"
|
echo "${sorted}"
|
||||||
}
|
}
|
||||||
|
|
||||||
# Gets a package list of dependencies as newline delimited pairs
|
# Gets a package list of dependencies as space delimited pairs with each pair colon delimited.
|
||||||
# <name>:<version>\n<name:version>...
|
# <name>:<version> <name:version>...
|
||||||
function get_dep_packages {
|
function get_dep_packages {
|
||||||
echo $(apt-fast install --dry-run --yes "${1}" | \
|
local regex="^Inst ([^ ]+) (\[[^ ]+\]\s)?\(([^ ]+)"
|
||||||
grep "^Inst" | sort | awk '{print $2 $3}' | \
|
dep_packages=""
|
||||||
tr '(' ':' | grep -v "${1}:")
|
while read -r line; do
|
||||||
|
if [[ "${line}" =~ ${regex} ]]; then
|
||||||
|
dep_packages="${dep_packages}${BASH_REMATCH[1]}:${BASH_REMATCH[3]} "
|
||||||
|
else
|
||||||
|
log_err "Unable to parse package name and version from \"$line\""
|
||||||
|
exit 2
|
||||||
|
fi
|
||||||
|
done < <(apt-fast install --dry-run --yes "${1}" | grep "^Inst" | grep -v "^Inst ${1} " | sort)
|
||||||
|
echo "${dep_packages:0:-1}" # Removing trailing space.
|
||||||
}
|
}
|
||||||
|
|
||||||
# Split fully qualified package into name and version
|
# Split fully qualified package into name and version.
|
||||||
function get_package_name_ver {
|
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 version not found in the fully qualified package value.
|
||||||
|
@ -28,13 +36,14 @@ function get_package_name_ver {
|
||||||
}
|
}
|
||||||
|
|
||||||
function log { echo "$(date +%H:%M:%S)" "${@}"; }
|
function log { echo "$(date +%H:%M:%S)" "${@}"; }
|
||||||
|
function log_err { >&2 echo "$(date +%H:%M:%S)" "${@}"; }
|
||||||
|
|
||||||
function log_empty_line { echo ""; }
|
function log_empty_line { echo ""; }
|
||||||
|
|
||||||
# Writes the manifest to a specified file.
|
# Writes the manifest to a specified file.
|
||||||
function write_manifest {
|
function write_manifest {
|
||||||
log "Writing ${1} packages manifest to ${3}..."
|
log "Writing ${1} packages manifest to ${3}..."
|
||||||
# 0:-1 to remove trailing comma, delimit by newline and sort
|
# 0:-1 to remove trailing comma, delimit by newline and sort.
|
||||||
echo "${2:0:-1}" | tr ',' '\n' | sort > ${3}
|
echo "${2:0:-1}" | tr ',' '\n' | sort > ${3}
|
||||||
log "done"
|
log "done"
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue