-
Notifications
You must be signed in to change notification settings - Fork 1
192 lines (170 loc) · 6.95 KB
/
frontend_deploy_prod.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
name: KnowX Frontend Deploy
on:
push:
branches:
- tests-Diego
- main
permissions:
actions: write
id-token: write
contents: read
jobs:
test-e2e:
name: "Frontend E2E Tests"
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Install Node
uses: actions/setup-node@v4
with:
node-version: "20"
working-directory: knowx
- name: Install Dependencies
run: npm install
working-directory: knowx
- name: Make envfile
uses: SpicyPizza/[email protected]
with:
envkey_API_ROOT_ROUTE: ${{ secrets.API_ROOT_ROUTE }}
envkey_DB_URL: ${{ secrets.DEV_DB_URL }}
envkey_NEXTAUTH_URL: "http://localhost:3000/"
envkey_NEXTAUTH_SECRET: ${{ secrets.NEXTAUTH_SECRET }}
envkey_GITHUB_ID: ${{ secrets.NEXTAUTH_GITHUB_ID }}
envkey_GITHUB_SECRET: ${{ secrets.NEXTAUTH_GITHUB_SECRET }}
envkey_GOOGLE_CLIENT_ID: ${{ secrets.GOOGLE_CLIENT_ID }}
envkey_GOOGLE_CLIENT_SECRET: ${{ secrets.GOOGLE_CLIENT_SECRET }}
envkey_SLACK_CLIENT_ID: ${{ secrets.SLACK_CLIENT_ID }}
envkey_SLACK_CLIENT_SECRET: ${{ secrets.SLACK_CLIENT_SECRET }}
envkey_EMAIL_SERVER_HOST: ${{ secrets.EMAIL_SERVER_HOST }}
envkey_EMAIL_SERVER_PORT: ${{ secrets.EMAIL_SERVER_PORT }}
envkey_EMAIL_SERVER_USER: ${{ secrets.EMAIL_SERVER_USER }}
envkey_EMAIL_SERVER_PASSWORD: ${{ secrets.EMAIL_SERVER_PASSWORD }}
envkey_EMAIL_FROM: ${{ secrets.EMAIL_FROM }}
envkey_SENDGRID_API_KEY: ${{ secrets.SENDGRID_API_KEY }}
directory: knowx
- name: Run Server
run: npm run dev &
working-directory: knowx
- name: Run Tests
uses: cypress-io/github-action@v6
with:
browser: chrome
headed: true
wait-on: "http://localhost:3000"
working-directory: knowx
env:
CYPRESS_CACHE_FOLDER: ~/.cache/Cypress
- name: Upload screenshots
uses: actions/upload-artifact@v4
if: failure()
with:
name: cypress-screenshots
path: /home/runner/work/itesm-socioformador-feb-jun-2024-Croods/itesm-socioformador-feb-jun-2024-Croods/knowx/cypress/screenshots
- name: Send Deploy Failure Message
if: failure()
run: curl -s -X POST "${{ secrets.DISCORD_WEBHOOK }}" -d "content=💥 Front Testing Failed"
- name: Send Deploy Success Message
if: success()
run: |
curl -s -X POST "${{ secrets.DISCORD_WEBHOOK }}" -d "content=🧪 Front Testing Successful"
unit-tests:
name: "Frontend Unit Tests"
needs: test-e2e
runs-on: ubuntu-latest
defaults:
run:
working-directory: knowx
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Node setup
uses: actions/setup-node@v4
with:
node-version: 20
- name: install dependencies
run: npm install
- name: run tests
run: npm run test:ci
deploy:
needs: [test-e2e, unit-tests]
name: "Deploy to AWS - PRODUCTION"
environment: prod
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Cofigure AWS
uses: aws-actions/configure-aws-credentials@v4
with:
aws-region: us-east-1
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
- name: Install SST
run: |
ls
wget https://github.com/sst/ion/releases/download/v0.0.193/sst-linux-amd64.deb
sudo dpkg -i sst-linux-amd64.deb
sst version
- name: Copy Secrets
run: |
sst secret set APIRootRoute $API_ROOT_ROUTE --stage prod
sst secret set DBUrl $DB_URL --stage prod
sst secret set NextAuthUrl $NEXTAUTH_URL --stage prod
sst secret set NextAuthSecret $NEXTAUTH_SECRET --stage prod
sst secret set GithubId $GITHUB_ID --stage prod
sst secret set GithubSecret $GITHUB_SECRET --stage prod
sst secret set GoogleClientId $GOOGLE_CLIENT_ID --stage prod
sst secret set GoogleClientSecret $GOOGLE_CLIENT_SECRET --stage prod
sst secret set SlackClientId $SLACK_CLIENT_ID --stage prod
sst secret set SlackClientSecret $SLACK_CLIENT_SECRET --stage prod
sst secret set EmailServerHost $EMAIL_SERVER_HOST --stage prod
sst secret set EmailServerPort $EMAIL_SERVER_PORT --stage prod
sst secret set EmailServerUser $EMAIL_SERVER_USER --stage prod
sst secret set EmailServerPassword $EMAIL_SERVER_PASSWORD --stage prod
sst secret set EmailFrom $EMAIL_FROM --stage prod
sst secret set SendgridApiKey $SENDGRID_API_KEY --stage prod
working-directory: knowx
env:
API_ROOT_ROUTE: ${{ secrets.API_ROOT_ROUTE }}
DB_URL: ${{ secrets.DB_URL }}
NEXTAUTH_URL: ${{ secrets.NEXTAUTH_URL }}
NEXTAUTH_SECRET: ${{ secrets.NEXTAUTH_SECRET }}
GITHUB_ID: ${{ secrets.NEXTAUTH_GITHUB_ID }}
GITHUB_SECRET: ${{ secrets.NEXTAUTH_GITHUB_SECRET }}
GOOGLE_CLIENT_ID: ${{ secrets.GOOGLE_CLIENT_ID }}
GOOGLE_CLIENT_SECRET: ${{ secrets.GOOGLE_CLIENT_SECRET }}
SLACK_CLIENT_ID: ${{ secrets.SLACK_CLIENT_ID }}
SLACK_CLIENT_SECRET: ${{ secrets.SLACK_CLIENT_SECRET }}
EMAIL_SERVER_HOST: ${{ secrets.EMAIL_SERVER_HOST }}
EMAIL_SERVER_PORT: ${{ secrets.EMAIL_SERVER_PORT }}
EMAIL_SERVER_USER: ${{ secrets.EMAIL_SERVER_USER }}
EMAIL_SERVER_PASSWORD: ${{ secrets.EMAIL_SERVER_PASSWORD }}
EMAIL_FROM: ${{ secrets.EMAIL_FROM }}
SENDGRID_API_KEY: ${{ secrets.SENDGRID_API_KEY }}
- name: NPM install
run: npm install
working-directory: knowx
- name: Deploy
id: deploy
run: |
sst deploy --stage prod > deployment_output.txt
echo "deployment_output_path=deployment_output.txt" >> $GITHUB_OUTPUT
working-directory: knowx
- name: Extract URL from Deployment Output
id: extract_url
run: |
output=$(cat ${{ steps.deploy.outputs.deployment_output_path }})
urls=$(echo "$output" | grep -oE 'https?://[^ ]+')
last_url=$(echo "$urls" | tail -n1)
echo "url=$last_url" >> $GITHUB_OUTPUT
working-directory: knowx
- name: Send Deploy Failure Message
if: failure()
run: curl -s -X POST "${{ secrets.DISCORD_WEBHOOK }}" -d "content=🚨 Frontend PROD Deploy Failed"
- name: Send Deploy Success Message
if: success()
run: |
curl -s -X POST "${{ secrets.DISCORD_WEBHOOK }}" -d "content=✅ Frontend PROD Deploy Successful"
url=${{ steps.extract_url.outputs.url }}
curl -s -X POST "${{ secrets.DISCORD_WEBHOOK }}" -d "content=🚀 Deployment PROD URL: $url"