Skip to content

Clean Preview

Clean Preview #30

Workflow file for this run

name: Clean Preview
on:
workflow_run:
workflows:
- Close Preview
types:
- completed
permissions:
deployments: write
id-token: write
jobs:
close:
name: Close
runs-on: ubuntu-latest
env:
PROJECT_ID: slowreader-418220
REGION: europe-west1
steps:
- name: Download PR number from prepare step
uses: actions/download-artifact@v4
with:
name: preview-id
repository: ${{ github.repository_owner }}/${{ github.event.repository.name }}
run-id: ${{ github.event.workflow_run.id }}
github-token: ${{ secrets.PREVIEW_ARTIFACT_PAT }}
- name: Extract PR number
run: |
PR_NUMBER=$(cat ./preview-id)
echo "PR_NUMBER=$PR_NUMBER" >> $GITHUB_ENV
- name: Disable deploy at GitHub
continue-on-error: true
uses: bobheadxi/deployments@v1
with:
step: delete-env
token: ${{ secrets.PREVIEW_DEPLOYMENT_PAT }}
env: preview-${{ env.PR_NUMBER }}
- name: Auth Google Cloud
uses: google-github-actions/auth@v2
with:
workload_identity_provider: projects/225773869708/locations/global/workloadIdentityPools/github/providers/slowreader
service_account: github-deploy@${{ env.PROJECT_ID }}.iam.gserviceaccount.com
- name: Install Google Cloud
uses: google-github-actions/setup-gcloud@v2
- name: Shut down Cloud Run
run: gcloud run services update-traffic staging --region=${{ env.REGION }} --project=${{ env.PROJECT_ID }} --remove-tags preview-${{ env.PR_NUMBER }} --async
- name: Delete image
run: |
tagged=$(gcloud artifacts docker images list $REGION-docker.pkg.dev/$PROJECT_ID/staging/staging --include-tags --format="get(version)" --filter="tags = 'preview-${{ env.PR_NUMBER }}'")
for digest in $tagged; do
image=$REGION-docker.pkg.dev/$PROJECT_ID/staging/staging@$digest
echo "Deleting unused image: $image"
gcloud artifacts docker images delete $image --delete-tags --quiet
done