-
Notifications
You must be signed in to change notification settings - Fork 11
190 lines (169 loc) · 5.96 KB
/
dev-deploy.yml
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
name: Deploy to dev cluster
on:
push:
branches:
- 'dev-*'
delete:
branches:
- 'dev-*'
pull_request:
types: [labeled, unlabeled, synchronize, closed]
# https://docs.github.com/en/actions/deployment/security-hardening-your-deployments/configuring-openid-connect-in-amazon-web-services
permissions:
contents: read
id-token: write
pull-requests: write
jobs:
deploy-to-dev:
name: deploy dev branch
runs-on: ubuntu-latest
environment: dev
if: |
github.repository == 'chanzuckerberg/cryoet-data-portal' && (
github.event_name != 'pull_request' || (
startsWith(github.head_ref, 'dev-') != true && (
contains(github.event.pull_request.labels.*.name, 'preview') || (
github.event.action == 'unlabeled' &&
github.event.label.name == 'preview'
)
)
)
)
steps:
- name: Checkout Repo
uses: actions/checkout@v4
- id: deploy-data
name: get stack name
uses: actions/github-script@v7
with:
result-encoding: string
script: |
const event = ${{ toJson(github.event) }}
const eventName = '${{ github.event_name }}'
let name = ''
switch (eventName) {
case 'pull_request': {
name = event.pull_request.head.ref
break
}
default: {
name = event.ref.replace('refs/heads/', '')
break
}
}
return name.replaceAll('/', '-').slice(0, 25)
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v4
with:
mask-aws-account-id: true
aws-region: ${{ secrets.AWS_REGION }}
role-to-assume: ${{ secrets.AWS_ROLE_TO_ASSUME }}
role-duration-seconds: 1200
- name: Create or update dev stack
if: |
github.event_name == 'push' || (
github.event_name == 'pull_request' && (
github.event.action == 'labeled' ||
github.event.action == 'synchronize'
)
)
uses: chanzuckerberg/github-actions/.github/actions/[email protected]
env:
# Force using BuildKit instead of normal Docker, required so that metadata
# is written/read to allow us to use layers of previous builds as cache.
DOCKER_BUILDKIT: 1
COMPOSE_DOCKER_CLI_BUILD: 1
DOCKER_REPO: ${{ secrets.ECR_REPO }}/
ENV: dev
with:
stack-name: ${{ steps.deploy-data.outputs.result }}
create-tag: true
tfe-token: ${{ secrets.TFE_TOKEN }}
working-directory: ./frontend
env: dev
operation: create-or-update
- name: Annotate workflow run with frontend URL
if: |
github.event_name == 'push' || (
github.event_name == 'pull_request' && (
github.event.action == 'labeled' ||
github.event.action == 'synchronize'
)
)
run: |
echo "# Frontend URL:" >> $GITHUB_STEP_SUMMARY
echo >> $GITHUB_STEP_SUMMARY
echo "https://${{ steps.deploy-data.outputs.result }}.cryoet.dev.si.czi.technology" >> $GITHUB_STEP_SUMMARY
- id: find-comment
name: Find PR comment
if: github.event_name == 'pull_request'
uses: peter-evans/find-comment@v3
with:
issue-number: ${{ github.event.pull_request.number }}
body-includes: 'Frontend Preview URL'
- id: get-comment-date
name: Get PR comment updated date
if: github.event_name == 'pull_request'
uses: actions/github-script@v7
with:
result-encoding: string
script: |
const date = new Date()
const options = {
month: '2-digit',
day: '2-digit',
year: '2-digit',
hour: '2-digit',
minute: '2-digit',
second: '2-digit',
hour12: true,
};
const pstDate = date.toLocaleString('en-US', { timeZone: 'America/Los_Angeles', ...options });
return pstDate.replace(',', ' @');
- name: Post comment on PR
if: |
github.event_name == 'pull_request' && (
github.event.action == 'labeled' ||
github.event.action == 'synchronize'
)
uses: peter-evans/create-or-update-comment@v4
with:
comment-id: ${{ steps.find-comment.outputs.comment-id}}
issue-number: ${{ github.event.pull_request.number}}
edit-mode: replace
body: |
# Frontend Preview URL
https://${{ steps.deploy-data.outputs.result }}.cryoet.dev.si.czi.technology
Updated: ${{ steps.get-comment-date.outputs.result }} PST
- name: Delete PR comment
if: |
github.event_name == 'pull_request' && (
github.event.action == 'unlabeled' ||
github.event.action == 'closed'
) &&
steps.find-comment.outputs.comment-id != ''
uses: actions/github-script@v7
with:
script: |
github.rest.issues.deleteComment({
comment_id: ${{ steps.find-comment.outputs.comment-id }},
owner: context.repo.owner,
repo: context.repo.repo,
})
- name: Delete dev
if: |
github.event_name == 'delete' || (
github.event_name == 'pull_request' && (
github.event.action == 'unlabeled' ||
github.event.action == 'closed'
)
)
uses: chanzuckerberg/github-actions/.github/actions/[email protected]
env:
ENV: dev
with:
stack-name: ${{ steps.deploy-data.outputs.result }}
operation: delete
tfe-token: ${{ secrets.TFE_TOKEN }}
env: dev
working-directory: ./frontend