From 4c7d3638fd908499ca32cc3b24fb24c8c3b3fa51 Mon Sep 17 00:00:00 2001 From: "Sure Admin (bot)" Date: Sun, 17 May 2026 20:24:45 +0200 Subject: [PATCH] fix(preview): delete stale container app before redeploy (#1820) --- .github/workflows/preview-deploy.yml | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/.github/workflows/preview-deploy.yml b/.github/workflows/preview-deploy.yml index 269adf510..e23b9694c 100644 --- a/.github/workflows/preview-deploy.yml +++ b/.github/workflows/preview-deploy.yml @@ -82,6 +82,28 @@ jobs: sed -i "s/\${PR_NUMBER}/${{ github.event.pull_request.number }}/g" src/index.ts cat wrangler.toml + - name: Delete existing preview container app before redeploy + env: + CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }} + CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} + working-directory: workers/preview + run: | + CONTAINER_NAME="sure-preview-${{ github.event.pull_request.number }}-railscontainer" + echo "Looking for stale preview container app: $CONTAINER_NAME" + + CONTAINER_ID=$(npx wrangler containers list --json | jq -r --arg NAME "$CONTAINER_NAME" ' + map(select((.name // .application_name // .app_name // "") == $NAME)) + | first + | (.id // .container_id // .application_id // empty) + ') + + if [ -n "$CONTAINER_ID" ]; then + echo "Deleting stale preview container app $CONTAINER_NAME ($CONTAINER_ID)" + npx wrangler containers delete "$CONTAINER_ID" + else + echo "No stale preview container app found; continuing" + fi + - name: Delete existing preview Worker before redeploy env: CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}