From 743bbabe69ccf57448441849f7b23881ca8b7a02 Mon Sep 17 00:00:00 2001 From: Jeff Jennings Date: Mon, 12 Aug 2024 12:54:27 -0400 Subject: [PATCH] update_stats workflow: set up and use actions cache --- .github/workflows/update_stats.yml | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/.github/workflows/update_stats.yml b/.github/workflows/update_stats.yml index 9050e6a..e472127 100644 --- a/.github/workflows/update_stats.yml +++ b/.github/workflows/update_stats.yml @@ -30,8 +30,29 @@ jobs: pip install setuptools --upgrade pip install . + # cache key syntax: https://docs.github.com/en/actions/writing-workflows/choosing-what-your-workflow-does/caching-dependencies-to-speed-up-workflows#using-contexts-to-create-cache-keys + - name: Restore cached files + id: cache-files-restore + uses: actions/cache/restore@v4 + with: + path: ./cache + key: ${{ runner.os }}-${{ hashFiles('~/.cache_key') }} - name: Run update script run: | python -m repo_stats.runner -a ${{ secrets.ADS_TOKEN }} -g ${{ secrets.GIT_TOKEN }} -c "cache" + # caches are immutable, so create a new one (new key) each time any of the files being cached change. + # the cache key will be new if any files in the cache path have been changed by 'repo_stats.runner'. + # otherwise the cache save will 'fail' (because there's no need to update it - that's fine) + - name: Update cached files + id: cache-files-save + uses: actions/cache/save@v4 + with: + path: ./cache + key: ${{ runner.os }}-${{ hashFiles('./cache') }} + + - name: Save cache key + run: | + echo ${{ hashFiles('./cache') }} >> ~/.cache_key +