Tidy Docker #156
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Tidy Docker | |
| # Remove all docker images from the github registry that match; | |
| # | |
| # 1. <sha> or <untagged> older than 2 days | |
| # 2. pr-<NUMBER> older than 5 days | |
| # 3. anything that isn't `latest`, `edge` or a release tag | |
| on: | |
| schedule: | |
| - cron: "0 0 */2 * *" # Every 2 days at 00:00 UTC | |
| workflow_dispatch: | |
| inputs: | |
| dry-run: | |
| description: Perform a dry run without deleting images | |
| required: false | |
| default: false | |
| type: boolean | |
| force: | |
| description: Remove all non-persistent images NOW (i.e not latest, edge, a release tag or one from an open PR) | |
| required: false | |
| default: false | |
| type: boolean | |
| concurrency: | |
| group: tidy-docker | |
| cancel-in-progress: true | |
| permissions: | |
| packages: write | |
| env: | |
| PERSIST: ^edge|latest|(\d+\.\d+\.\d+(-[a-z]+(\.\d+)?)?)$ | |
| PACKAGES: merod,mero-relayer | |
| # ^~~ comma separated list of packages to clean | |
| jobs: | |
| clean: | |
| name: Clean Docker Images | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| with: | |
| ref: ${{ github.event.pull_request.head.sha }} | |
| - name: Cleanup non-persistent images, except open PRs | |
| uses: dataaxiom/ghcr-cleanup-action@v1 | |
| with: | |
| dry-run: ${{ github.event.inputs.dry-run }} | |
| package: ${{ env.PACKAGES }} | |
| use-regex: true | |
| exclude-tags: ${{ env.PERSIST }}|^pr-\d+$ | |
| keep-n-tagged: 0 | |
| delete-untagged: true | |
| older-than: ${{ github.event.inputs.force == 'true' && '0 days' || '2 days'}} | |
| delete-orphaned-images: true | |
| delete-partial-images: true | |
| validate: true | |
| - name: Get open PRs | |
| id: prepare | |
| env: | |
| GH_TOKEN: ${{ github.token }} | |
| run: | | |
| prs=( $(gh pr list --state open --json number -q '.[].number') ) | |
| echo "Found open PRs: ${prs[@]}" | |
| expr="$(IFS='|'; echo "${prs[*]}")" | |
| echo "Regex for PRs: $expr" | |
| echo "active_prs=$expr" >> $GITHUB_OUTPUT | |
| - name: Cleanup closed PR images | |
| uses: dataaxiom/ghcr-cleanup-action@v1 | |
| with: | |
| dry-run: ${{ github.event.inputs.dry-run }} | |
| package: ${{ env.PACKAGES }} | |
| use-regex: true | |
| delete-tags: pr-\d+ | |
| exclude-tags: ^pr-(${{ steps.prepare.outputs.active_prs }})$ | |
| older-than: ${{ github.event.inputs.force == 'true' && '0 days' || '5 days'}} |