fix(THU-539): make Preview Destroy idempotent when the Pulumi stack is gone#983
Conversation
Preview teardown ran `pulumi destroy` unconditionally, so any PR whose stack was already torn down (manual destroy, a prior failed run, or a PR that never deployed) failed with "no stack named ... found" and surfaced a red x on close. Guard destroy behind a stack-existence check so a clean environment is treated as success. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
| run: | | ||
| curl -fsSL https://get.pulumi.com | sh | ||
| export PATH="$HOME/.pulumi/bin:$PATH" | ||
| if pulumi stack select "${{ inputs.stack_name }}" --non-interactive 2>/dev/null; then | ||
| echo "Stack ${{ inputs.stack_name }} exists — proceeding to destroy." | ||
| echo "exists=true" >> "$GITHUB_OUTPUT" | ||
| else | ||
| echo "Stack ${{ inputs.stack_name }} not found — nothing to destroy." | ||
| echo "exists=false" >> "$GITHUB_OUTPUT" | ||
| fi | ||
|
|
Semgrep Security ScanFound 1 issue(s).
Finding details
|
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 5edef0e. Configure here.
| echo "exists=true" >> "$GITHUB_OUTPUT" | ||
| else | ||
| echo "Stack ${{ inputs.stack_name }} not found — nothing to destroy." | ||
| echo "exists=false" >> "$GITHUB_OUTPUT" |
There was a problem hiding this comment.
Stack check masks real failures
High Severity
The stack existence step treats any non-zero pulumi stack select exit as “stack missing” because stderr is discarded and only the shell if exit status is used. Auth, network, or permission failures are misread as exists=false, so Destroy is skipped and the job succeeds even when the stack still exists and should be torn down.
Reviewed by Cursor Bugbot for commit 5edef0e. Configure here.
PR Metrics
Updated Fri, 12 Jun 2026 19:38:19 GMT · run #1882 |
|
Preview environment deployed 🚀
Stack: Auto-destroys on PR close/merge. Login via the bundled Keycloak realm — |


Problem
Preview Destroyfails itsdestroy / destroystep witherror: no stack named 'preview-pr-NNN' foundwhenever the Pulumi stack no longer exists at destroy time — a PR that never deployed, or whose stack was already torn down. The env is actually clean, but every PR close/merge throws a red ✗ in Actions (now constant per the urgency bump), drowning out real CI signal.Fix
The destroy job uses the
pulumi/actions@v7wrapper (command: destroy), which errors on a missing stack. Added a guard step before it that checks existence viapulumi stack select(exit code) and gates the destroy:Auth is inherited from the workflow-level
PULUMI_ACCESS_TOKENenv. When the stack is gone, the destroy is skipped and the job goes green.Notes
continue-on-error, so a real destroy failure still fails loudly.pulumi destroy, so the check is a separate gating step.Testing
YAML validated. Behavioral verification happens on the next PR close (stack-present → destroys as before; stack-absent → skips, green).
🤖 Generated with Claude Code
Note
Low Risk
CI workflow-only change; destroy still runs and fails loudly when the stack exists and teardown fails.
Overview
Makes Preview Destroy in
stack-deploy.ymlsucceed when the Pulumi stack is already gone, instead of failing withno stack named ... foundon every PR close (THU-539).A new Check whether the stack still exists step installs the Pulumi CLI, runs
pulumi stack selectfor the target stack, and setsexists=true|false. The Destroypulumi/actionsstep runs only whenexists == 'true', so missing stacks are skipped with a green job; actual destroy errors still fail the workflow.Reviewed by Cursor Bugbot for commit 5edef0e. Bugbot is set up for automated code reviews on this repo. Configure here.