awalsh128 / cache-apt-pkgs-action

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

Fails to install on self-hosted runners #107

Closed nadenf closed 9 months ago

nadenf commented 1 year ago

When using the following on a self-hosted runner:

      - name: Install Packages
        uses: awalsh128/cache-apt-pkgs-action@latest
        with:
          packages: cmake curl gcc gnupg jq pkg-config python3-pip tar unzip zip zlib1g-dev
          version: 1.0

It fails with the following error messages:

root is not in the sudoers file.  This incident will be reported.
root is not in the sudoers file.  This incident will be reported.

On self-hosted the user is "runner" and it does have permission to call sudo. But I suspect on managed runners if you call sudo as root it allows it whilst on self-hosted it does not.

Because the following code seems to somehow call sudo twice on the apt_fast_installation method:

apt_fast_installation() {
  if ! type aria2c >/dev/null 2>&1; then
    sudo apt-get update
    sudo apt-get install -y aria2
  fi

  wget https://raw.githubusercontent.com/ilikenwf/apt-fast/master/apt-fast -O /usr/local/sbin/apt-fast
  chmod +x /usr/local/sbin/apt-fast
  if ! [[ -f /etc/apt-fast.conf ]]; then
    wget https://raw.githubusercontent.com/ilikenwf/apt-fast/master/apt-fast.conf -O /etc/apt-fast.conf
  fi
}

if [[ "$EUID" -eq 0 ]]; then
  apt_fast_installation
else
  type sudo >/dev/null 2>&1 || { echo "sudo not installed, change into root context" >&2; exit 1; }

  DECL="$(declare -f apt_fast_installation)"
  sudo bash -c "$DECL; apt_fast_installation"
fi'
awalsh128 commented 1 year ago

Thanks for your patience.

Sounds like this is something that should get filed against https://github.com/ilikenwf/apt-fast ? Happy to implement a workaround in the meantime though if you can suggest one.

awalsh128 commented 9 months ago

Since I haven't heard anything, I am going to close it out but feel free to respond if you still need help.