-
Notifications
You must be signed in to change notification settings - Fork 25
182 lines (156 loc) · 6.74 KB
/
Copy pathdeploy.yml
File metadata and controls
182 lines (156 loc) · 6.74 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
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
name: Deployment
on:
pull_request:
branches:
- master
- main
- develop
- release/next
types: [closed]
concurrency:
group: ${{ github.workflow }}-${{ github.base_ref }}
cancel-in-progress: true
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK }}
SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN_V2 }}
jobs:
build_and_deploy:
if: github.event.pull_request.merged == true
runs-on: ubuntu-latest
steps:
- name: Checkout Repo
uses: actions/checkout@master
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '18'
cache: 'npm'
- name: Setup rclone
if: github.base_ref == 'develop' || github.base_ref == 'master' || github.base_ref == 'main' || github.base_ref == 'release/next'
uses: AnimMouse/setup-rclone@v1
with:
rclone_config: |
[r2]
type = s3
provider = Cloudflare
access_key_id = ${{ secrets.RCLONE_CONFIG_R2_ACCESS_KEY_ID }}
secret_access_key = ${{ secrets.RCLONE_CONFIG_R2_SECRET_ACCESS_KEY }}
endpoint = ${{ secrets.RCLONE_CONFIG_R2_ENDPOINT }}
disable_base64: true
- name: Cache NPM dependencies
uses: actions/cache@v4
id: node_modules_cache
with:
path: node_modules
key: ${{ runner.os }}-v18-npm-v4-${{ hashFiles('package-lock.json') }}
- name: Cache Next.js
uses: actions/cache@v4
with:
path: |
~/.npm
${{ github.workspace }}/.next/cache
key: ${{ runner.os }}-nextjs-${{ hashFiles('**/package-lock.json') }}-${{ hashFiles('**/*.js', '**/*.jsx', '**/*.ts', '**/*.tsx') }}
restore-keys: |
${{ runner.os }}-nextjs-${{ hashFiles('**/package-lock.json') }}-
- name: Install Dependencies
if: steps.node_modules_cache.outputs.cache-hit != 'true'
run: npm ci
- name: Generate Types (develop)
if: github.base_ref == 'develop'
run: npm run gen:type
- name: Generate Types (production)
if: github.base_ref == 'master' || github.base_ref == 'main' || github.base_ref == 'release/next'
run: npm run gen:type:prod
- name: Lint
run: |
npm run i18n \
&& npm run lint \
&& npm run format:check
# - name: Test
# run: npm install codecov -g && npm run test && codecov
# env:
# CODECOV_TOKEN: f109cbf6-b6c7-4a08-ad03-981bc4cd1fe8
# MATTERS_ENV: test
# API_URL: http://matters-server-develop.ap-southeast-1.elasticbeanstalk.com/graphql
# - name: Test - BDD
# === `develop` branch ===
- name: Build (develop)
if: github.base_ref == 'develop'
run: cp .env.dev .env.local && npm run build
# === `master` branch ===
- name: Build (production)
if: github.base_ref == 'master' || github.base_ref == 'main'
run: cp .env.prod .env.local && npm run build
# === `webnext` branch ===
- name: Build (webnext)
if: github.base_ref == 'release/next'
run: cp .env.prod-next .env.local && npm run build
- name: Setup AWS
if: github.base_ref == 'develop' || github.base_ref == 'master' || github.base_ref == 'main' || github.base_ref == 'release/next'
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ github.base_ref == 'develop' && secrets.AWS_REGION_DEV || secrets.AWS_REGION_PROD }}
- name: Generate deployment package
if: github.base_ref == 'develop' || github.base_ref == 'master' || github.base_ref == 'main' || github.base_ref == 'release/next'
run: |
zip -r --symlinks deploy.zip . -x .git/\* node_modules/\* .next/cache/\*
- name: Upload Assets (develop - R2)
if: github.base_ref == 'develop'
run: rclone copy .next r2:matters-assets-next-develop/_next --include "/*" --include "/static/**" -P
- name: Deploy to EB (develop)
if: github.base_ref == 'develop'
uses: einaregilsson/beanstalk-deploy@v22
with:
aws_access_key: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws_secret_key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
application_name: matters-stage
environment_name: ${{ secrets.AWS_EB_ENV_NAME_DEV }}
version_label: matters-web-develop-${{ hashFiles('deploy.zip') }}
version_description: ${{ github.SHA }}
region: ${{ secrets.AWS_REGION_DEV }}
deployment_package: deploy.zip
use_existing_version_if_available: true
wait_for_deployment: true
- name: Upload Assets (production - R2)
if: github.base_ref == 'master' || github.base_ref == 'main' || github.base_ref == 'release/next'
run: rclone copy .next r2:matters-assets-next/_next --include "/*" --include "/static/**" -P
- name: Deploy to EB (production)
if: github.base_ref == 'master' || github.base_ref == 'main'
uses: einaregilsson/beanstalk-deploy@v22
with:
aws_access_key: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws_secret_key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
application_name: matters-prod
environment_name: ${{ secrets.AWS_EB_ENV_NAME_PROD }}
version_label: matters-web-prod-${{ hashFiles('deploy.zip') }}
version_description: ${{ github.SHA }}
region: ${{ secrets.AWS_REGION_PROD }}
deployment_package: deploy.zip
use_existing_version_if_available: true
wait_for_deployment: true
- name: Deploy to EB (webnext)
if: github.base_ref == 'release/next'
uses: einaregilsson/beanstalk-deploy@v22
with:
aws_access_key: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws_secret_key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
application_name: matters-prod
environment_name: ${{ secrets.AWS_EB_ENV_NAME_WEBNEXT }}
version_label: matters-web-webnext-${{ hashFiles('deploy.zip') }}
version_description: ${{ github.SHA }}
region: ${{ secrets.AWS_REGION_DEV }}
deployment_package: deploy.zip
use_existing_version_if_available: true
wait_for_deployment: true
- name: Slack Notification
if: always()
uses: 8398a7/action-slack@v3
with:
status: ${{ job.status }}
author_name: matters-web
fields: repo,message,commit,author,action,eventName,ref,workflow,job,took