awalsh128 / cache-apt-pkgs-action

Cache APT packages in GitHub Actions
Other
205 stars 35 forks source link

apt-cache does not find packages with nektos/act #125

Open BadIdeaException opened 9 months ago

BadIdeaException commented 9 months ago

I use nektos act to debug my workflows locally before committing them.

The following minimal reproducible example:

name: CI
on:
  workflow_dispatch:

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - uses: awalsh128/cache-apt-pkgs-action@latest
        with:
          packages: python3-semver python3-requests

fails:

[CI/build] ⭐ Run Main awalsh128/cache-apt-pkgs-action@latest
[CI/build]   🐳  docker cp src=/home/vagrant/.cache/act/awalsh128-cache-apt-pkgs-action@latest/ dst=/var/run/act/actions/awalsh128-cache-apt-pkgs-action@latest/
[CI/build] ⭐ Run Main ${GITHUB_ACTION_PATH}/pre_cache_action.sh \
  ~/cache-apt-pkgs \
  "$VERSION" \
  "$EXEC_INSTALL_SCRIPTS" \
  "$DEBUG" \
  "$PACKAGES"
echo "CACHE_KEY=$(cat ~/cache-apt-pkgs/cache_key.md5)" >> $GITHUB_ENV
[CI/build]   🐳  docker exec cmd=[bash --noprofile --norc -e -o pipefail /var/run/act/workflow/0-composite-pre-cache.sh] user= workdir=
| 08:35:29.331 Normalizing package list...
| Error encountered running apt-cache --quiet=0 --no-all-versions show python3-semver python3-requests
| Exited with status code 100; see combined output below:
| N: Unable to locate package python3-semver
| N: Unable to locate package python3-requests
| N: Unable to locate package python3-semver
| N: Unable to locate package python3-requests
| E: No packages found
[CI/build]   ❌  Failure - Main ${GITHUB_ACTION_PATH}/pre_cache_action.sh \
  ~/cache-apt-pkgs \
  "$VERSION" \
  "$EXEC_INSTALL_SCRIPTS" \
  "$DEBUG" \
  "$PACKAGES"
echo "CACHE_KEY=$(cat ~/cache-apt-pkgs/cache_key.md5)" >> $GITHUB_ENV
[CI/build] exitcode '1': failure
[CI/build]   ⚙  ::set-output:: package-version-list=
[CI/build]   ⚙  ::set-output:: all-package-version-list=
[CI/build]   ⚙  ::set-output:: cache-hit=false
[CI/build]   ❌  Failure - Main awalsh128/cache-apt-pkgs-action@latest
[CI/build] exitcode '1': failure
[CI/build] ⭐ Run Post awalsh128/cache-apt-pkgs-action@latest
[CI/build]   🐳  docker cp src=/home/vagrant/.cache/act/awalsh128-cache-apt-pkgs-action@latest/ dst=/var/run/act/actions/awalsh128-cache-apt-pkgs-action@latest/
[CI/build]   ✅  Success - Post awalsh128/cache-apt-pkgs-action@latest
[CI/build] 🏁  Job failed

It looks like, at the heart of it, apt-cache is unable to find the requested packages, but I haven't been able to find an exact explanation for its exit codes.

It works when I actually run it on GitHub, just not locally.

BadIdeaException commented 9 months ago

After further investigation:

I have manually logged into the container that act had spun up, and indeed, running apt-cache show python3-semver gives me same error. I then ran sudo apt update and, lo and behold, the error disappears.

Indeed, inserting run: sudo apt update as an extra step before cache-apt-pkgs-action makes the workflow work locally with act. I don't like having to insert extra steps for the sole purpose of making it play nice locally though.

At this point I felt like it might not be a bug with this action so much as a problem with act - they don't seem to have apt update'd in the default image? But that doesn't make sense either, because I can apt install python3-semver from the workflow. Without a previous apt update, this shouldn't be possible either.

I'm a little confused now...

awalsh128 commented 9 months ago

I would look at the package on install and then on update on the logs to see what the difference is. That would be a good start to the investigation. Post it here.

BadIdeaException commented 8 months ago

Hi and thanks for your response. Can you elaborate on what you mean by "on install" and "on update"?

hbontempo-cw commented 6 months ago

Hi!

Had this issue while trying to use this action on a pipeline. Turns out that the runner I was using (a self-hosted one) had no information about any almost any package, as consequence when the action tries to run a apt-cache --quiet=0 --no-all-versions show build-essential package-x package-y (here).


Since @BadIdeaException has seen the problem while using act I suspect the runner image used to simulate the GitHub runner suffers from the same problem.

olivier-thatch commented 6 months ago

Hi, we're observing the same issue with self-hosted runners. Our runners use the RunsOn AWS images which are based on the official GitHub Action images, so I'm not entirely sure what exactly is different. Running sudo apt-get update before calling the cache-apt-pkgs-action fixes the issue, but it would be nice if the action handled this gracefully.

I haven't dug into the code but I assume the action does run apt-get update anyway at some point, so maybe it's just a matter of reordering some steps to ensure apt-get update runs before the call to apt-cache that normalizes package names?

hbontempo-cw commented 5 months ago

Not sure if that's simple. I would expect not to run a apt update if the packages I requested are already installed on the system.