Skip to content

Commit a542851

Browse files
adamanciniclaude
andcommitted
feat: separate PR cleanup workflow to only run on merge to main
Create dedicated cleanup workflow that only runs when PRs are merged to main, rather than on every PR update. This prevents interference with active development and debugging while ensuring proper resource cleanup. Changes: - Add wg-easy-pr-cleanup.yaml workflow triggered only on PR merge - Remove cleanup job from wg-easy-pr-validation.yaml - Add informational message about resource cleanup in validation workflow - Update CLAUDE.md documentation to explain new cleanup strategy - Maintain same cleanup logic using task cleanup-pr-resources Benefits: - Resources remain available during PR development for testing/debugging - No unnecessary cleanup API calls during PR updates - Clear separation of validation vs cleanup concerns - Manual cleanup option still available via task command 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
1 parent 84a253a commit a542851

File tree

3 files changed

+82
-18
lines changed

3 files changed

+82
-18
lines changed
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
---
2+
name: WG-Easy PR Cleanup - clean up resources after merge
3+
4+
on:
5+
pull_request:
6+
types: [closed]
7+
branches: [main]
8+
paths:
9+
- 'applications/wg-easy/**'
10+
- '.github/workflows/wg-easy-pr-validation.yaml'
11+
- '.github/workflows/wg-easy-pr-cleanup.yaml'
12+
13+
env:
14+
APP_DIR: applications/wg-easy
15+
REPLICATED_API_TOKEN: ${{ secrets.WG_EASY_REPLICATED_API_TOKEN }}
16+
REPLICATED_APP: ${{ secrets.WG_EASY_REPLICATED_APP }}
17+
18+
jobs:
19+
cleanup:
20+
runs-on: ubuntu-22.04
21+
# Only run cleanup when PR is actually merged to main
22+
if: github.event.pull_request.merged == true
23+
steps:
24+
- name: Checkout code
25+
uses: actions/checkout@v4
26+
27+
- name: Set branch and channel variables
28+
id: vars
29+
run: |
30+
# Use the head branch name for cleanup (the branch that was merged)
31+
BRANCH_NAME="${{ github.event.pull_request.head.ref }}"
32+
# Channel name is normalized to lowercase with hyphens for Replicated channels
33+
CHANNEL_NAME=$(echo "$BRANCH_NAME" | tr '[:upper:]' '[:lower:]' | tr '/' '-')
34+
echo "branch-name=$BRANCH_NAME" >> $GITHUB_OUTPUT
35+
echo "channel-name=$CHANNEL_NAME" >> $GITHUB_OUTPUT
36+
echo "Cleaning up resources for merged branch: $BRANCH_NAME (channel: $CHANNEL_NAME)"
37+
38+
- name: Setup tools
39+
uses: ./.github/actions/setup-tools
40+
with:
41+
app-dir: ${{ env.APP_DIR }}
42+
43+
- name: Cleanup PR resources
44+
run: |
45+
echo "Starting cleanup for merged PR branch: ${{ steps.vars.outputs.branch-name }}"
46+
task cleanup-pr-resources BRANCH_NAME="${{ steps.vars.outputs.channel-name }}" || echo "Cleanup completed with some warnings"
47+
echo "Cleanup completed for merged PR"
48+
working-directory: ${{ env.APP_DIR }}
49+
50+
- name: Report cleanup status
51+
if: always()
52+
run: |
53+
if [ $? -eq 0 ]; then
54+
echo "✅ Successfully cleaned up resources for merged PR: ${{ steps.vars.outputs.branch-name }}"
55+
else
56+
echo "⚠️ Cleanup completed with warnings for merged PR: ${{ steps.vars.outputs.branch-name }}"
57+
fi

.github/workflows/wg-easy-pr-validation.yaml

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -129,21 +129,14 @@ jobs:
129129
/tmp/*.log
130130
~/.replicated/
131131
132-
cleanup:
133-
runs-on: ubuntu-22.04
134-
needs: [setup, test-deployment]
135-
if: always()
136-
steps:
137-
- name: Checkout code
138-
uses: actions/checkout@v4
139-
140-
- name: Setup tools
141-
uses: ./.github/actions/setup-tools
142-
with:
143-
app-dir: ${{ env.APP_DIR }}
144-
145-
- name: Cleanup PR resources
132+
- name: PR validation info
146133
run: |
147-
task cleanup-pr-resources BRANCH_NAME="${{ needs.setup.outputs.channel-name }}" || echo "Cleanup completed with some warnings"
148-
working-directory: ${{ env.APP_DIR }}
134+
echo "🎉 PR validation completed successfully!"
135+
echo "📋 Resources created for this PR:"
136+
echo " - Customer: ${{ needs.setup.outputs.channel-name }}"
137+
echo " - Cluster: ${{ needs.setup.outputs.channel-name }}"
138+
echo " - Channel: ${{ needs.setup.outputs.channel-name }}"
139+
echo ""
140+
echo "ℹ️ Resources will be automatically cleaned up when this PR is merged to main."
141+
echo " For manual cleanup, run: task cleanup-pr-resources BRANCH_NAME=${{ needs.setup.outputs.channel-name }}"
149142

applications/wg-easy/CLAUDE.md

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,14 @@ The `wg-easy-pr-validation.yaml` workflow is structured for maximum efficiency:
440440
2. **Chart Packaging** - Builds once, shares artifacts between jobs
441441
3. **Release Creation** - Creates Replicated channel and release
442442
4. **Deployment Testing** - Tests full customer workflow
443-
5. **Automatic Cleanup** - Cleans up PR resources
443+
444+
### PR Cleanup Workflow
445+
The `wg-easy-pr-cleanup.yaml` workflow handles resource cleanup:
446+
447+
- **Triggers**: Only runs when PRs are merged to main (not on every PR update)
448+
- **Resources Cleaned**: Customers, clusters, and channels created during PR validation
449+
- **Smart Cleanup**: Uses the same `task cleanup-pr-resources` with proper branch name normalization
450+
- **Graceful Handling**: Continues cleanup even if some resources are already deleted
444451

445452
### Reusable Actions
446453
Located in `.github/actions/` for consistent tool setup and operations:
@@ -458,7 +465,14 @@ Located in `.github/actions/` for consistent tool setup and operations:
458465
- **Maintainability** - Logic centralized in Taskfile, not scattered in YAML
459466

460467
### Usage
461-
PR validation runs automatically on pull requests affecting `applications/wg-easy/`. Manual trigger available via `workflow_dispatch`.
468+
**PR Validation**: Runs automatically on pull requests affecting `applications/wg-easy/`. Manual trigger available via `workflow_dispatch`.
469+
470+
**PR Cleanup**: Runs automatically when PRs are merged to main. Resources remain available during PR development for testing and debugging.
471+
472+
**Manual Cleanup**: If needed, cleanup can be run manually:
473+
```bash
474+
task cleanup-pr-resources BRANCH_NAME=$(git branch --show-current)
475+
```
462476

463477
## Future Considerations
464478

0 commit comments

Comments
 (0)