Skip to content

Delete caches that are related to the context of the triggered workflow event without any configuration.

License

Notifications You must be signed in to change notification settings

4m-mazi/souji-action

Use this GitHub action with your project
Add this Action to an existing workflow or create a new one
View on Marketplace

Repository files navigation

Souji Action 🧹

GitHub Super-Linter CI Check dist/ CodeQL

Souji Action is a GitHub Action that deletes all GitHub Actions Caches related to the context of the triggered workflow event, without any configuration required.

Why

GitHub Actions Caches have branch scope restriction in place. This means that there are caches that will never be restored in the future. This action allows you to easily delete such caches.

Usage

actions:write permission is required to delete caches.

name: cleanup caches by a branch
on:
  pull_request_target:
    types:
      - closed
  delete:
  workflow_dispatch:
    inputs:
      branchNames:
        description: 'List of branch(ref) names with caches to be deleted'
        required: false
        type: string

jobs:
  cleanup:
    runs-on: ubuntu-latest
    permissions:
      actions: write
    steps:
      - name: Cleanup
        uses: 4m-mazi/souji-action@v1.3.0
        with:
          branch-names: ${{ inputs.branchNames }}

This workflow cleans up caches for branches when they are merged(closed) or deleted.
This will clear the following cache:

  • merge ref refs/pull/<number>/merge
    • When a pull request is merged or closed, this workflow removes cached data associated with the merge ref.
  • branch <branch name>
    • When a branch is deleted, this workflow deletes the cached data associated with the branch.

Inputs

Note

List type is a string of characters separated by newlines or spaces.

branch-names: |
  main
  refs/pull/123/merge
  refs/tags/1.0.0
branch-names: main refs/pull/123/merge refs/tags/1.0.0
Name Description Type Default
dry-run If true, dry-run caches deletion. Boolean false
branch-names List of branch(ref) names with caches to be deleted (e.g., main refs/pull/123/merge refs/tags/1.0.0) List N/A

Supported events

Important

The branch(ref) to be deleted is determined by the context of the event.
Please note that this is not the same as $GITHUB_REF(github.ref).

event branch name format of caches to be deleted
check_run <branch name>
check_suite <branch name>
create (branch) <branch name>
create (tag) refs/tags/<tag name>
delete (branch) <branch name>
delete (tag) refs/tags/<tag name>
deployment_status <branch name>
issue_comment 1 refs/pull/<number>/merge
merge_group <branch name>
pull_request 2 refs/pull/<number>/merge
pull_request_review refs/pull/<number>/merge
pull_request_review_comment refs/pull/<number>/merge
pull_request_target refs/pull/<number>/merge
push (branch) <branch name>
push (tag) refs/tags/<tag name>
registry_package refs/tags/<tag name>
release refs/tags/<tag name>
workflow_dispatch (branch) <branch name>
workflow_dispatch (tag) refs/tags/<tag name>
workflow_run <branch name>

Footnotes

  1. Only works with pull request comments.

  2. This action doesn't work when triggered by a pull_request event if the pull request is a cross-repository pull request.
    Therefore, it is recommended to use the pull_request_target event instead.

About

Delete caches that are related to the context of the triggered workflow event without any configuration.

Resources

License

Stars

Watchers

Forks