Skip to content

Commit 7d75738

Browse files
committed
fix-for-delete
1 parent 92ad3a7 commit 7d75738

File tree

3 files changed

+190
-41
lines changed

3 files changed

+190
-41
lines changed

.github/workflows/delete-review-app.yml

Lines changed: 22 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -11,58 +11,51 @@ permissions:
1111
issues: write
1212

1313
env:
14-
CPLN_ORG: ${{ secrets.CPLN_ORG_STAGING }}
15-
CPLN_TOKEN: ${{ secrets.CPLN_TOKEN_STAGING }}
14+
CPLN_ORG: ${{ secrets.CPLN_ORG }}
15+
CPLN_TOKEN: ${{ secrets.CPLN_TOKEN }}
16+
APP_NAME: qa-react-webpack-rails-tutorial-pr-${{ github.event.issue.number }}
17+
PR_NUMBER: ${{ github.event.issue.number }}
1618

1719
jobs:
18-
Process-Delete-Command:
19-
if: |
20-
github.event_name == 'issue_comment' &&
21-
github.event.issue.pull_request &&
22-
github.event.comment.body == '/delete-review-app'
20+
debug-trigger:
21+
if: always()
2322
runs-on: ubuntu-latest
24-
2523
steps:
2624
- name: Debug Trigger Conditions
2725
env:
2826
EVENT_NAME: ${{ github.event_name }}
29-
IS_PR: ${{ github.event.issue.pull_request != '' }}
27+
IS_PR: ${{ toJSON(github.event.issue.pull_request) }}
3028
COMMENT: ${{ github.event.comment.body }}
31-
PR_NUMBER: ${{ github.event.issue.number }}
3229
run: |
3330
echo "Debug information for delete-review-app command:"
3431
echo "Event name: $EVENT_NAME"
35-
echo "Is PR: $IS_PR"
32+
echo "Is PR (raw): $IS_PR"
3633
echo "Comment body: $COMMENT"
37-
echo "PR number: $PR_NUMBER"
3834
echo "Raw event payload:"
3935
echo '${{ toJSON(github.event) }}'
4036
41-
- name: Get PR number
42-
id: pr
43-
uses: actions/github-script@v7
44-
with:
45-
script: |
46-
const prNumber = context.payload.issue.number;
47-
core.setOutput('pr_number', prNumber);
48-
core.exportVariable('PR_NUMBER', prNumber);
49-
50-
- name: Set App Name
51-
run: echo "APP_NAME=qa-react-webpack-rails-tutorial-pr-${{ env.PR_NUMBER }}" >> $GITHUB_ENV
37+
Process-Delete-Command:
38+
needs: debug-trigger
39+
if: |
40+
github.event_name == 'issue_comment' &&
41+
github.event.issue.pull_request &&
42+
github.event.comment.body == '/delete-review-app'
43+
runs-on: ubuntu-latest
5244

45+
steps:
5346
- uses: actions/checkout@v4
5447

5548
- name: Validate Required Secrets
5649
run: |
5750
missing_secrets=()
58-
for secret in "CPLN_TOKEN_STAGING" "CPLN_ORG_STAGING"; do
51+
for secret in "CPLN_TOKEN" "CPLN_ORG"; do
5952
if [ -z "${!secret}" ]; then
6053
missing_secrets+=("$secret")
6154
fi
6255
done
6356
6457
if [ ${#missing_secrets[@]} -ne 0 ]; then
65-
echo " Required secrets are not set: ${missing_secrets[*]}"
58+
echo " Required secrets are not set: ${missing_secrets[*]}"
6659
exit 1
6760
fi
6861
@@ -78,7 +71,7 @@ jobs:
7871
issue_number: process.env.PR_NUMBER,
7972
owner: context.repo.owner,
8073
repo: context.repo.repo,
81-
body: '🗑️ Starting app deletion...'
74+
body: ' Starting app deletion...'
8275
});
8376
return { commentId: comment.data.id };
8477
@@ -101,11 +94,11 @@ jobs:
10194
const cpConsoleUrl = `https://console.cpln.io/org/${process.env.CPLN_ORG}/workloads/${process.env.APP_NAME}`;
10295
10396
const message = success
104-
? ' Review app for PR #' + prNumber + ' was successfully deleted'
97+
? ' Review app for PR #' + prNumber + ' was successfully deleted'
10598
: [
106-
' Review app for PR #' + prNumber + ' failed to be deleted',
99+
' Review app for PR #' + prNumber + ' failed to be deleted',
107100
'',
108-
'[View in Control Plane Console](' + cpConsoleUrl + ')'
101+
'[Control Plane Console for Review App with PR #' + prNumber + '](' + cpConsoleUrl + ')'
109102
].join('\n');
110103
111104
await github.rest.issues.updateComment({

.github/workflows/deploy-to-control-plane.yml

Lines changed: 154 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ concurrency:
1515

1616
env:
1717
APP_NAME: qa-react-webpack-rails-tutorial-pr-${{ github.event.pull_request.number || github.event.issue.number }}
18-
CPLN_ORG: ${{ secrets.CPLN_ORG_STAGING }}
19-
CPLN_TOKEN: ${{ secrets.CPLN_TOKEN_STAGING }}
18+
CPLN_ORG: ${{ secrets.CPLN_ORG }}
19+
CPLN_TOKEN: ${{ secrets.CPLN_TOKEN }}
2020
PR_NUMBER: ${{ github.event.pull_request.number || github.event.issue.number }}
2121

2222
jobs:
@@ -53,7 +53,7 @@ jobs:
5353
- name: Validate Required Secrets
5454
run: |
5555
missing_secrets=()
56-
for secret in "CPLN_TOKEN_STAGING" "CPLN_ORG_STAGING"; do
56+
for secret in "CPLN_TOKEN" "CPLN_ORG"; do
5757
if [ -z "${!secret}" ]; then
5858
missing_secrets+=("$secret")
5959
fi
@@ -249,4 +249,155 @@ jobs:
249249
repo: context.repo.repo,
250250
comment_id: process.env.COMMENT_ID,
251251
body: isSuccess ? successMessage : failureMessage
252+
});
253+
254+
debug-help:
255+
if: always()
256+
runs-on: ubuntu-latest
257+
steps:
258+
- name: Debug Trigger Conditions
259+
env:
260+
EVENT_NAME: ${{ github.event_name }}
261+
IS_PR: ${{ toJSON(github.event.issue.pull_request) }}
262+
COMMENT: ${{ github.event.comment.body }}
263+
run: |
264+
echo "Debug information for help command:"
265+
echo "Event name: $EVENT_NAME"
266+
echo "Is PR (raw): $IS_PR"
267+
echo "Comment body: $COMMENT"
268+
echo "Raw event payload:"
269+
echo '${{ toJSON(github.event) }}'
270+
271+
show-help:
272+
needs: debug-help
273+
if: |
274+
github.event_name == 'issue_comment' &&
275+
github.event.issue.pull_request &&
276+
github.event.comment.body == '/help'
277+
runs-on: ubuntu-latest
278+
279+
steps:
280+
- name: Show Available Commands
281+
uses: actions/github-script@v7
282+
with:
283+
script: |
284+
const helpMessage = [
285+
'## 📚 Available Commands',
286+
'',
287+
'### `/deploy`',
288+
'Deploys your PR branch to a review environment on Control Plane.',
289+
'- Creates a new review app if one doesn\'t exist',
290+
'- Updates the existing review app if it already exists',
291+
'- Provides a unique URL to preview your changes',
292+
'- Shows build and deployment progress in real-time',
293+
'',
294+
'### `/delete-review-app`',
295+
'Deletes the review app associated with this PR.',
296+
'- Removes all resources from Control Plane',
297+
'- Helpful for cleaning up when you\'re done testing',
298+
'- Can be re-deployed later using `/deploy`',
299+
'',
300+
'### `/help`',
301+
'Shows this help message explaining available commands.',
302+
'',
303+
'---',
304+
'_Note: These commands only work in pull request comments._'
305+
].join('\n');
306+
307+
await github.rest.issues.createComment({
308+
owner: context.repo.owner,
309+
repo: context.repo.repo,
310+
issue_number: context.payload.issue.number,
311+
body: helpMessage
312+
});
313+
314+
debug-delete:
315+
if: always()
316+
runs-on: ubuntu-latest
317+
steps:
318+
- name: Debug Trigger Conditions
319+
env:
320+
EVENT_NAME: ${{ github.event_name }}
321+
IS_PR: ${{ toJSON(github.event.issue.pull_request) }}
322+
COMMENT: ${{ github.event.comment.body }}
323+
run: |
324+
echo "Debug information for delete-review-app command:"
325+
echo "Event name: $EVENT_NAME"
326+
echo "Is PR (raw): $IS_PR"
327+
echo "Comment body: $COMMENT"
328+
echo "Raw event payload:"
329+
echo '${{ toJSON(github.event) }}'
330+
331+
Process-Delete-Command:
332+
needs: debug-delete
333+
if: |
334+
github.event_name == 'issue_comment' &&
335+
github.event.issue.pull_request &&
336+
github.event.comment.body == '/delete-review-app'
337+
runs-on: ubuntu-latest
338+
339+
steps:
340+
- uses: actions/checkout@v4
341+
342+
- name: Validate Required Secrets
343+
run: |
344+
missing_secrets=()
345+
for secret in "CPLN_TOKEN" "CPLN_ORG"; do
346+
if [ -z "${!secret}" ]; then
347+
missing_secrets+=("$secret")
348+
fi
349+
done
350+
351+
if [ ${#missing_secrets[@]} -ne 0 ]; then
352+
echo "❌ Required secrets are not set: ${missing_secrets[*]}"
353+
exit 1
354+
fi
355+
356+
- name: Setup Environment
357+
uses: ./.github/actions/setup-environment
358+
359+
- name: Create Initial Delete Comment
360+
id: init-delete
361+
uses: actions/github-script@v7
362+
with:
363+
script: |
364+
const comment = await github.rest.issues.createComment({
365+
issue_number: process.env.PR_NUMBER,
366+
owner: context.repo.owner,
367+
repo: context.repo.repo,
368+
body: '🗑️ Starting app deletion...'
369+
});
370+
return { commentId: comment.data.id };
371+
372+
- name: Delete Review App
373+
uses: ./.github/actions/delete-control-plane-app
374+
with:
375+
app_name: ${{ env.APP_NAME }}
376+
org: ${{ env.CPLN_ORG }}
377+
github_token: ${{ secrets.GITHUB_TOKEN }}
378+
env:
379+
CPLN_TOKEN: ${{ secrets.CPLN_TOKEN }}
380+
381+
- name: Update Delete Status
382+
if: always()
383+
uses: actions/github-script@v7
384+
with:
385+
script: |
386+
const success = '${{ job.status }}' === 'success';
387+
const prNumber = process.env.PR_NUMBER;
388+
const cpConsoleUrl = `https://console.cpln.io/org/${process.env.CPLN_ORG}/workloads/${process.env.APP_NAME}`;
389+
390+
const message = success
391+
? '✅ Review app for PR #' + prNumber + ' was successfully deleted'
392+
: [
393+
'❌ Review app for PR #' + prNumber + ' failed to be deleted',
394+
'',
395+
'🎮 [Control Plane Console for Review App with PR #' + prNumber + '](' + cpConsoleUrl + ')'
396+
].join('\n');
397+
398+
await github.rest.issues.updateComment({
399+
owner: context.repo.owner,
400+
repo: context.repo.repo,
401+
comment_id: ${{ fromJSON(steps.init-delete.outputs.result).commentId }},
402+
body: message
252403
});

.github/workflows/help-command.yml

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,33 +9,38 @@ permissions:
99
pull-requests: write
1010

1111
jobs:
12-
show-help:
13-
if: |
14-
github.event_name == 'issue_comment' &&
15-
github.event.issue.pull_request &&
16-
github.event.comment.body == '/help'
12+
debug-trigger:
13+
if: always()
1714
runs-on: ubuntu-latest
18-
1915
steps:
2016
- name: Debug Trigger Conditions
2117
env:
2218
EVENT_NAME: ${{ github.event_name }}
23-
IS_PR: ${{ github.event.issue.pull_request != '' }}
19+
IS_PR: ${{ toJSON(github.event.issue.pull_request) }}
2420
COMMENT: ${{ github.event.comment.body }}
2521
run: |
2622
echo "Debug information for help command:"
2723
echo "Event name: $EVENT_NAME"
28-
echo "Is PR: $IS_PR"
24+
echo "Is PR (raw): $IS_PR"
2925
echo "Comment body: $COMMENT"
3026
echo "Raw event payload:"
3127
echo '${{ toJSON(github.event) }}'
3228
29+
show-help:
30+
needs: debug-trigger
31+
if: |
32+
github.event_name == 'issue_comment' &&
33+
github.event.issue.pull_request &&
34+
github.event.comment.body == '/help'
35+
runs-on: ubuntu-latest
36+
37+
steps:
3338
- name: Show Available Commands
3439
uses: actions/github-script@v7
3540
with:
3641
script: |
3742
const helpMessage = [
38-
'## 📚 Available Commands',
43+
'## Available Commands',
3944
'',
4045
'### `/deploy`',
4146
'Deploys your PR branch to a review environment on Control Plane.',

0 commit comments

Comments
 (0)