@@ -15,8 +15,8 @@ concurrency:
1515
1616env :
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
2222jobs :
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 });
0 commit comments