Do package cleanup as part of build workflow

This commit is contained in:
BtbN 2023-03-18 14:58:57 +01:00
parent ffa7c41e0f
commit 1b3fd62fbf
2 changed files with 42 additions and 27 deletions

View file

@ -22,6 +22,7 @@ on:
env:
DOCKER_BUILDKIT: 1
HAVE_CLEANUP_PAT: ${{ secrets.CLEANUP_PAT != '' }}
jobs:
build_base:
@ -43,7 +44,10 @@ jobs:
password: ${{ github.token }}
- name: Image Name
id: imagename
run: echo "name=ghcr.io/${GITHUB_REPOSITORY,,}/base" >> $GITHUB_OUTPUT
run: |
IMG="${GITHUB_REPOSITORY,,}/base"
echo "name=ghcr.io/${IMG/ /-}" >> $GITHUB_OUTPUT
echo "rawname=${IMG/ /-}" >> $GITHUB_OUTPUT
- name: Stop Commands
run: T="$(echo -n ${{ github.token }} | sha256sum | head -c 64)" && echo -e "::add-mask::${T}\n::stop-commands::${T}"
- name: Build target base image
@ -55,6 +59,16 @@ jobs:
tags: ${{ steps.imagename.outputs.name }}:latest
cache-to: type=registry,mode=max,ref=${{ steps.imagename.outputs.name }}:cache
cache-from: type=registry,ref=${{ steps.imagename.outputs.name }}:cache
- name: Cleanup
if: ${{ env.HAVE_CLEANUP_PAT == 'true' }}
uses: BtbN/delete-untagged-ghcr-action@main
with:
token: ${{ secrets.CLEANUP_PAT }}
package_name: ${{ steps.imagename.outputs.rawname }}
repository_owner: ${{ github.repository_owner }}
repository: ${{ github.repository }}
owner_type: user
untagged_only: true
build_target_bases:
name: Build target base image
if: ${{ github.event.inputs.buildOnly != 'true' }}
@ -79,7 +93,10 @@ jobs:
password: ${{ github.token }}
- name: Image Name
id: imagename
run: echo "name=ghcr.io/${GITHUB_REPOSITORY,,}/base-${{ matrix.target }}" >> $GITHUB_OUTPUT
run: |
IMG="${GITHUB_REPOSITORY,,}/base-${{ matrix.target }}"
echo "name=ghcr.io/${IMG/ /-}" >> $GITHUB_OUTPUT
echo "rawname=${IMG/ /-}" >> $GITHUB_OUTPUT
- name: Stop Commands
run: T="$(echo -n ${{ github.token }} | sha256sum | head -c 64)" && echo -e "::add-mask::${T}\n::stop-commands::${T}"
- name: Build target base image
@ -91,6 +108,16 @@ jobs:
tags: ${{ steps.imagename.outputs.name }}:latest
cache-to: type=registry,mode=max,ref=${{ steps.imagename.outputs.name }}:cache
cache-from: type=registry,ref=${{ steps.imagename.outputs.name }}:cache
- name: Cleanup
if: ${{ env.HAVE_CLEANUP_PAT == 'true' }}
uses: BtbN/delete-untagged-ghcr-action@main
with:
token: ${{ secrets.CLEANUP_PAT }}
package_name: ${{ steps.imagename.outputs.rawname }}
repository_owner: ${{ github.repository_owner }}
repository: ${{ github.repository }}
owner_type: user
untagged_only: true
build_targets:
name: Build target-variant image
if: ${{ github.event.inputs.buildOnly != 'true' }}
@ -119,8 +146,9 @@ jobs:
- name: Image Name
id: imagename
run: |
IMG="ghcr.io/${GITHUB_REPOSITORY,,}/${{ matrix.target }}-${{ matrix.variant }}"
echo "name=${IMG/ /-}" >> $GITHUB_OUTPUT
IMG="${GITHUB_REPOSITORY,,}/${{ matrix.target }}-${{ matrix.variant }}"
echo "name=ghcr.io/${IMG/ /-}" >> $GITHUB_OUTPUT
echo "rawname=${IMG/ /-}" >> $GITHUB_OUTPUT
echo "gh_repo=${GITHUB_REPOSITORY,,}" >> $GITHUB_OUTPUT
- name: Stop Commands
run: T="$(echo -n ${{ github.token }} | sha256sum | head -c 64)" && echo -e "::add-mask::${T}\n::stop-commands::${T}"
@ -135,6 +163,16 @@ jobs:
cache-from: type=registry,ref=${{ steps.imagename.outputs.name }}:cache
build-args: |
GH_REPO=ghcr.io/${{ steps.imagename.outputs.gh_repo }}
- name: Cleanup
if: ${{ env.HAVE_CLEANUP_PAT == 'true' }}
uses: BtbN/delete-untagged-ghcr-action@main
with:
token: ${{ secrets.CLEANUP_PAT }}
package_name: ${{ steps.imagename.outputs.rawname }}
repository_owner: ${{ github.repository_owner }}
repository: ${{ github.repository }}
owner_type: user
untagged_only: true
build_ffmpeg:
name: Build ffmpeg
if: ${{ ( github.event.inputs.buildOnly == 'true' && !cancelled() ) || success() }}

View file

@ -1,23 +0,0 @@
name: Cleanup
on:
workflow_dispatch: ~
schedule:
- cron: '0 20 * * *'
jobs:
cleanup:
name: Cleanup
runs-on: ubuntu-latest
env:
HAVE_PAT: ${{ secrets.CLEANUP_PAT != '' }}
steps:
- name: Cleanup
if: ${{ env.HAVE_PAT == 'true' }}
uses: Chizkiyahu/delete-untagged-ghcr-action@v2
with:
token: ${{ secrets.CLEANUP_PAT }}
repository_owner: ${{ github.repository_owner }}
repository: ${{ github.repository }}
owner_type: user
untagged_only: true