I have a CI that runs at every pull request created and at every push of a new commit. This CI installs Python dependencies and then run some tests. I use two separate requirements.txt files because one of them contains heavier packages and they are handled differently in Docker.
I am trying to use the actions/cache@v2
action to cache the dependencies but from what I could understand, it only caches between runs in the same branch. So when I create a new PR, for example, cache is not detected from another branch and everything is installed from scratch.
Is there a way to cache dependencies across workflow runs? So the cache created by the CI in one branch can be used by another branch if nothing was changed in the requirements?
Looking at the logs of the workflow that ran in two different branches the cache key is the same:
- Workflow in
branchA
Cache not found for input keys: /opt/hostedtoolcache/Python/3.8.12/x64-03a86b868f006751e123da18168c989ab4c3c2713de4f5c87cf732ffbb6fb4ae-cd1b416332d9d5b55f413e2bd74c2efce6107aef1ce3f497fa5a81b9abc83deb
- Workflow in
branchB
Cache not found for input keys: /opt/hostedtoolcache/Python/3.8.12/x64-03a86b868f006751e123da18168c989ab4c3c2713de4f5c87cf732ffbb6fb4ae-cd1b416332d9d5b55f413e2bd74c2efce6107aef1ce3f497fa5a81b9abc83deb
- This is my workflow:
name: ci
on:
pull_request:
types: [opened, synchronize]
branches-ignore:
- "master"
- "staging"
push:
branches-ignore:
- "master"
- "staging"
jobs:
run-tests:
name: Run tests
runs-on: ubuntu-latest
steps:
- name: Set up Python 3.8
uses: actions/setup-python@v2
with:
python-version: 3.8
- name: Checkout repository
uses: actions/checkout@v2
- name: Cache dependencies
uses: actions/cache@v2
with:
path: ${{ env.pythonLocation }}
key: ${{ env.pythonLocation }}-${{ hashFiles('requirements.txt') }}-${{ hashFiles('requirements-ml.txt') }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install -r requirements.txt
python -m pip install -r requirements-ml.txt