-
Notifications
You must be signed in to change notification settings - Fork 0
101 lines (81 loc) · 2.94 KB
/
node.js.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
name: Build & Deploy
on:
push:
branches:
- staging
- development
- master
pull_request:
branches:
- staging
- master
workflow_dispatch:
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
build:
name: Checks, Tests & Build
runs-on: ubuntu-latest
steps:
- name: Repository checkout
uses: actions/checkout@v4
- name: Node.js setup
uses: actions/setup-node@v4
with:
node-version-file: .tool-versions
- name: 📦 Install dependencies
run: yarn install
- name: 💅 Prettier check
run: yarn prettier:check
- name: 💨 Lint check
run: yarn lint
- name: ✅ Run Tests
run: yarn test --no-watch
- name: 🏗️ Build app
run: yarn build
deploy:
name: Deploy
if: (github.event_name == 'push' || github.event_name == 'workflow_dispatch') && (github.ref == 'refs/heads/master' || github.ref == 'refs/heads/staging' || github.ref == 'refs/heads/development')
runs-on: ubuntu-latest
environment:
name: ${{ (github.ref == 'refs/heads/master' && 'prod') || (github.ref == 'refs/heads/staging' && 'stage') || 'dev' }}
needs: build
permissions:
id-token: write
contents: read
steps:
- name: Repository checkout
uses: actions/checkout@v4
- name: Node.js setup
uses: actions/setup-node@v4
with:
node-version-file: .tool-versions
- name: 📦 Install dependencies
run: yarn install
- name: 🏗️ Build app
run: yarn build --configuration $buildEnvironment
env:
buildEnvironment: ${{ github.ref == 'refs/heads/development' && 'development' || 'production' }}
- name: Copy embed.js
run: cp embed/embed.js dist/embed.js
- name: Copy mobile directory
run: cp -r mobile/ dist/mobile/
- name: Update embed host
run: sed -i "s%$appDomainPlaceholder%$appDomain%g" dist/embed.js
env:
appDomainPlaceholder: '{appDomain}'
appDomain: https://${{ secrets.HOST_NAME }}
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
aws-region: us-east-1
role-to-assume: ${{ secrets.AWS_IAM_ROLE_ARN }}
- name: Deploy to s3
run: |
aws s3 sync dist/knowgod $S3_BUCKET --acl 'public-read' --exclude '*.html' --cache-control 'public, max-age=31536000' --delete
aws s3 sync dist/knowgod $S3_BUCKET --acl 'public-read' --include '*.html' --cache-control 'public, max-age=120' --delete
aws s3 cp dist/embed.js $S3_BUCKET --acl 'public-read' --cache-control 'public, max-age=600'
aws s3 sync dist/mobile $S3_BUCKET --acl 'public-read' --cache-control 'public, max-age=3600' --content-type 'application/json'
env:
S3_BUCKET: s3://${{ secrets.AWS_S3_BUCKET }}