Skip to content

Commit b181008

Browse files
authored
Merge pull request #367 from The-Strategy-Unit/fix_remove_pr_image
moves the removal of PR images into main pipeline
2 parents 883156f + c6a8119 commit b181008

File tree

2 files changed

+28
-35
lines changed

2 files changed

+28
-35
lines changed

.github/workflows/build_container.yaml

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,6 @@ jobs:
8787
``` bash
8888
docker pull ghcr.io/the-strategy-unit/nhp_model:pr-${{ github.event.number }}
8989
```
90-
91-
[Download Artifact](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }})
9290
edit-mode: replace
9391

9492
deploy-ghcr:
@@ -163,4 +161,31 @@ jobs:
163161
if: ${{ inputs.latest }}
164162
run: |
165163
docker tag ${{ secrets.REGISTRY_LOGIN_SERVER }}/nhp_model:${{ inputs.docker-tag }} ${{ secrets.REGISTRY_LOGIN_SERVER }}/nhp_model:latest
166-
docker push ${{ secrets.REGISTRY_LOGIN_SERVER }}/nhp_model:latest
164+
docker push ${{ secrets.REGISTRY_LOGIN_SERVER }}/nhp_model:latest
165+
166+
remove-pr-image:
167+
runs-on: ubuntu-latest
168+
needs: ["deploy-ghcr"]
169+
if: github.event_name == 'pull_request' && github.event.action == 'closed'
170+
permissions:
171+
packages: write
172+
contents: read
173+
steps:
174+
- name: "Remove pr image"
175+
env:
176+
TAG_TO_DELETE: "pr-${{ github.event.pull_request.number }}"
177+
run: |
178+
VERSION_ID=$(gh api /orgs/the-strategy-unit/packages/container/nhp_model/versions \
179+
-H "Accept: application/vnd.github+json" \
180+
--paginate | \
181+
jq -r '.[] | select(.metadata.container.tags[] == "$TAG_TO_DELETE") | .id')
182+
183+
if [ -n "$VERSION_ID" ]; then
184+
echo "Deleting version ID: $VERSION_ID"
185+
gh api \
186+
-X DELETE \
187+
/orgs/the-strategy-unit/packages/container/nhp_model/versions/${VERSION_ID} \
188+
-H "Accept: application/vnd.github+json"
189+
else
190+
echo "Tag '$TAG_TO_DELETE' not found — skipping delete"
191+
fi

.github/workflows/remove_pr_container_image.yaml

Lines changed: 0 additions & 32 deletions
This file was deleted.

0 commit comments

Comments
 (0)