-
Notifications
You must be signed in to change notification settings - Fork 3
177 lines (152 loc) · 5.63 KB
/
ci.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
name: CI
on:
push:
branches: ["main", "production"]
pull_request:
types: [opened, synchronize]
workflow_dispatch:
env:
TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }} # remote caching
TURBO_TEAM: ${{ secrets.TURBO_TEAM }} # remote caching
jobs:
build:
name: Lint, Build and Test
timeout-minutes: 15
runs-on: ubuntu-latest
steps:
- name: Grab cache
uses: actions/cache/restore@v3
with:
path: .
key: CI-${{ runner.os }}-${{ github.ref }}-${{ github.run_id }}
restore-keys: |
CI-${{ runner.os }}-${{ github.ref }}-
CI-${{ runner.os }}-refs/head/main-
- name: Check out code
uses: actions/checkout@v3
with:
fetch-depth: 2
- name: Setup Node.js environment
uses: actions/setup-node@v3
with:
node-version: 16
cache: "yarn"
- name: Install dependencies
run: yarn install --prefer-offline --frozen-lockfile
- name: Run Prettier
id: prettier-run
uses: rutajdash/[email protected]
with:
config_path: ./.prettierrc
# This step only runs if prettier finds errors causing the previous step to fail
# This steps lists the files where errors were found
- name: Prettier Output
if: ${{ failure() }}
shell: bash
run: |
echo "❌ The following files are not formatted:"
echo "${{steps.prettier-run.outputs.prettier_output}}"
echo "⭐️ You should run `yarn format` in the root of the project directory to fix these files"
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID_CI }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY_CI }}
aws-region: ap-southeast-1
- name: Lint + Build + Unit Test
run: yarn turbo run lint build:ci --color
env:
#merch
AWS_REGION: 'ap-southeast-1'
PRODUCT_TABLE_NAME: 'be-dev-products'
ORDER_TABLE_NAME: 'be-dev-orders'
ORDER_HOLD_TABLE_NAME: 'be-dev-orders-hold'
# web
WORDPRESS_API_URL: 'https://clubs.ntu.edu.sg/csec/graphql'
NEXT_PUBLIC_MERCH_API_ORIGIN: 'http://127.0.0.1:3002'
- name: Cache CI workflow for dependent jobs
uses: actions/cache/save@v3
with:
path: .
key: CI-${{ runner.os }}-${{ github.ref }}-${{ github.run_id }}
preview:
name: Vercel Preview - web
timeout-minutes: 15
runs-on: ubuntu-latest
needs: build
permissions:
deployments: write
pull-requests: write
env:
VERCEL_TOKEN: ${{ secrets.VERCEL_TOKEN }}
VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }}
VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID_WEB }}
steps:
- name: Create GitHub deployment
uses: chrnorm/deployment-action@v2
id: deployment
with:
token: '${{ github.token }}'
environment: Preview - website
- name: Set Github Deployment status to pending
uses: chrnorm/deployment-status@v2
with:
token: '${{ github.token }}'
state: 'pending'
deployment-id: ${{ steps.deployment.outputs.deployment_id }}
- name: Get build cache
uses: actions/cache/restore@v3
with:
path: .
key: CI-${{ runner.os }}-${{ github.ref }}-${{ github.run_id }}
fail-on-cache-miss: true
- name: Install Vercel CLI
run: npm install --global vercel@latest
- name: Pull Vercel Environment Information
run: vercel pull --yes --environment=preview --token=${{ secrets.VERCEL_TOKEN }}
- name: Copy Build Artifacts to .vercel dir
run: vercel build --token=${{ secrets.VERCEL_TOKEN }}
- name: Deploy Project Artifacts to Vercel
id: deploy-to-vercel
run: |
DEPLOYMENT_URL=$(vercel deploy --prebuilt --token=${{ secrets.VERCEL_TOKEN }})
echo "deployment-url=$DEPLOYMENT_URL" >> "$GITHUB_OUTPUT"
- name: Print Deployment URL
env:
DEPLOYMENT_URL: ${{ steps.deploy-to-vercel.outputs.deployment-url }}
run: echo $DEPLOYMENT_URL
- name: Update deployment status (success)
if: success()
uses: chrnorm/deployment-status@v2
with:
token: '${{ github.token }}'
environment-url: '${{ steps.deploy-to-vercel.outputs.deployment-url }}'
state: 'success'
deployment-id: ${{ steps.deployment.outputs.deployment_id }}
- name: Update deployment status (failure)
if: failure()
uses: chrnorm/deployment-status@v2
with:
token: '${{ github.token }}'
state: 'failure'
deployment-id: ${{ steps.deployment.outputs.deployment_id }}
- name: Comment PR with preview link if success
if: success() && github.event_name == 'pull_request'
uses: thollander/actions-comment-pull-request@v2
env:
DEPLOYMENT_URL: ${{ steps.deploy-to-vercel.outputs.deployment-url }}
with:
message: |
Deployment preview link: ${{ env.DEPLOYMENT_URL }}
comment_tag: execution
mode: recreate
- name: Comment PR with preview link if fail
if: failure() && github.event_name == 'pull_request'
uses: thollander/actions-comment-pull-request@v2
env:
DEPLOYMENT_URL: ${{ steps.deploy-to-vercel.outputs.deployment-url }}
with:
message: |
Deployment preview link: ❌
comment_tag: execution
mode: recreate