-
Notifications
You must be signed in to change notification settings - Fork 460
204 lines (169 loc) · 5.9 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
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
name: CI
on:
pull_request:
push:
branches:
- main
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
# This job installs dependencies once and caches them.
build:
runs-on: ubuntu-latest
outputs:
yarn-types-cache-key: ${{ steps.restore-yarn-types.outputs.cache-primary-key }}
nc-cache-key: ${{ steps.restore-nc.outputs.cache-primary-key }}
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/corepack
- name: Restore Yarn Cache & Types
id: restore-yarn-types
uses: ./.github/actions/cache-deps
with:
mode: restore-yarn
- name: Echo cache hit
run: |
echo "Yarn cache hit: ${{ steps.restore-yarn-types.outputs.cache-hit-yarn }}"
- name: Yarn install & after-install generate types
if: steps.restore-yarn-types.outputs.cache-hit-yarn != 'true'
run: |
yarn install --immutable
yarn after-install
- name: Save Yarn Cache & Types
if: steps.restore-yarn-types.outputs.cache-hit-yarn != 'true'
uses: ./.github/actions/cache-deps
with:
mode: save-yarn
key: ${{ steps.restore-yarn-types.outputs.computed-cache-key-yarn }}
eslint:
needs: build
permissions:
checks: write
pull-requests: read
statuses: write
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Restore Yarn Cache & Types
uses: ./.github/actions/cache-deps
with:
mode: restore-yarn
- uses: CatChen/[email protected]
with:
request-changes: true # optional
fail-check: true # optional
github-token: ${{ secrets.GITHUB_TOKEN }} # optional
directory: './' # optional
targets: 'src' # optional
config-path: './eslint.config.mjs'
test:
needs: build
permissions:
contents: read
checks: write
pull-requests: write
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/corepack
- name: Restore Yarn Cache & Types
uses: ./.github/actions/cache-deps
with:
mode: restore-yarn
- name: Annotations and coverage report
uses: ArtiomTr/[email protected]
with:
skip-step: install
annotations: failed-tests
package-manager: yarn
test-script: yarn test:ci
github-token: ${{ secrets.GITHUB_TOKEN }}
deploy:
needs: build
runs-on: ubuntu-latest
permissions:
pull-requests: write
id-token: write
name: Deploy to dev/staging
steps:
# Post a PR comment before deploying
- name: Post a comment while building
if: github.event.number
uses: mshick/add-pr-comment@v2
with:
message-id: praul
message: |
## Branch preview
⏳ Deploying a preview site...
repo-token: ${{ secrets.GITHUB_TOKEN }}
repo-token-user-login: 'github-actions[bot]'
- uses: actions/checkout@v4
- uses: ./.github/actions/corepack
- name: Restore Yarn Cache & Types
uses: ./.github/actions/cache-deps
with:
mode: restore-yarn
- name: Restore Next.js Build Cache & Cypress cache
id: restore-nc
uses: ./.github/actions/cache-deps
with:
mode: restore-nc
- uses: ./.github/actions/build
with:
secrets: ${{ toJSON(secrets) }}
#if: startsWith(github.ref, 'refs/heads/main')
- name: Save Next.js Build Cache & Cypress cache
if: steps.restore-nc.outputs.cache-hit-nc != 'true'
uses: ./.github/actions/cache-deps
with:
mode: save-nc
key: ${{ steps.restore-nc.outputs.computed-cache-key-nc }}
#- uses: ./.github/workflows/build-storybook
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: ${{ secrets.AWS_ROLE }}
aws-region: ${{ secrets.AWS_REGION }}
# Staging
- name: Deploy to the staging S3
if: startsWith(github.ref, 'refs/heads/main')
env:
BUCKET: s3://${{ secrets.AWS_STAGING_BUCKET_NAME }}/current
run: bash ./scripts/github/s3_upload.sh
# Dev
- name: Deploy to the dev S3
if: startsWith(github.ref, 'refs/heads/dev')
env:
BUCKET: s3://${{ secrets.AWS_DEVELOPMENT_BUCKET_NAME }}
run: bash ./scripts/github/s3_upload.sh
### PRs ###
# Extract branch name
- name: Extract branch name
shell: bash
## Cut off "refs/heads/", only allow alphanumeric characters and convert to lower case,
## e.g. "refs/heads/features/hello-1.2.0" -> "features_hello_1_2_0"
run: echo "branch=$(echo $GITHUB_HEAD_REF | sed 's/refs\/heads\///' | sed 's/[^a-z0-9]/_/ig' | sed 's/[A-Z]/\L&/g')" >> $GITHUB_OUTPUT
id: extract_branch
# Deploy to S3
- name: Deploy PR branch
if: github.event.number
env:
BUCKET: s3://${{ secrets.AWS_REVIEW_BUCKET_NAME }}/walletweb/${{ steps.extract_branch.outputs.branch }}
run: bash ./scripts/github/s3_upload.sh
# Comment
- name: Post a deployment link in the PR
if: always() && github.event.number
uses: mshick/add-pr-comment@v2
with:
message-id: praul
message: |
## Branch preview
✅ Deploy successful!
**Website:**
https://${{ steps.extract_branch.outputs.branch }}--walletweb.review.5afe.dev/home?safe=eth:0xA77DE01e157f9f57C7c4A326eeE9C4874D0598b6
**Storybook:**
https://${{ steps.extract_branch.outputs.branch }}--walletweb.review.5afe.dev/storybook/
message-failure: |
## Branch preview
❌ Deploy failed!