generated from app-generator/django-react-soft-dashboard
-
Notifications
You must be signed in to change notification settings - Fork 0
261 lines (240 loc) · 8.04 KB
/
main.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
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
name: Mainframe pipeline
on:
push:
branches:
- main
env:
BACKEND_SERVICE: ${{ secrets.BACKEND_SERVICE }}
FRONTEND_SERVICE: ${{ secrets.FRONTEND_SERVICE }}
PROJECT_ID: ${{ secrets.PROJECT_ID }}
RUN_REGION: ${{ secrets.REGION }}
REACT_APP_NGROK_URL: ${{ secrets.REACT_APP_NGROK_URL }}
jobs:
notify-telegram:
name: Notify telegram
runs-on: ubuntu-latest
steps:
- name: send telegram message
uses: appleboy/telegram-action@master
with:
disable_notification: true
disable_web_page_preview: true
format: markdown
message: |
New changes: [${{ github.event.commits[0].message }}](https://github.com/${{ github.repository }}/commit/${{github.sha}})
Author: ${{ github.actor }}
Repo: ${{ github.repository }}
to: ${{ secrets.TELEGRAM_TO }}
token: ${{ secrets.TELEGRAM_TOKEN }}
changes:
outputs:
backend: ${{ steps.filter.outputs.backend }}
dockerfile: ${{ steps.filter.outputs.dockerfile }}
frontend: ${{ steps.filter.outputs.frontend }}
tests: ${{ steps.filter.outputs.tests }}
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- uses: dorny/paths-filter@v3
id: filter
with:
filters: |
backend:
- 'src/mainframe/**'
dockerfile:
- 'Dockerfile'
frontend:
- 'frontend/**'
tests:
- 'tests/**'
security:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@main
- name: Run Safety CLI to check for vulnerabilities
uses: pyupio/safety-action@v1
with:
api-key: ${{ secrets.SAFETY_API_KEY }}
args: --detailed-output
pre-commit:
name: pre-commit (w/o pytest)
runs-on: ubuntu-latest
needs: changes
if: ${{ (needs.changes.outputs.backend == 'true') || (needs.changes.outputs.dockerfile == 'true') || (needs.changes.outputs.tests == 'true') }}
steps:
- uses: actions/checkout@v4
- name: Installing dev dependencies for migration check
run: pip install -r requirements-dev.lock
- uses: pre-commit/[email protected]
env:
ENV: ci
SKIP: pytest
tests:
runs-on: ubuntu-latest
needs: changes
if: ${{ (needs.changes.outputs.backend == 'true') || (needs.changes.outputs.dockerfile == 'true') || (needs.changes.outputs.tests == 'true') }}
steps:
- uses: actions/checkout@v4
- uses: Harmon758/[email protected]
with:
postgresql version: 13
postgresql db: test_db
postgresql user: test_user
postgresql password: test_pass
- name: Run a multi-line script
run: |
pip install -r requirements-dev.lock
PYTHONPATH=src ENV=ci pytest tests --cov=. --ds mainframe.core.settings --nomigrations
backend-deploy:
name: BE - Deploy
runs-on: ubuntu-latest
permissions:
contents: 'read'
id-token: 'write'
needs:
- pre-commit
- security
- tests
steps:
- name: Notify BE start deployment
uses: appleboy/telegram-action@master
with:
disable_notification: true
disable_web_page_preview: true
format: markdown
message: Mainframe - Starting BE deploy
to: ${{ secrets.TELEGRAM_TO }}
token: ${{ secrets.TELEGRAM_TOKEN }}
- name: Checkout Repo
uses: actions/checkout@v4
- name: Setup GCloud Auth
id: auth
uses: google-github-actions/[email protected]
with:
service_account: ${{ secrets.WIF_SERVICE_ACCOUNT }}
token_format: 'access_token'
workload_identity_provider: ${{ secrets.WIF_PROVIDER }}
- name: Set up Cloud SDK
uses: google-github-actions/[email protected]
- name: Build & Push
run: |-
gcloud builds submit \
--quiet \
--tag="$RUN_REGION-docker.pkg.dev/$PROJECT_ID/mainframe-backend/$BACKEND_SERVICE:$GITHUB_SHA" \
--gcs-log-dir="gs://build-backend-logs"
# Deploy image to Cloud Run
- name: Deploy GCR
run: |-
gcloud run deploy "$BACKEND_SERVICE" \
--quiet \
--region "$RUN_REGION" \
--image "$RUN_REGION-docker.pkg.dev/$PROJECT_ID/mainframe-backend/$BACKEND_SERVICE:$GITHUB_SHA" \
--platform "managed" \
--allow-unauthenticated
- name: Notify
uses: appleboy/telegram-action@master
with:
disable_notification: true
disable_web_page_preview: true
format: markdown
message: Mainframe - BE deployed successfully 🚀
to: ${{ secrets.TELEGRAM_TO }}
token: ${{ secrets.TELEGRAM_TOKEN }}
frontend-build:
name: FE - Build
runs-on: ubuntu-latest
needs:
- changes
- security
if: ${{ needs.changes.outputs.frontend == 'true' }}
steps:
- name: Notify FE start deployment
uses: appleboy/telegram-action@master
with:
disable_notification: true
disable_web_page_preview: true
format: markdown
message: |
[Mainframe](${{ github.event.workflow_job.html_url }}) - Starting FE deploy
to: ${{ secrets.TELEGRAM_TO }}
token: ${{ secrets.TELEGRAM_TOKEN }}
- name: Checkout Repo
uses: actions/checkout@master
- name: Setup Node.js (NPM)
uses: actions/setup-node@master
with:
node-version: '14.x'
- name: Use cached node_modules
uses: actions/cache@master
with:
path: node_modules
key: nodeModules-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
nodeModules-
- name: Install dependencies
working-directory: frontend
run: npm install --frozen-lockfile
env:
CI: true
- name: Build Development
working-directory: frontend
run: npm run build
env:
CI: false
- name: Archive Production Artifact
uses: actions/upload-artifact@main
with:
name: build
path: frontend/build
frontend-deploy:
name: FE - Deploy
needs: frontend-build
runs-on: ubuntu-latest
permissions:
contents: 'read'
id-token: 'write'
steps:
- name: Checkout Repo
uses: actions/checkout@v3
- name: Download Artifact
uses: actions/download-artifact@master
with:
name: build
path: frontend/.docker/build
- name: Setup GCloud Auth
id: auth
uses: google-github-actions/[email protected]
with:
service_account: ${{ secrets.WIF_SERVICE_ACCOUNT }}
token_format: 'access_token'
workload_identity_provider: ${{ secrets.WIF_PROVIDER }}
- name: Set up Cloud SDK
uses: google-github-actions/[email protected]
# Build and push image to Google Container Registry
- name: Build & Push
run: |-
gcloud builds submit \
--quiet \
--tag="$RUN_REGION-docker.pkg.dev/$PROJECT_ID/mainframe-frontend/$FRONTEND_SERVICE:$GITHUB_SHA" \
--gcs-log-dir="gs://build-frontend-logs"
working-directory: frontend/.docker
# Deploy image to Cloud Run
- name: Deploy GCR
run: |-
gcloud run deploy "$FRONTEND_SERVICE" \
--quiet \
--region "$RUN_REGION" \
--image "$RUN_REGION-docker.pkg.dev/$PROJECT_ID/mainframe-frontend/$FRONTEND_SERVICE:$GITHUB_SHA" \
--platform "managed" \
--allow-unauthenticated \
--set-env-vars "REACT_APP_NGROK_URL=$REACT_APP_NGROK_URL"
- name: Notify
uses: appleboy/telegram-action@master
with:
disable_notification: true
disable_web_page_preview: true
format: markdown
message: Mainframe - FE deployed successfully 🚀
to: ${{ secrets.TELEGRAM_TO }}
token: ${{ secrets.TELEGRAM_TOKEN }}