/souji-action

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

Primary LanguageTypeScriptMIT LicenseMIT

Souji Action 🧹 OpenSSF Scorecard

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

Souji-action can be used either as a reusable workflow or as an action.

actions:write permission is required to delete caches.
contents:read permission is required to checkout private repositories.

  • Reusable workflow
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:
    permissions:
      actions: write
      contents: read
    uses: 4m-mazi/souji-action/.github/workflows/_souji.yml@v1.4.8
    with:
      branch-names: ${{ inputs.branchNames }}
  • Action
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.4.8
        with:
          branch-names: ${{ inputs.branchNames }}

These workflows 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

All inputs are optional.

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 #branch-names-default-values

branch-names default values

If branch-names is not specified, the value derived from the context of the event is used as the default value.

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 concrete example
check_run <branch name> main
check_suite <branch name> main
create (branch) <branch name> test
create (tag) refs/tags/<tag name> refs/tags/v2.3.4
delete (branch) <branch name> gh-readonly-queue/main/pr-813-bef2983ddf2ae45fbf6ef6c788732c6bc7797cae
delete (tag) refs/tags/<tag name> refs/tags/v2.3.4
deployment_status <branch name> test
issue_comment 1 refs/pull/<number>/merge refs/pull/123/merge
merge_group <branch name> gh-readonly-queue/main/pr-746-48d2a411fc179d6938d5c57a5040d1b38f3eb198
pull_request 2 refs/pull/<number>/merge refs/pull/123/merge
pull_request_review refs/pull/<number>/merge refs/pull/123/merge
pull_request_review_comment refs/pull/<number>/merge refs/pull/123/merge
pull_request_target refs/pull/<number>/merge refs/pull/123/merge
push (branch) <branch name> test
push (tag) refs/tags/<tag name> refs/tags/v2.3.4
registry_package refs/tags/<tag name> refs/tags/v2.3.4
release refs/tags/<tag name> refs/tags/v2.3.4
workflow_dispatch (branch) <branch name> test
workflow_dispatch (tag) refs/tags/<tag name> refs/tags/v2.3.4
workflow_run <branch name> main

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.