ci: create Docker images for PR preview (#772)
This commit is contained in:
56
.github/workflows/docker-cleanup.yaml
vendored
Normal file
56
.github/workflows/docker-cleanup.yaml
vendored
Normal file
@@ -0,0 +1,56 @@
|
||||
name: Docker PR Image Cleanup
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
types:
|
||||
- closed
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
packages: write
|
||||
|
||||
concurrency:
|
||||
group: docker-cleanup-${{ github.event.pull_request.number }}
|
||||
cancel-in-progress: false
|
||||
|
||||
jobs:
|
||||
enumerate:
|
||||
runs-on: ubuntu-latest
|
||||
if: ${{ !github.event.pull_request.head.repo.fork }}
|
||||
outputs:
|
||||
packages: ${{ steps.list.outputs.packages }}
|
||||
steps:
|
||||
- id: list
|
||||
env:
|
||||
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
ORG: stoatchat
|
||||
REPO: ${{ github.repository }}
|
||||
run: |
|
||||
set -euo pipefail
|
||||
packages=$(gh api --paginate \
|
||||
"/orgs/${ORG}/packages?package_type=container" \
|
||||
--jq "[.[] | select(.repository.full_name == \"${REPO}\") | .name]")
|
||||
echo "packages=${packages}" >> "$GITHUB_OUTPUT"
|
||||
|
||||
cleanup:
|
||||
needs: enumerate
|
||||
runs-on: ubuntu-latest
|
||||
if: ${{ needs.enumerate.outputs.packages != '[]' }}
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
package: ${{ fromJSON(needs.enumerate.outputs.packages) }}
|
||||
steps:
|
||||
- env:
|
||||
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
ORG: stoatchat
|
||||
PACKAGE: ${{ matrix.package }}
|
||||
TAG: pr-${{ github.event.pull_request.number }}
|
||||
run: |
|
||||
set -euo pipefail
|
||||
gh api --paginate \
|
||||
"/orgs/${ORG}/packages/container/${PACKAGE}/versions" \
|
||||
--jq ".[] | select(.metadata.container.tags | index(\"${TAG}\")) | .id" \
|
||||
| while read -r id; do
|
||||
gh api -X DELETE "/orgs/${ORG}/packages/container/${PACKAGE}/versions/${id}"
|
||||
done
|
||||
Reference in New Issue
Block a user