Skip to content

"Force deletion of caches overriding default cache eviction policy" example code can delete the wrong branch's cache #1107

@mikeage

Description

@mikeage

The page at https://github.com/actions/cache/blob/main/tips-and-workarounds.md#force-deletion-of-caches-overriding-default-cache-eviction-policy gives an example of deleting a cache created on a feature branch when the PR is merged, to prevent the feature branch's caches from taking up space and potentially evicting the cache from the master/main branch. The example code triggers on:

on:
  pull_request:
    types:
      - closed

and runs against:

...
          REPO=${{ github.repository }}
          BRANCH=${{ github.ref }}

The documentation at https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#pull_request suggests that $GITHUB_REF / ${{ github.ref }} should contain refs/pull/:prNumber/merge.

However, in my testing, this is only true if the PR is closed without being merged. In that case, it does, indeed, point to refs/pull/:prNumber/merge. If the PR is merged, however, then the value of ${{ github.ref }} is the target branch, e.g., main. As such, this code will then clear the main branch's cache, which is not only pointless, but harmful!

As such, in our code at icosa-foundation/open-brush#397, I changed it to use ${{ format('refs/pull/{0}/merge', github.event.number) }}. This behaves correct in both the regular close, and close-on-merge cases.

The root cause may a general github actions issue, but until that's confirmed or fixed or clarified, I think the example should be modified accordingly.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions