Fix apt-cache package lookup failure in nektos/act environments#172
Fix apt-cache package lookup failure in nektos/act environments#172
Conversation
Co-authored-by: awalsh128 <2087466+awalsh128@users.noreply.github.com>
Co-authored-by: awalsh128 <2087466+awalsh128@users.noreply.github.com>
|
|
||
| # Trim commas, excess spaces, and sort. | ||
| log "Normalizing package list..." | ||
|
|
There was a problem hiding this comment.
Move this block to a library function in lib.sh and have it used in both locations
There was a problem hiding this comment.
Refactored the apt list update logic into update_apt_lists_if_stale() function in lib.sh and updated both pre_cache_action.sh and install_and_cache_pkgs.sh to use it. See commit d6013a0.
pre_cache_action.sh
Outdated
| # Uses the same logic as install_and_cache_pkgs.sh | ||
| 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 |
There was a problem hiding this comment.
Will this ever happen? apt-fast should have a guarantee of being installed
There was a problem hiding this comment.
The check for apt-fast is necessary in pre_cache_action.sh because apt-fast is not installed at that point (unlike in install_and_cache_pkgs.sh where it's installed first). The shared function now checks for apt-fast availability and falls back to apt if it's not present, making it work correctly in both contexts. See commit d6013a0.
There was a problem hiding this comment.
This will slow down the action though. The point is that this part run without needing to update. Is there a way to detect if the nektos/act is being ran?
There was a problem hiding this comment.
Modified the function to only check/update package lists when ACT=true (nektos/act environment). Normal GitHub Actions runs are unaffected and have zero performance overhead. See commit for details.
|
@copilot Please continue working on this PR. |
Co-authored-by: awalsh128 <2087466+awalsh128@users.noreply.github.com>
|
Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details. Warning Firewall rules blocked me from connecting to one or more addresses (expand for details)I tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
|
@copilot Please continue working on this PR. |
Co-authored-by: awalsh128 <2087466+awalsh128@users.noreply.github.com>
|
Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details. Warning Firewall rules blocked me from connecting to one or more addresses (expand for details)I tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
|
This actually fixes a problem I have in the following action: https://codeberg.org/Mynacol/flowpipeline/actions/runs/197#jobstep-2-21 Unfortunately, it still doesn't work when using this PR. But that's on the runner environment: https://codeberg.org/Mynacol/flowpipeline/actions/runs/200#jobstep-2-1421 |
Fixes apt-cache package lookup failures when using nektos/act for local GitHub Actions testing by automatically updating stale APT package lists, with zero performance impact on normal GitHub Actions runs.
Problem
When running this action with nektos/act (local GitHub Actions runner), the package normalization step fails because
apt-cache showis called beforeapt updatehas refreshed the package lists. This works fine on GitHub's runners which have pre-updated package lists, but nektos/act containers typically start with empty/stale package lists.Solution
Created a shared
update_apt_lists_if_stale()function inlib.shthat:ACTenvironment variable/var/lib/apt/listsis older than 5 minutespre_cache_action.shandinstall_and_cache_pkgs.shshare the same logicChanges Made
update_apt_lists_if_stale()function inlib.shwith ACT environment detectionpre_cache_action.shto call the shared function before package normalizationinstall_and_cache_pkgs.shto use the shared function instead of inline logicTesting
Performance Impact
Normal GitHub Actions (ACT not set): Zero overhead - function returns immediately without any checks
nektos/act (ACT=true): Checks package list freshness and updates only if stale (>5 minutes old)
This approach specifically targets the nektos/act issue while maintaining optimal performance for standard GitHub Actions workflows.
Fixes #125
Original prompt
💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.