Is there anyway to cache python itself with actions/setup-python?

I use actions/setup-python@v4 frequently in the following:

name: Build

on: [push]

jobs:
  build:
    runs-on: ubuntu-22.04
    container:
      image: catthehacker/ubuntu:act-22.04
  
    steps:
      - uses: actions/checkout@v3
      - uses: actions/setup-python@v4
        with:
          python-version: '3.7'

      - name: Update Ubuntu
        env:
          DEBIAN_FTONTEND: noninteractive
        run: sudo apt-get update

      - name: Install dependencies
        env:
          DEBIAN_FRONTEND: noninteractive
        run: sudo apt-get install -y -qq libtinfo5 ccache bc

I have two questions:

  1. I searched for a way to cache it but I only found a way to cache pip dependencies, not python itself. Is there a way to cache it?

  2. The image I’m using catthehacker/ubuntu:act-22.04 actually does include python 3.10.12. However even if I specify this version in the script, it says Version 3.10.12 was not found in the local cache and it goes ahead and download then install it. Why is it doing that and how can I avoid it?

I’m having the same problem, have you made any progress please?

Hello. In case you are using Docker Gitea runner you can mount the act-toolcache volume to the container image like this:

name: flake8 lint
run-name: ${{ gitea.actor }}
on: [push]

jobs:
  flake8:
    runs-on: ubuntu-latest
    container:
      image: catthehacker/ubuntu:act-22.04
      volumes:
        - act-toolcache:/opt/hostedtoolcache

    steps:
      - uses: actions/checkout@v3
      - uses: actions/setup-python@v4
        with:
          python-version: '3.12'
          architecture: 'x64'
          cache: 'pip'

This way, I got cache works: Python setup took only 2 seconds.