|
1 | 1 | name: Deploy to Control Plane |
2 | 2 |
|
3 | | -run-name: "${{ github.event_name == 'pull_request' || (github.event_name == 'issue_comment' && github.event.issue.pull_request) ? 'Deploying Review App' : format('Deploying {0} to Staging App', github.ref_name) }}" |
| 3 | +run-name: ${{ (github.event_name == 'pull_request' || (github.event_name == 'issue_comment' && github.event.issue.pull_request)) && 'Deploying Review App' || format('Deploying {0} to Staging App', github.ref_name) }} |
4 | 4 |
|
5 | 5 | on: |
6 | 6 | pull_request: |
|
20 | 20 | PR_NUMBER: ${{ github.event.pull_request.number || github.event.issue.number }} |
21 | 21 |
|
22 | 22 | jobs: |
23 | | - deploy: |
| 23 | + process-command: |
24 | 24 | if: | |
25 | 25 | github.event_name == 'pull_request' || |
26 | 26 | (github.event_name == 'issue_comment' && |
27 | | - github.event.comment.body == '/deploy-review-app' && |
| 27 | + (github.event.comment.body == '/deploy-review-app' || |
| 28 | + github.event.comment.body == '/delete-app') && |
28 | 29 | github.event.issue.pull_request) |
29 | 30 | runs-on: ubuntu-latest |
30 | 31 | permissions: |
|
34 | 35 | issues: write |
35 | 36 |
|
36 | 37 | steps: |
| 38 | + - name: Determine Action |
| 39 | + id: determine_action |
| 40 | + run: | |
| 41 | + if [[ "${{ github.event.comment.body }}" == "/delete-app" ]]; then |
| 42 | + echo "action=delete" >> $GITHUB_OUTPUT |
| 43 | + else |
| 44 | + echo "action=deploy" >> $GITHUB_OUTPUT |
| 45 | + fi |
| 46 | +
|
| 47 | + - uses: actions/checkout@v4 |
| 48 | + with: |
| 49 | + fetch-depth: 0 |
| 50 | + ref: ${{ steps.getRef.outputs.PR_REF || github.ref }} |
| 51 | + |
| 52 | + - name: Setup Environment |
| 53 | + uses: ./.github/actions/setup-environment |
| 54 | + |
| 55 | + # Delete App Steps |
| 56 | + - name: Create Initial Delete Comment |
| 57 | + if: steps.determine_action.outputs.action == 'delete' |
| 58 | + uses: actions/github-script@v7 |
| 59 | + id: init-delete |
| 60 | + with: |
| 61 | + script: | |
| 62 | + const comment = await github.rest.issues.createComment({ |
| 63 | + issue_number: process.env.PR_NUMBER, |
| 64 | + owner: context.repo.owner, |
| 65 | + repo: context.repo.repo, |
| 66 | + body: '🗑️ Starting app deletion...' |
| 67 | + }); |
| 68 | + return { commentId: comment.data.id }; |
| 69 | +
|
| 70 | + - name: Delete App |
| 71 | + if: steps.determine_action.outputs.action == 'delete' |
| 72 | + id: delete |
| 73 | + uses: ./.github/actions/delete-control-plane-app |
| 74 | + continue-on-error: true |
| 75 | + with: |
| 76 | + app_name: ${{ env.APP_NAME }} |
| 77 | + org: ${{ env.CPLN_ORG }} |
| 78 | + |
| 79 | + - name: Update Delete Status |
| 80 | + if: steps.determine_action.outputs.action == 'delete' |
| 81 | + uses: actions/github-script@v7 |
| 82 | + with: |
| 83 | + script: | |
| 84 | + const success = '${{ steps.delete.outcome }}' === 'success'; |
| 85 | + const message = success |
| 86 | + ? '✅ App deletion successful' |
| 87 | + : '❌ App deletion failed'; |
| 88 | + |
| 89 | + await github.rest.issues.updateComment({ |
| 90 | + owner: context.repo.owner, |
| 91 | + repo: context.repo.repo, |
| 92 | + comment_id: ${{ fromJSON(steps.init-delete.outputs.result).commentId }}, |
| 93 | + body: message |
| 94 | + }); |
| 95 | +
|
| 96 | + # Deploy Steps (existing steps) |
37 | 97 | - name: Get PR HEAD Ref |
38 | | - if: ${{ github.event_name == 'issue_comment' }} |
| 98 | + if: steps.determine_action.outputs.action == 'deploy' |
39 | 99 | id: getRef |
40 | 100 | run: | |
41 | 101 | echo "PR_REF=$(gh pr view $PR_NUMBER --repo ${{ github.repository }} --json headRefName | jq -r '.headRefName')" >> $GITHUB_OUTPUT |
|
47 | 107 | fetch-depth: 0 |
48 | 108 | ref: ${{ steps.getRef.outputs.PR_REF || github.ref }} |
49 | 109 |
|
50 | | - - name: Setup Environment |
51 | | - uses: ./.github/actions/setup-environment |
52 | | - |
53 | 110 | - name: Initialize Deployment |
54 | 111 | id: init-deployment |
55 | 112 | uses: actions/github-script@v7 |
|
82 | 139 | run_id: context.runId |
83 | 140 | }); |
84 | 141 | |
85 | | - const jobId = jobs.data.jobs.find(job => job.name === 'deploy')?.id; |
| 142 | + const jobId = jobs.data.jobs.find(job => job.name === 'process-command')?.id; |
86 | 143 | const jobUrl = getJobUrl(context.runId, jobId, prNumber); |
87 | 144 | |
88 | 145 | // Create initial comment |
|
0 commit comments