-
Notifications
You must be signed in to change notification settings - Fork 374
Expand file tree
/
Copy pathdeploy-to-control-plane-review.yml
More file actions
103 lines (91 loc) · 3.38 KB
/
deploy-to-control-plane-review.yml
File metadata and controls
103 lines (91 loc) · 3.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
name: Deploy Review App to Control Plane
on:
workflow_dispatch:
pull_request:
types: [opened, synchronize, reopened]
branches: [master]
issue_comment:
types: [created]
concurrency:
group: review-app-${{ github.event.pull_request.number || github.event.issue.number }}
cancel-in-progress: true
env:
CPLN_ORG: ${{secrets.CPLN_ORG_STAGING}}
CPLN_TOKEN: ${{secrets.CPLN_TOKEN_STAGING}}
PR_NUMBER: ${{ github.event.pull_request.number || github.event.issue.number }}
jobs:
deploy-to-control-plane-review:
if: |
github.event_name == 'workflow_dispatch' ||
github.event_name == 'pull_request' ||
(github.event_name == 'issue_comment' &&
github.event.comment.body == '/deploy-review-app' &&
github.event.issue.pull_request)
runs-on: ubuntu-latest
outputs:
app_url: ${{ steps.deploy.outputs.app_url }}
deployment_id: ${{ steps.create-deployment.outputs.deployment_id }}
steps:
- name: Create GitHub Deployment
id: create-deployment
uses: actions/github-script@v7
with:
script: |
const deployment = await github.rest.repos.createDeployment({
owner: context.repo.owner,
repo: context.repo.repo,
ref: context.sha,
environment: 'review-app',
auto_merge: false,
required_contexts: []
});
return deployment.data.id;
- name: Get PR HEAD Ref
if: ${{ github.event_name == 'issue_comment' }}
id: getRef
run: |
echo "PR_REF=$(gh pr view $PR_NUMBER --repo ${{ github.repository }} --json headRefName | jq -r '.headRefName')" >> $GITHUB_OUTPUT
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Checkout source code
uses: actions/checkout@v4
with:
fetch-depth: 0
ref: ${{ steps.getRef.outputs.PR_REF || github.ref }}
- name: Update deployment status (in_progress)
uses: actions/github-script@v7
with:
script: |
await github.rest.repos.createDeploymentStatus({
owner: context.repo.owner,
repo: context.repo.repo,
deployment_id: ${{ steps.create-deployment.outputs.deployment_id }},
state: 'in_progress',
description: 'Deployment is in progress'
});
# ... rest of your existing steps ...
- name: Update deployment status (success)
if: success()
uses: actions/github-script@v7
with:
script: |
await github.rest.repos.createDeploymentStatus({
owner: context.repo.owner,
repo: context.repo.repo,
deployment_id: ${{ steps.create-deployment.outputs.deployment_id }},
state: 'success',
environment_url: '${{ steps.deploy.outputs.app_url }}',
description: 'Deployment successful'
});
- name: Update deployment status (failure)
if: failure()
uses: actions/github-script@v7
with:
script: |
await github.rest.repos.createDeploymentStatus({
owner: context.repo.owner,
repo: context.repo.repo,
deployment_id: ${{ steps.create-deployment.outputs.deployment_id }},
state: 'failure',
description: 'Deployment failed'
});