├── .github ├── dependabot.yaml └── workflows │ └── test.yaml ├── CHANGELOG.md ├── LICENSE ├── README.md └── action.yml /.github/dependabot.yaml: -------------------------------------------------------------------------------- 1 | version: 2 2 | updates: 3 | - package-ecosystem: "github-actions" 4 | directory: "/" 5 | schedule: 6 | interval: "daily" 7 | -------------------------------------------------------------------------------- /.github/workflows/test.yaml: -------------------------------------------------------------------------------- 1 | name: Test action 2 | on: 3 | push: 4 | workflow_dispatch: 5 | 6 | jobs: 7 | create-caches: 8 | name: Prepare action test 9 | runs-on: ubuntu-22.04 10 | steps: 11 | - name: Init Cache 1 12 | uses: actions/cache@v4 13 | with: 14 | path: .cache-test/one 15 | key: ${{ runner.os }}-test-1 16 | - name: Init Cache 2 17 | uses: actions/cache@v4 18 | with: 19 | path: .cache-test/two 20 | key: ${{ runner.os }}-test-2 21 | - name: Init Cache 3 22 | uses: actions/cache@v4 23 | with: 24 | path: .cache-test/three 25 | key: ${{ runner.os }}-test-3 26 | - name: Fill Caches 27 | run: | 28 | for i in one two three; do 29 | mkdir -p ".cache-test/$i" 30 | echo $i >> ".cache-test/$i/$i" 31 | done 32 | 33 | test-action: 34 | name: Test action 35 | runs-on: ubuntu-22.04 36 | needs: create-caches 37 | 38 | steps: 39 | - name: Check out Wipe-Cache action 40 | uses: actions/checkout@v4 41 | with: 42 | path: ./.github/actions/wipe-cache 43 | 44 | - name: Wipe caches 45 | uses: ./.github/actions/wipe-cache 46 | with: 47 | page-size: 2 48 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | 3 | ## [v1] - 2022-07-07: Initial release 4 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022 Markus Dobel 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Wipe Github Actions Cache 2 | 3 | This action deletes *all* actions caches (created with [actions/cache](https://github.com/actions/cache)) 4 | attached to the current repository. 5 | 6 | ## Usage 7 | 8 | ### Example Workflow 9 | 10 | ```yaml 11 | name: Clear all Github actions caches on sundays 12 | on: 13 | schedule: 14 | - cron: "0 0 * * 0" 15 | workflow_dispatch: 16 | 17 | jobs: 18 | my-job: 19 | name: Delete all caches 20 | runs-on: ubuntu-20.04 21 | 22 | steps: 23 | - name: Clear caches 24 | uses: easimon/wipe-cache@main 25 | with: 26 | dry-run: 'true' 27 | ``` 28 | 29 | ### Inputs 30 | 31 | ```yaml 32 | github-token: 33 | description: 'Your GITHUB_TOKEN.' 34 | required: false 35 | default: ${{ github.token }} 36 | dry-run: 37 | description: 'List caches only, do not clear them.' 38 | required: false 39 | default: 'false' 40 | ``` 41 | -------------------------------------------------------------------------------- /action.yml: -------------------------------------------------------------------------------- 1 | name: 'Wipe Github Actions cache' 2 | description: 'Wipes all Github Actions caches for a repository.' 3 | branding: 4 | icon: 'archive' 5 | color: 'orange' 6 | inputs: 7 | github-token: 8 | description: 'Your GITHUB_TOKEN.' 9 | required: false 10 | default: ${{ github.token }} 11 | dry-run: 12 | description: 'List caches only, do not clear them.' 13 | required: false 14 | default: 'false' 15 | page-size: 16 | description: 'Page size for cache listing.' 17 | required: false 18 | default: '100' 19 | runs: 20 | using: "composite" 21 | steps: 22 | - name: List caches 23 | id: list-caches 24 | shell: bash 25 | env: 26 | GH_TOKEN: ${{ inputs.github-token }} 27 | PAGE_SIZE: ${{ inputs.page-size }} 28 | run: | 29 | function list_caches { 30 | local pageindex="$1" 31 | gh api \ 32 | -H 'Accept: application/vnd.github+json' \ 33 | "/repos/${GITHUB_REPOSITORY}/actions/caches?per_page=${PAGE_SIZE}&page=${pageindex}" 34 | } 35 | 36 | pageindex=1 37 | 38 | echo "fetching page ${pageindex}..." 39 | first="$(list_caches "${pageindex}")" 40 | total_count="$(jq -r '.total_count' <<< "${first}")" 41 | all_ids="$(jq '.actions_caches[].id' <<< "${first}" | tr '\n' ' ')" 42 | 43 | remaining="$((total_count-PAGE_SIZE))" 44 | echo " cache ids in page ${pageindex}: ${all_ids}, ${remaining} remaining." 45 | while [[ $remaining > 0 ]]; do 46 | pageindex="$((pageindex+1))" 47 | echo "fetching page ${pageindex}..." 48 | ids="$(list_caches "${pageindex}" | jq '.actions_caches[].id' | tr '\n' ' ')" 49 | 50 | all_ids="${all_ids} ${ids}" 51 | remaining="$((remaining-PAGE_SIZE))" 52 | if [[ $remaining < 0 ]]; then remaining=0; fi 53 | echo " cache ids in page ${pageindex}: ${ids}, ${remaining} remaining." 54 | done 55 | 56 | echo "cache ids total: ${all_ids}" 57 | echo "cache_ids=$all_ids" >> "$GITHUB_OUTPUT" 58 | 59 | - name: Wipe caches 60 | id: wipe 61 | shell: bash 62 | env: 63 | GH_TOKEN: ${{ inputs.github-token }} 64 | run: | 65 | for id in ${{ steps.list-caches.outputs.cache_ids }}; do 66 | if [[ "${{ inputs.dry-run }}" == 'true' ]]; then 67 | echo "would delete cache $id using following command:" 68 | echo gh api \ 69 | --method DELETE \ 70 | -H 'Accept: application/vnd.github+json' \ 71 | "/repos/${GITHUB_REPOSITORY}/actions/caches/$id" 72 | else 73 | echo "deleting cache $id" 74 | gh api \ 75 | --method DELETE \ 76 | -H 'Accept: application/vnd.github+json' \ 77 | "/repos/${GITHUB_REPOSITORY}/actions/caches/$id" 78 | fi 79 | done 80 | --------------------------------------------------------------------------------