cache icon indicating copy to clipboard operation
cache copied to clipboard

feat: Add force-overwrite for cache

Open PrinsFrank opened this issue 1 year ago • 1 comments

Description

This PR adds a force-overwrite options to force overwrite an already existing cache.

I could use some help with the implementation. I'm native to PHP and not familiar with where all the code lives in the NPM packages. There is a CLI available with this exact command, but I guess it would make sense to implement the request to delete a cache in typescript just as all the other request, but I don't know where to. Any pointer or help would be appreciated!

Motivation and Context

When working with very long workflows and incremental changes any tiny change in cache can be helpful. That's why currently I delete a cache when it exists with the following workflow:

- name: Pull PHPStan cache
  id: pull-phpstan-cache
  uses: actions/cache/restore@v3
  with:
    path: ${{ env.PHPSTAN_CACHE_DIR }}
    key: phpstan-${{ github.ref_name }}
    restore-keys: |
      phpstan

- name: Run PHPStan
  run: composer run stan

- name: Install gh-actions cache plugin
  if: always()
  run: gh extension install actions/gh-actions-cache

- name: Clear previous version of PHPStan branch cache
  if: always()
  continue-on-error: true
  run: gh actions-cache delete phpstan-${{ github.ref_name }} -B ${{ github.ref }} --confirm

- name: Push PHPStan branch cache
  if: always()
  uses: actions/cache/save@v3
  with:
    path: ${{ env.PHPSTAN_CACHE_DIR }}
    key: phpstan-${{ github.ref_name }}

For context: without any caching the job will take about 20 minutes. With a main cache and a 'branch cache' that is never updated again, the job will take a few minutes after the first commit, but every next change results in the cache being further out of date and the job taking longer and longer. That's why deleting the existing cache will speed things up significantly.

How Has This Been Tested?

N/A

Screenshots (if appropriate):

N/A

Types of changes

  • [ ] Bug fix (non-breaking change which fixes an issue)
  • [x] New feature (non-breaking change which adds functionality)
  • [ ] Breaking change (fix or feature that would cause existing functionality to change)
  • [ ] Documentation (add or update README or docs)

Checklist:

  • [x] My code follows the code style of this project.
  • [x] My change requires a change to the documentation.
  • [x] I have updated the documentation accordingly.
  • [x] I have read the CONTRIBUTING document.
  • [ ] I have added tests to cover my changes.
  • [ ] All new and existing tests passed.

PrinsFrank avatar Jan 22 '24 17:01 PrinsFrank

@joshmgross Would you mind reviewing this, or could you point me to the right person for that? This would close #342 which has hundreds of upvotes, mentions and a lot of comments.

PrinsFrank avatar Aug 01 '24 21:08 PrinsFrank