mirror of
https://github.com/awalsh128/cache-apt-pkgs-action.git
synced 2025-12-25 04:41:27 +00:00
Only update apt lists when running in nektos/act environment
Co-authored-by: awalsh128 <2087466+awalsh128@users.noreply.github.com>
This commit is contained in:
parent
d6013a02d0
commit
75561fd6ee
23
lib.sh
23
lib.sh
|
|
@ -138,23 +138,28 @@ function get_tar_relpath {
|
|||
###############################################################################
|
||||
# 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.
|
||||
# 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 {
|
||||
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
|
||||
# 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
|
||||
sudo apt update > /dev/null 2>&1 || true
|
||||
log "APT package lists are fresh (within 5 minutes), skipping update"
|
||||
fi
|
||||
log "APT package lists updated"
|
||||
else
|
||||
log "APT package lists are fresh (within 5 minutes), skipping update"
|
||||
fi
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue