Skip to content

Manual Cleanup on Closed Pull Request #10

Manual Cleanup on Closed Pull Request

Manual Cleanup on Closed Pull Request #10

Workflow file for this run

name: Manual Cleanup on Closed Pull Request
on:
workflow_dispatch:
inputs:
pull_request_number:
description: "Pull Request Number"
type: string
pull_request_merged:
type: boolean
description: "Pull Request Merged or not"
jobs:
# this job will only run if the PR has been merged
merge_job:
name: "Merged"
if: ${{ inputs.pull_request_merged == true }}
runs-on: ubuntu-latest
steps:
- uses: actions/delete-package-versions@v5
with:
package-name: 'traefik-acme'
package-type: 'container'
min-versions-to-keep: 0
delete-only-untagged-versions: 'true'
- name: Get Version ID from the Versions List
id: version-id
run: |
curl \
-X GET \
-H "X-GitHub-Api-Version: 2022-11-28" \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${{secrets.GITHUB_TOKEN}}" \
"${{github.api_url}}/users/${{github.repository_owner}}/packages/container/${{github.event.repository.name}}/versions" >> ${HOME}/versionIds.json
echo "VERSION_ID=$(jq -r ".[] | select(.metadata.container.tags | index(\"pr-${{ inputs.pull_request_number }}\")).id" ${HOME}/versionIds.json)" | tee -a "${GITHUB_OUTPUT}"
- name: Print Version ID
run: echo "The selected Version ID is ${{ steps.version-id.outputs.VERSION_ID }}"
- uses: actions/delete-package-versions@v5
if: ${{ steps.version-id.outputs.VERSION_ID != '' }}
with:
package-name: 'traefik-acme'
package-type: 'container'
package-version-ids: '${{ steps.version-id.outputs.VERSION_ID }}'
# this job will only run if the PR has been closed without being merged
close_job:
name: "Closed"
if: ${{ inputs.pull_request_merged == false }}
runs-on: ubuntu-latest
steps:
- uses: actions/delete-package-versions@v5
with:
package-name: 'traefik-acme'
package-type: 'container'
min-versions-to-keep: 0
delete-only-untagged-versions: 'true'
- name: Get Version ID from the Versions List
id: version-id
run: |
curl \
-X GET \
-H "X-GitHub-Api-Version: 2022-11-28" \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${{secrets.GITHUB_TOKEN}}" \
"${{github.api_url}}/users/${{github.repository_owner}}/packages/container/${{github.event.repository.name}}/versions" >> ${HOME}/versionIds.json
echo "VERSION_ID=$(jq -r ".[] | select(.metadata.container.tags | index(\"pr-${{ inputs.pull_request_number }}\")).id" ${HOME}/versionIds.json)" | tee -a "${GITHUB_OUTPUT}"
- name: Print Version ID
run: echo "The selected Version ID is ${{ steps.version-id.outputs.VERSION_ID }}"
- uses: actions/delete-package-versions@v5
if: ${{ steps.version-id.outputs.VERSION_ID != '' }}
with:
package-name: 'traefik-acme'
package-type: 'container'
package-version-ids: '${{ steps.version-id.outputs.VERSION_ID }}'