Skip to content

Function name changes #4

Function name changes

Function name changes #4

name: "Delete untagged images."
on:
schedule:
- cron: "15 16 * * *" # 16:15 UTC
workflow_dispatch:
push:
jobs:
delete-untagged-images:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
strategy:
fail-fast: false
matrix:
images:
- image: al2023
- image: alpine
- image: debian
steps:
- name: "Delete untagged images."
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const response = await github.rest.packages.getAllPackageVersionsForPackageOwnedByAuthenticatedUser({
package_type: "container",
package_name: "${{ env.PACKAGE_NAME }}",
per_page: ${{ env.PER_PAGE }}
});
for(version of response.data) {
if (version.metadata.container.tags.length == 0) {
console.log("Removing: " + version.id)
const deleteResponse = await github.rest.packages.deletePackageVersionForAuthenticatedUser({
package_type: "container",
package_name: ${{ env.PACKAGE_NAME }},
package_version_id: version.id
});
console.log("Status: " + deleteResponse.status)
}
}
env:
OWNER: ${{ github.repository_owner }}
PACKAGE_NAME: ${{ matrix.images.image }}
PER_PAGE: 100