1
1
name : Delete Review App
2
2
3
3
on :
4
+ pull_request :
5
+ types : [closed]
4
6
issue_comment :
5
7
types : [created]
6
8
@@ -12,14 +14,18 @@ permissions:
12
14
13
15
env :
14
16
CPLN_ORG : ${{ secrets.CPLN_ORG_STAGING }}
15
- CPLN_TOKEN : ${{ secrets.CPLN_TOKEN_STAGING }}
17
+ CPLN_TOKEN : ${{ secrets.CPLN_TOKEN }}
18
+ APP_NAME : qa-react-webpack-rails-tutorial-pr-${{ github.event.pull_request.number || github.event.issue.number }}
19
+ PR_NUMBER : ${{ github.event.pull_request.number || github.event.issue.number }}
16
20
17
21
jobs :
18
22
Process-Delete-Command :
19
23
if : |
20
- github.event_name == 'issue_comment' &&
21
- github.event.issue.pull_request &&
22
- github.event.comment.body == '/delete-review-app'
24
+ (github.event_name == 'issue_comment' &&
25
+ github.event.issue.pull_request &&
26
+ github.event.comment.body == '/delete-review-app') ||
27
+ (github.event_name == 'pull_request' &&
28
+ github.event.action == 'closed')
23
29
runs-on : ubuntu-latest
24
30
25
31
steps :
@@ -37,24 +43,97 @@ jobs:
37
43
38
44
- uses : actions/checkout@v4
39
45
46
+ - name : Validate Required Secrets
47
+ run : |
48
+ missing_secrets=()
49
+ for secret in "CPLN_TOKEN" "CPLN_ORG"; do
50
+ if [ -z "${!secret}" ]; then
51
+ missing_secrets+=("$secret")
52
+ fi
53
+ done
54
+
55
+ if [ ${#missing_secrets[@]} -ne 0 ]; then
56
+ echo "Required secrets are not set: ${missing_secrets[*]}"
57
+ exit 1
58
+ fi
59
+
40
60
- name : Setup Environment
41
61
uses : ./.github/actions/setup-environment
42
62
63
+ - name : Set shared functions
64
+ id : shared-functions
65
+ uses : actions/github-script@v7
66
+ with :
67
+ script : |
68
+ core.exportVariable('GET_CONSOLE_LINK', `
69
+ function getConsoleLink(prNumber) {
70
+ return '🎮 [Control Plane Console](' +
71
+ 'https://console.cpln.io/console/org/' + process.env.CPLN_ORG + '/gvc/' + process.env.APP_NAME + '/-info)';
72
+ }
73
+ `);
74
+
75
+ - name : Setup Workflow URL
76
+ id : setup-workflow-url
77
+ uses : actions/github-script@v7
78
+ with :
79
+ script : |
80
+ async function getWorkflowUrl(runId) {
81
+ // Get the current job ID
82
+ const jobs = await github.rest.actions.listJobsForWorkflowRun({
83
+ owner: context.repo.owner,
84
+ repo: context.repo.repo,
85
+ run_id: runId
86
+ });
87
+
88
+ const currentJob = jobs.data.jobs.find(job => job.status === 'in_progress');
89
+ const jobId = currentJob?.id;
90
+
91
+ if (!jobId) {
92
+ console.log('Warning: Could not find current job ID');
93
+ return `${process.env.GITHUB_SERVER_URL}/${context.repo.owner}/${context.repo.repo}/actions/runs/${runId}`;
94
+ }
95
+
96
+ return `${process.env.GITHUB_SERVER_URL}/${context.repo.owner}/${context.repo.repo}/actions/runs/${runId}/job/${jobId}`;
97
+ }
98
+
99
+ const workflowUrl = await getWorkflowUrl(context.runId);
100
+ core.exportVariable('WORKFLOW_URL', workflowUrl);
101
+ return { workflowUrl };
102
+
43
103
- name : Create Initial Delete Comment
44
- id : init -delete
104
+ id : create -delete-comment
45
105
uses : actions/github-script@v7
46
106
with :
47
107
script : |
108
+ eval(process.env.GET_CONSOLE_LINK);
109
+
110
+ let message = '🗑️ Starting app deletion';
111
+ if ('${{ github.event_name }}' === 'pull_request') {
112
+ const merged = '${{ github.event.pull_request.merged }}' === 'true';
113
+ message += merged ? ' (PR merged)' : ' (PR closed)';
114
+ }
115
+
48
116
const comment = await github.rest.issues.createComment({
49
117
issue_number: process.env.PR_NUMBER,
50
118
owner: context.repo.owner,
51
119
repo: context.repo.repo,
52
120
body: '🗑️ Starting app deletion...'
121
+ body: [
122
+ message,
123
+ '',
124
+ ' 🗑️ [View Delete Logs](' + process.env.WORKFLOW_URL + ')',
125
+ '',
126
+ getConsoleLink(process.env.PR_NUMBER)
127
+ ].join('\n')
53
128
});
54
129
return { commentId: comment.data.id };
55
130
56
131
- name : Delete Review App
57
132
uses : ./.github/actions/delete-control-plane-app
133
+ with :
134
+ app_name : ${{ env.APP_NAME }}
135
+ org : ${{ env.CPLN_ORG }}
136
+ github_token : ${{ secrets.GITHUB_TOKEN }}
58
137
env :
59
138
APP_NAME : ${{ env.APP_NAME }}
60
139
CPLN_ORG : ${{ secrets.CPLN_ORG }}
@@ -65,21 +144,31 @@ jobs:
65
144
uses : actions/github-script@v7
66
145
with :
67
146
script : |
147
+ eval(process.env.GET_CONSOLE_LINK);
148
+
68
149
const success = '${{ job.status }}' === 'success';
69
150
const prNumber = process.env.PR_NUMBER;
70
151
const cpConsoleUrl = `https://console.cpln.io/org/${process.env.CPLN_ORG}/workloads/${process.env.APP_NAME}`;
71
152
72
- const message = success
73
- ? '✅ Review app for PR #' + prNumber + ' was successfully deleted'
74
- : [
75
- '❌ Review app for PR #' + prNumber + ' failed to be deleted',
76
- '',
77
- '[View in Control Plane Console](' + cpConsoleUrl + ')'
78
- ].join('\n');
153
+ const successMessage = [
154
+ '✅ Review app for PR #' + prNumber + ' was successfully deleted',
155
+ '',
156
+ ' [View Completed Delete Logs](' + process.env.WORKFLOW_URL + ')',
157
+ '',
158
+ ' [Control Plane Organization](https://console.cpln.io/console/org/' + process.env.CPLN_ORG + '/-info)'
159
+ ].join('\n');
160
+
161
+ const failureMessage = [
162
+ '❌ Review app for PR #' + prNumber + ' failed to be deleted',
163
+ '',
164
+ ' [View Delete Logs with Errors](' + process.env.WORKFLOW_URL + ')',
165
+ '',
166
+ getConsoleLink(prNumber)
167
+ ].join('\n');
79
168
80
169
await github.rest.issues.updateComment({
81
170
owner: context.repo.owner,
82
171
repo: context.repo.repo,
83
- comment_id: ${{ fromJSON(steps.init -delete.outputs.result).commentId }},
84
- body: message
172
+ comment_id: ${{ fromJSON(steps.create -delete-comment .outputs.result).commentId }},
173
+ body: success ? successMessage : failureMessage
85
174
});
0 commit comments