Speed up you Github Actions by caching you Python packages install

Batiste
1 min readJun 30, 2023

--

Uncached run

Installing python packages on every CI run can be adding precious seconds before you can get a feedback. For my current project it was up to a minute. Github cache action can help us here.

My setup uses pipenv, but potentially a similar setup should work with pip, you just need to point to your pip install file.

    - name: Cache pipenv
uses: actions/cache@v3
id: cache-pipenv
with:
path: ${{ env.pythonLocation }}
key: ${{ runner.os }}-pip-${{ hashFiles('**/Pipfile.lock') }}
restore-keys: |
${{ runner.os }}-pipenv
- name: Install pipenv
if: steps.cache-pipenv.outputs.cache-hit != 'true'
run: |
python -m pip install --upgrade pipenv wheel
- name: Install Dependencies
if: steps.cache-pipenv.outputs.cache-hit != 'true'
run: |
pipenv install --system --deploy --dev

If everything works as intended, and once the cache is filled you should be able save some precious second, and github action credits.

Cache is hot, it is a hit

And voilà, you saved a minute on each build.

--

--