mirror of
https://github.com/awalsh128/cache-apt-pkgs-action.git
synced 2026-06-16 04:04:53 +00:00
Fix apt-cache package lookup failure in nektos/act environments (#172)
* Initial plan * Add apt package list update to fix nektos/act compatibility Co-authored-by: awalsh128 <2087466+awalsh128@users.noreply.github.com> * Remove build artifacts and update .gitignore Co-authored-by: awalsh128 <2087466+awalsh128@users.noreply.github.com> * Refactor apt list update logic into shared library function Co-authored-by: awalsh128 <2087466+awalsh128@users.noreply.github.com> * Only update apt lists when running in nektos/act environment Co-authored-by: awalsh128 <2087466+awalsh128@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: awalsh128 <2087466+awalsh128@users.noreply.github.com> Co-authored-by: Andrew Walsh <awalsh128@gmail.com>
This commit is contained in:
parent
cd5ee21d96
commit
599df6ec23
3
.gitignore
vendored
3
.gitignore
vendored
|
|
@ -1,2 +1,3 @@
|
|||
src/cmd/apt_query/apt_query*
|
||||
*.log
|
||||
apt_query*
|
||||
*.log
|
||||
|
|
|
|||
|
|
@ -42,12 +42,7 @@ if [ -n "${add_repository}" ]; then
|
|||
fi
|
||||
|
||||
log "Updating APT package list..."
|
||||
if [[ -z "$(find -H /var/lib/apt/lists -maxdepth 0 -mmin -5)" ]]; then
|
||||
sudo apt-fast update > /dev/null
|
||||
log "done"
|
||||
else
|
||||
log "skipped (fresh within at least 5 minutes)"
|
||||
fi
|
||||
update_apt_lists_if_stale
|
||||
|
||||
log_empty_line
|
||||
|
||||
|
|
|
|||
28
lib.sh
28
lib.sh
|
|
@ -135,6 +135,34 @@ function get_tar_relpath {
|
|||
fi
|
||||
}
|
||||
|
||||
###############################################################################
|
||||
# Updates APT package lists if they are stale (modified more than 5 minutes ago).
|
||||
# This ensures compatibility with environments like nektos/act where package lists
|
||||
# may be empty or stale. Only runs when ACT environment variable is set (nektos/act)
|
||||
# to avoid slowing down normal GitHub Actions runs.
|
||||
# Arguments:
|
||||
# None
|
||||
# Returns:
|
||||
# None
|
||||
###############################################################################
|
||||
function update_apt_lists_if_stale {
|
||||
# Only check for stale package lists when running in nektos/act
|
||||
# GitHub Actions runners have fresh package lists, so skip this overhead
|
||||
if [ "${ACT}" = "true" ]; then
|
||||
if [[ -z "$(find -H /var/lib/apt/lists -maxdepth 0 -mmin -5 2>/dev/null)" ]]; then
|
||||
log "APT package lists are stale, updating..."
|
||||
if command -v apt-fast > /dev/null 2>&1; then
|
||||
sudo apt-fast update > /dev/null 2>&1 || sudo apt update > /dev/null 2>&1 || true
|
||||
else
|
||||
sudo apt update > /dev/null 2>&1 || true
|
||||
fi
|
||||
log "APT package lists updated"
|
||||
else
|
||||
log "APT package lists are fresh (within 5 minutes), skipping update"
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
function log { echo "${@}"; }
|
||||
function log_err { >&2 echo "${@}"; }
|
||||
|
||||
|
|
|
|||
|
|
@ -32,6 +32,10 @@ input_packages="${@:6}"
|
|||
|
||||
# Trim commas, excess spaces, and sort.
|
||||
log "Normalizing package list..."
|
||||
|
||||
# Ensure APT package lists are updated if stale (for nektos/act compatibility)
|
||||
update_apt_lists_if_stale
|
||||
|
||||
packages="$(get_normalized_package_list "${input_packages}")"
|
||||
log "done"
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue