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 https://github.com/icosa-gallery/open-brush/pull/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.
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:
and runs against:
The documentation at https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#pull_request suggests that
$GITHUB_REF
/${{ github.ref }}
should containrefs/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 https://github.com/icosa-gallery/open-brush/pull/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.