Skip to content

Commit 43f43c2

Browse files
authored
Merge pull request #697 from rajbos/rajbos/keep-test-env-after-pr
chore: make test environment cleanup manual-only
2 parents 55985a8 + 722c9db commit 43f43c2

1 file changed

Lines changed: 15 additions & 10 deletions

File tree

.github/workflows/sharing-server-cleanup.yml

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
1-
name: Cleanup Sharing Server (branch deleted)
1+
name: Cleanup Sharing Server (manual)
22

3-
# Destroys the test Container Apps environment when a branch is deleted.
3+
# Destroys the test Container Apps environment on demand.
4+
# Run this manually via workflow_dispatch to clean up a test environment.
45
# Production (main) is intentionally excluded.
56
on:
6-
delete:
7+
workflow_dispatch:
8+
inputs:
9+
branch:
10+
description: 'Branch name whose test environment should be destroyed'
11+
required: true
12+
type: string
713

814
permissions:
915
contents: read
@@ -12,8 +18,8 @@ jobs:
1218
cleanup:
1319
name: Destroy test environment
1420
runs-on: ubuntu-latest
15-
# Only run for branch deletions; skip tag deletions and the main branch.
16-
if: github.event.ref_type == 'branch' && github.event.ref != 'main'
21+
# Prevent accidental destruction of production.
22+
if: github.event.inputs.branch != 'main'
1723
environment: testing
1824
permissions:
1925
contents: read
@@ -33,11 +39,10 @@ jobs:
3339

3440
# Reproduce the exact same slug+hash logic used by the deploy workflow
3541
# so the state key resolves to the same tfstate file.
36-
- name: Compute state key for deleted branch
42+
- name: Compute state key for branch
3743
id: env
3844
run: |
39-
# NOTE: on the `delete` event, github.event.ref is the deleted branch name.
40-
BRANCH="${{ github.event.ref }}"
45+
BRANCH="${{ github.event.inputs.branch }}"
4146
SLUG=$(echo "$BRANCH" | tr '[:upper:]' '[:lower:]' | sed 's/[^a-z0-9]/-/g' | sed 's/-\+/-/g' | sed 's/^-//;s/-$//')
4247
SLUG_TRUNC=$(echo "$SLUG" | cut -c1-13 | sed 's/-$//')
4348
HASH=$(echo -n "$BRANCH" | sha256sum | cut -c1-6)
@@ -77,6 +82,6 @@ jobs:
7782
terraform destroy -auto-approve
7883
echo "✅ Environment destroyed: ${{ steps.env.outputs.app_name }}" >> "$GITHUB_STEP_SUMMARY"
7984
else
80-
echo "No resources found in state for branch '${{ github.event.ref }}' — nothing to destroy."
81-
echo "ℹ️ No resources found for branch \`${{ github.event.ref }}\` — nothing to destroy." >> "$GITHUB_STEP_SUMMARY"
85+
echo "No resources found in state for branch '${{ github.event.inputs.branch }}' — nothing to destroy."
86+
echo "ℹ️ No resources found for branch \`${{ github.event.inputs.branch }}\` — nothing to destroy." >> "$GITHUB_STEP_SUMMARY"
8287
fi

0 commit comments

Comments
 (0)