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