Quantcast
Channel: Clear cache in GitHub Actions - Stack Overflow
Viewing all articles
Browse latest Browse all 12

Answer by TrinitronX for Clear cache in GitHub Actions

$
0
0

Here's another automated solution similar to @beatngu13's cache key invalidation method. This one uses a generated timestamp file that gets committed and then used in a hashFiles(...) prefix to the cache key.

Included is a set of GNU Makefile targets to make using this method very easy: make clear-github-cache

Note: Make sure each Makefile"recipe" section is indented with 1 tab character! StackOverflow converts tabs to spaces in the code block.

.github/clear_github_actions_cache:    date  +%s > .github/clear_github_actions_cache.PHONY: clean-github-cache-file clear-github-cacheclear-github-cache: clean-github-cache-file .github/clear_github_actions_cache ## Force GitHub Actions Cache key to change for fresh CI run    git add .github/clear_github_actions_cache    git commit -m "Clear GitHub Actions Cache @ $$(cat .github/clear_github_actions_cache)"clean-github-cache-file: ## Remove GitHub Actions Cache timestamp invalidator file.    [ -f '.github/clear_github_actions_cache' ] && rm -f '.github/clear_github_actions_cache' || true

Then, inside the GitHub Actions workflow YAML, add a cache key prefix that uses the hash of this file:

      - name: Cache R packages        if: runner.os != 'Windows'        uses: actions/cache@v2        with:          path: ${{ env.R_LIBS_USER }}          key: ${{ runner.os }}-${{ runner.arch }}-${{ hashFiles('.github/clear_github_actions_cache') }}-${{ hashFiles('.github/R-version') }}-${{ hashFiles('.github/depends.Rds') }}          restore-keys: |            ${{ runner.os }}-${{ runner.arch }}-${{ hashFiles('.github/clear_github_actions_cache') }}-${{ hashFiles('.github/R-version') }}-${{ hashFiles('.github/depends.Rds') }}            ${{ runner.os }}-${{ runner.arch }}-${{ hashFiles('.github/clear_github_actions_cache') }}-${{ hashFiles('.github/R-version') }}-            ${{ runner.os }}-${{ runner.arch }}-${{ hashFiles('.github/clear_github_actions_cache') }}-

Now just run:

make clear-github-cache

This generates and commits a file, .github/clear_github_actions_cache, with Unix timestamp as contents. The hashFiles(...) cache key prefix uses this and will generate a unique hash of this file as a prefix to the rest of the cache / restore-key.

Next time you use git push, the cache key will be invalidated... effectively running GitHub Actions with an empty cache.


Viewing all articles
Browse latest Browse all 12

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>