11name : Delete Review App
22
33on :
4+ pull_request :
5+ types : [closed]
46 issue_comment :
57 types : [created]
68
@@ -12,14 +14,18 @@ permissions:
1214
1315env :
1416 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 }}
1620
1721jobs :
1822 Process-Delete-Command :
1923 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')
2329 runs-on : ubuntu-latest
2430
2531 steps :
@@ -37,24 +43,97 @@ jobs:
3743
3844 - uses : actions/checkout@v4
3945
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+
4060 - name : Setup Environment
4161 uses : ./.github/actions/setup-environment
4262
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+
43103 - name : Create Initial Delete Comment
44- id : init -delete
104+ id : create -delete-comment
45105 uses : actions/github-script@v7
46106 with :
47107 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+
48116 const comment = await github.rest.issues.createComment({
49117 issue_number: process.env.PR_NUMBER,
50118 owner: context.repo.owner,
51119 repo: context.repo.repo,
52120 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')
53128 });
54129 return { commentId: comment.data.id };
55130
56131 - name : Delete Review App
57132 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 }}
58137 env :
59138 APP_NAME : ${{ env.APP_NAME }}
60139 CPLN_ORG : ${{ secrets.CPLN_ORG }}
@@ -65,21 +144,31 @@ jobs:
65144 uses : actions/github-script@v7
66145 with :
67146 script : |
147+ eval(process.env.GET_CONSOLE_LINK);
148+
68149 const success = '${{ job.status }}' === 'success';
69150 const prNumber = process.env.PR_NUMBER;
70151 const cpConsoleUrl = `https://console.cpln.io/org/${process.env.CPLN_ORG}/workloads/${process.env.APP_NAME}`;
71152
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');
79168
80169 await github.rest.issues.updateComment({
81170 owner: context.repo.owner,
82171 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
85174 });
0 commit comments