Skip to content

Commit

Permalink
Use date for age based cache invalidation (techservicesillinois#77)
Browse files Browse the repository at this point in the history
The script weekold.py was used to invalidate a cache after a week.
The script worked but the cache contents were not updated since
cache contents are saved only on a cache miss. The only way to
update a Github Actions cache is to change the key.

This commit removes the weekold.py script, and inserts the week
number in the cache key name. This ensures that the cache can never
be more than a week old.
  • Loading branch information
ddriddle authored Feb 26, 2021
1 parent feb8b08 commit d77c1bb
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 52 deletions.
29 changes: 12 additions & 17 deletions .github/workflows/cicd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -84,37 +84,32 @@ jobs:
path: ${{ steps.pip-cache.outputs.dir }}
key: ${{ runner.os }}-pip-${{ secrets.CACHE_VERSION }}

- name: Get date
id: date
run: echo "::set-output name=week::$(date '+%U')"

- name: Cache tox virtualenv
id: tox
uses: actions/cache@v2
with:
path: |
**/.tox
**/cache
key: ${{ runner.os }}-${{ matrix.python-version }}-tox-${{ hashFiles('**/setup.py', '**/tox.ini') }}-${{ secrets.CACHE_VERSION }}
key: ${{ runner.os }}-${{ matrix.python-version }}-tox-${{ hashFiles('**/setup.py', '**/tox.ini') }}-${{ steps.date.outputs.week }}-${{ secrets.CACHE_VERSION }}

- name: Is cache old?
# touch cache and tox env so make will not rebuild them
- name: Update timestamps
if: steps.tox.outputs.cache-hit == 'true'
id: age
run: |
set -x
if python scripts/weekold.py cache/*
then
# touch cache and tox env so make will not rebuild them
touch -c cache .tox/wheel/pyvenv.cfg
else
# If cache is old force rebuild of tox virtualenv(s)
rm -rf .tox cache
fi
run: touch -c cache .tox/wheel/pyvenv.cfg
shell: bash

- name: Install system dependencies
if: matrix.os == 'ubuntu-latest' && (steps.tox.outputs.cache-hit != 'true' || steps.age.outputs.weekold == 'True')
if: matrix.os == 'ubuntu-latest' && steps.tox.outputs.cache-hit != 'true'
run: |
sudo apt-get install -y libxml2-dev libxslt-dev
- name: Upgrade pip
if: steps.tox.outputs.cache-hit != 'true' || steps.age.outputs.weekold == 'True'
if: steps.tox.outputs.cache-hit != 'true'
run: |
python -m pip install --upgrade --upgrade-strategy eager pip
Expand All @@ -123,11 +118,11 @@ jobs:
python -m pip install --upgrade --upgrade-strategy eager tox wheel
- name: Update Python wheel cache
if: steps.tox.outputs.cache-hit != 'true' || steps.age.outputs.weekold == 'True'
if: steps.tox.outputs.cache-hit != 'true'
run: make cache

- name: Install
if: steps.tox.outputs.cache-hit != 'true' || steps.age.outputs.weekold == 'True'
if: steps.tox.outputs.cache-hit != 'true'
run: make install

- name: Installed dependencies
Expand Down
35 changes: 0 additions & 35 deletions scripts/weekold.py

This file was deleted.

0 comments on commit d77c1bb

Please sign in to comment.