Move Test over #70
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Delete GHCR image on PR close | |
on: | |
pull_request: | |
types: [closed] | |
jobs: | |
delete-ghcr: | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
FLINK_PROFILE: [flink-1.19, flink-1.20] | |
steps: | |
- name: Delete GHCR image via GitHub REST API | |
env: | |
GH_USERNAME: ${{ secrets.PAT_USERNAME }} | |
GH_PASSWORD: ${{ secrets.PAT_PASSWORD }} | |
ORG: DataSQRL | |
PACKAGE: flink-sql-runner | |
TAG: pr-${{ github.event.number }}-${{ matrix.FLINK_PROFILE }} | |
run: | | |
set -euxo pipefail | |
echo "🔐 Generating basic auth token..." | |
TOKEN_BASE64=$(echo -n "$GH_USERNAME:$GH_PASSWORD" | base64) | |
echo "🔍 Getting package versions for $ORG/$PACKAGE..." | |
VERSION_LIST=$(curl -s \ | |
-H "Authorization: Basic $TOKEN_BASE64" \ | |
-H "Accept: application/vnd.github+json" \ | |
"https://api.github.com/orgs/$ORG/packages/container/$PACKAGE/versions") | |
echo "📦 Searching for tag: $TAG..." | |
PACKAGE_VERSION_ID=$(echo "$VERSION_LIST" | jq -r --arg TAG "$TAG" ' | |
.[] | select(.metadata.container.tags[]? == $TAG) | .id' | head -n 1) | |
if [[ -z "$PACKAGE_VERSION_ID" || "$PACKAGE_VERSION_ID" == "null" ]]; then | |
echo "❌ Package version with tag $TAG not found." | |
exit 1 | |
fi | |
echo "🗑️ Deleting package version ID: $PACKAGE_VERSION_ID..." | |
DELETE_STATUS=$(curl -s -o /dev/null -w "%{http_code}" \ | |
-X DELETE \ | |
-H "Authorization: Basic $TOKEN_BASE64" \ | |
-H "Accept: application/vnd.github+json" \ | |
"https://api.github.com/orgs/$ORG/packages/container/$PACKAGE/versions/$PACKAGE_VERSION_ID") | |
if [[ "$DELETE_STATUS" -ge 200 && "$DELETE_STATUS" -lt 300 ]]; then | |
echo "✅ Successfully deleted GHCR tag $TAG (version ID $PACKAGE_VERSION_ID)" | |
else | |
echo "❌ Failed to delete package version. HTTP status: $DELETE_STATUS" | |
exit 1 | |
fi |