Setting up a permanent Python virtual environment for GitHub Actions

In my project I have a script which prepares a Python virtual environment:

  • It creates a directory at myproject/venv/
  • Prepares a Python virtual environment using python -m venv myproject/venv/
  • Installs some Python packages in the virtual environment using pip

I need this virtual environment to be setup properly so that I can run unit tests. However, I don’t want to setup a new virtual environment for every job on GitHub-hosted runners. I would like to configure things so that I only need to create this virtual environment once, and then use it every time I run a new workflow. Is there a way to do this?