Skip to content

ci: add deletion of untagged images (#6) #19

ci: add deletion of untagged images (#6)

ci: add deletion of untagged images (#6) #19

name: buildAndPushImage
on:
push:
branches:
- 'main'
- 'dev'
pull_request:
branches:
- 'main'
env:
IMAGE_URL: ghcr.io/ust-demaf
IMAGE_NAME: helm-plugin
IMAGE_TAG: ${{ github.ref == 'refs/heads/main' && 'latest' || 'testing' }}
jobs:
build-using-dockerfile-push-2-ghcr:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
with:
platforms: linux/amd64
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
with:
platforms: linux/amd64
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push
uses: docker/build-push-action@v6
with:
context: .
file: ./Dockerfile
platforms: linux/amd64
push: true
tags: ${{ env.IMAGE_URL }}/${{ env.IMAGE_NAME }}:${{ env.IMAGE_TAG }}
provenance: false
delete-untagged-images:
needs:
- build-using-dockerfile-push-2-ghcr
runs-on: ubuntu-latest
steps:
- uses: actions/delete-package-versions@v5
with:
owner: ${{ github.repository_owner }}
package-name: ${{ env.IMAGE_NAME }}
package-type: "container"
token: ${{ secrets.GITHUB_TOKEN }}
min-versions-to-keep: 3
delete-only-pre-release-versions: "true"
delete-only-untagged-versions: "true"