@@ -105,7 +105,14 @@ jobs:
105105 - name : Save Docker image as artifact
106106 run : |
107107 echo "Saving Docker image as tar artifact..."
108- IMAGE_TAG="${{ steps.meta.outputs.tags }}" | head -n1
108+ IMAGE_TAG=$(echo "${{ steps.meta.outputs.tags }}" | head -n1)
109+ echo "Using image tag: $IMAGE_TAG"
110+
111+ # Pull the image locally if it's not available
112+ echo "Pulling image to ensure it's available locally..."
113+ docker pull "$IMAGE_TAG"
114+
115+ # Save the image as tar
109116 docker save "$IMAGE_TAG" -o wrongsecrets-preview.tar
110117 echo "Docker image saved to wrongsecrets-preview.tar"
111118 ls -lh wrongsecrets-preview.tar
@@ -153,7 +160,7 @@ jobs:
153160
154161 **🐳 Docker Image:** \`${imageTag}\`
155162
156- **� Download & Test Locally:**
163+ **📦 Download & Test Locally:**
157164 1. [📁 Download Docker Image Artifact](https://github.com/${{ github.repository }}/actions/runs/${runId}) (look for \`wrongsecrets-preview-pr-${prNumber}\`)
158165 2. Load and run the image:
159166 \`\`\`bash
@@ -377,33 +384,33 @@ jobs:
377384 body: comment
378385 });
379386
380- # cleanup-preview:
381- # runs-on: ubuntu-latest
382- # if: github.event.action == 'closed'
383- # steps:
384- # - name: Log in to GitHub Container Registry
385- # uses: docker/login-action@v3
386- # with:
387- # registry: ghcr.io
388- # username: ${{ github.actor }}
389- # password: ${{ secrets.GITHUB_TOKEN }}
390-
391- # - name: Delete PR container images
392- # run: |
393- # # Delete container images for this PR
394- # PR_NUMBER=${{ github.event.number }}
395- # REPO_LOWER=$(echo "${{ github.repository }}" | tr '[:upper:]' '[:lower:]')
396-
397- # # Get all tags for this PR and delete them
398- # for tag in $(curl -s -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
399- # "https://api.github.com/orgs/${{ github.repository_owner }}/packages/container/${REPO_LOWER}%2Fwrongsecrets-pr/versions" | \
400- # jq -r --arg pr "$PR_NUMBER" '.[] | select(.metadata.container.tags[]? | contains($pr)) | .id'); do
401-
402- # echo "Deleting container version: $tag"
403- # curl -X DELETE \
404- # -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
405- # "https://api.github.com/orgs/${{ github.repository_owner }}/packages/container/${REPO_LOWER}%2Fwrongsecrets-pr/versions/$tag"
406- # done
387+ cleanup-preview :
388+ runs-on : ubuntu-latest
389+ if : github.event.action == 'closed'
390+ steps :
391+ - name : Log in to GitHub Container Registry
392+ uses : docker/login-action@v3
393+ with :
394+ registry : ghcr.io
395+ username : ${{ github.actor }}
396+ password : ${{ secrets.GITHUB_TOKEN }}
397+
398+ - name : Delete PR container images
399+ run : |
400+ # Delete container images for this PR
401+ PR_NUMBER=${{ github.event.number }}
402+ REPO_LOWER=$(echo "${{ github.repository }}" | tr '[:upper:]' '[:lower:]')
403+
404+ # Get all tags for this PR and delete them
405+ for tag in $(curl -s -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
406+ "https://api.github.com/orgs/${{ github.repository_owner }}/packages/container/${REPO_LOWER}%2Fwrongsecrets-pr/versions" | \
407+ jq -r --arg pr "$PR_NUMBER" '.[] | select(.metadata.container.tags[]? | contains($pr)) | .id'); do
408+
409+ echo "Deleting container version: $tag"
410+ curl -X DELETE \
411+ -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
412+ "https://api.github.com/orgs/${{ github.repository_owner }}/packages/container/${REPO_LOWER}%2Fwrongsecrets-pr/versions/$tag"
413+ done
407414
408415 # Comment out Render cleanup for now
409416 # - name: Cleanup Render service
@@ -420,24 +427,24 @@ jobs:
420427 # -H "Authorization: Bearer $RENDER_API_KEY"
421428 # fi
422429
423- # - name: Comment PR closure
424- # uses: actions/github-script@v7
425- # with:
426- # script: |
427- # const comment = `🧹 **Preview Cleanup Complete**
430+ - name : Comment PR closure
431+ uses : actions/github-script@v7
432+ with :
433+ script : |
434+ const comment = `🧹 **Preview Cleanup Complete**
428435
429- # PR preview resources have been cleaned up:
430- # - ✅ Container images deleted from GitHub Container Registry
431- # - ✅ Artifacts will expire automatically in 30 days
436+ PR preview resources have been cleaned up:
437+ - ✅ Container images deleted from GitHub Container Registry
438+ - ✅ Artifacts will expire automatically in 30 days
432439
433- # Thanks for contributing to WrongSecrets! 🎉
440+ Thanks for contributing to WrongSecrets! 🎉
434441
435- # ---
436- # <sub>Cleanup completed by GitHub Actions</sub>`;
442+ ---
443+ <sub>Cleanup completed by GitHub Actions</sub>`;
437444
438- # github.rest.issues.createComment({
439- # issue_number: context.issue.number,
440- # owner: context.repo.owner,
441- # repo: context.repo.repo,
442- # body: comment
443- # });
445+ github.rest.issues.createComment({
446+ issue_number: context.issue.number,
447+ owner: context.repo.owner,
448+ repo: context.repo.repo,
449+ body: comment
450+ });
0 commit comments