-
Notifications
You must be signed in to change notification settings - Fork 59
303 lines (267 loc) · 10.9 KB
/
main.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
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
name: CI
on:
push:
branches: [master]
pull_request:
branches: [master]
workflow_dispatch:
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: ${{ github.ref != 'refs/heads/master' }}
jobs:
# Assigns the event creator to the PR
assign_pr_owner:
name: Assign PR Owner
runs-on: ubuntu-latest
steps:
- name: Assign PR to creator
uses: thomaseizinger/[email protected]
if: github.event_name == 'pull_request' && github.event.action == 'opened'
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
# Creates a build and uploads an artifact
build:
name: Build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version-file: '.nvmrc'
registry-url: 'https://registry.npmjs.org'
cache: 'npm'
- name: Build dependencies
run: |
npm run install:ci
npm run install:themes
npm run build
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
- name: Compress public directory
run: tar -zcvf public-dir.tar.gz ./public/
- uses: actions/upload-artifact@v4
with:
name: public-folder
path: public-dir.tar.gz
# Lint the code
lint:
name: Lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: actions/setup-node@v4
with:
node-version-file: '.nvmrc'
registry-url: 'https://registry.npmjs.org'
cache: 'npm'
- name: Linting
run: |
npm run install:ci
npm run lint
# Typecheck the source code
typecheck:
name: Typecheck
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup Node
uses: actions/setup-node@v4
with:
node-version-file: '.nvmrc'
registry-url: 'https://registry.npmjs.org'
cache: 'npm'
- name: Install
run: npm run install:ci
- name: Typecheck
run: npm run types:check
# Test components
testing:
name: Testing
runs-on: ubuntu-latest
outputs:
coverage_statements_pct_master: ${{ steps.coverage-master.outputs.coverage_statements_pct_master }}
coverage_branches_pct_master: ${{ steps.coverage-master.outputs.coverage_branches_pct_master }}
coverage_functions_pct_master: ${{ steps.coverage-master.outputs.coverage_functions_pct_master }}
coverage_lines_pct_master: ${{ steps.coverage-master.outputs.coverage_lines_pct_master }}
coverage_statements_pct_current: ${{ steps.coverage-current.outputs.coverage_statements_pct_current }}
coverage_branches_pct_current: ${{ steps.coverage-current.outputs.coverage_branches_pct_current }}
coverage_functions_pct_current: ${{ steps.coverage-current.outputs.coverage_functions_pct_current }}
coverage_lines_pct_current: ${{ steps.coverage-current.outputs.coverage_lines_pct_current }}
coverage_statements_total_current: ${{ steps.coverage-current.outputs.coverage_statements_total_current }}
coverage_branches_total_current: ${{ steps.coverage-current.outputs.coverage_branches_total_current }}
coverage_functions_total_current: ${{ steps.coverage-current.outputs.coverage_functions_total_current }}
coverage_lines_total_current: ${{ steps.coverage-current.outputs.coverage_lines_total_current }}
coverage_statements_covered_current: ${{ steps.coverage-current.outputs.coverage_statements_covered_current }}
coverage_branches_covered_current: ${{ steps.coverage-current.outputs.coverage_branches_covered_current }}
coverage_functions_covered_current: ${{ steps.coverage-current.outputs.coverage_functions_covered_current }}
coverage_lines_covered_current: ${{ steps.coverage-current.outputs.coverage_lines_covered_current }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: actions/setup-node@v4
with:
node-version-file: '.nvmrc'
cache: 'npm'
- name: Install xvfb for headless testing
run: sudo apt-get install xvfb
- name: Setup Max User Watches for Testing
run: echo fs.inotify.max_user_watches=524288 | sudo tee -a /etc/sysctl.conf && sudo sysctl -p
- name: Testing
run: |
npm run install:ci
xvfb-run --auto-servernum npm run test -- --ci --coverage
- name: Log Master Coverage
uses: actions/github-script@v7
id: coverage-master
with:
script: |
const script = require('./.github/SCRIPTS/exportCoverageFromMarkdownShields')
await script({github, context, core, exec}, './README.md')
- name: Log Current Coverage
uses: actions/github-script@v7
id: coverage-current
with:
script: |
const script = require('./.github/SCRIPTS/exportCoverageFromJsonSummary')
await script({github, context, core, exec}, './coverage/coverage.json')
- name: prepare coverage directory
run: |
mkdir _coverage
cp -rf ./coverage/coverage.xml ./coverage/coverage.json ./coverage/report-html/* ./_coverage/
rm -rf coverage/
mv _coverage coverage
- name: Compress coverage directory
run: tar -zcvf coverage-dir.tar.gz ./coverage/
- uses: actions/upload-artifact@v4
with:
name: coverage-folder
path: coverage-dir.tar.gz
# Publish the necessary npm new package versions
release:
name: Release
needs: [lint, typecheck, testing]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: actions/setup-node@v4
with:
node-version-file: '.nvmrc'
registry-url: 'https://registry.npmjs.org'
cache: 'npm'
- name: Comment Coverage
if: github.event_name == 'pull_request' && (github.event.action == 'opened' || github.event.action == 'synchronize')
uses: actions/github-script@v7
with:
script: |
const script = require('./.github/SCRIPTS/commentCoverage')
const needsObject = ${{ toJSON(needs) }}
await script(
{github, context, core, exec},
{
masterPCTStatements: needsObject.testing.outputs.coverage_statements_pct_master,
masterPCTBranches: needsObject.testing.outputs.coverage_branches_pct_master,
masterPCTFunctions: needsObject.testing.outputs.coverage_functions_pct_master,
masterPCTLines: needsObject.testing.outputs.coverage_lines_pct_master
},
{
currentPCTStatements: needsObject.testing.outputs.coverage_statements_pct_current,
currentPCTBranches: needsObject.testing.outputs.coverage_branches_pct_current,
currentPCTFunctions: needsObject.testing.outputs.coverage_functions_pct_current,
currentPCTLines: needsObject.testing.outputs.coverage_lines_pct_current,
currentTotalStatements: needsObject.testing.outputs.coverage_statements_total_current,
currentTotalBranches: needsObject.testing.outputs.coverage_branches_total_current,
currentTotalFunctions: needsObject.testing.outputs.coverage_functions_total_current,
currentTotalLines: needsObject.testing.outputs.coverage_lines_total_current,
currentCoveredStatements: needsObject.testing.outputs.coverage_statements_covered_current,
currentCoveredBranches: needsObject.testing.outputs.coverage_branches_covered_current,
currentCoveredFunctions: needsObject.testing.outputs.coverage_functions_covered_current,
currentCoveredLines: needsObject.testing.outputs.coverage_lines_covered_current
}
)
- name: Update Coverage Badges
if: github.event_name == 'push'
uses: actions/github-script@v7
with:
script: |
const script = require('./.github/SCRIPTS/updateCoverageBadges')
const needsObject = ${{ toJSON(needs) }}
await script(
{github, context, core, exec},
'./README.md',
{
currentPCTStatements: needsObject.testing.outputs.coverage_statements_pct_current,
currentPCTBranches: needsObject.testing.outputs.coverage_branches_pct_current,
currentPCTFunctions: needsObject.testing.outputs.coverage_functions_pct_current,
currentPCTLines: needsObject.testing.outputs.coverage_lines_pct_current
}
)
- name: Update README.md Coverage badges
uses: EndBug/add-and-commit@v7
if: github.event_name == 'push'
env:
GITHUB_USER: sui-bot
GITHUB_EMAIL: [email protected]
with:
add: 'README.md'
author_name: ${{ env.GITHUB_USER }}
author_email: ${{ env.GITHUB_EMAIL }}
message: 'chore(Root): Update coverage badges'
- name: Release components
if: github.event_name == 'push'
run: |
npm install @s-ui/mono@2 --no-audit --no-fund --legacy-peer-deps
npx @s-ui/ci release
env:
GITHUB_EMAIL: [email protected]
GITHUB_TOKEN: ${{github.token}}
GITHUB_USER: sui-bot
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
# Deploy artifact to Vercel
deploy:
name: Deploy
needs: [build, lint, testing]
runs-on: ubuntu-latest
environment:
name: ${{ github.event_name != 'pull_request' && 'Production' || 'Preview'}}
url: ${{ steps.deploy.outputs.url }}
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version-file: '.nvmrc'
cache: 'npm'
- uses: actions/download-artifact@v4
with:
name: public-folder
path: .
- uses: actions/download-artifact@v4
with:
name: coverage-folder
path: .
- name: Uncompress public directory
run: |
tar -zxvf ./public-dir.tar.gz
rm ./public-dir.tar.gz
- name: Uncompress coverage directory
run: |
tar -zxvf ./coverage-dir.tar.gz -C ./public/
rm ./coverage-dir.tar.gz
- name: Deploy
id: deploy
run: |
npm i -g vercel --no-save --no-fund --no-audit --no-scripts
DEPLOYMENT_URL=$(vercel deploy --token $VERCEL_TOKEN --yes $VERCEL_PARAMS)
echo "::set-output name=url::$(echo $DEPLOYMENT_URL)"
env:
VERCEL_PARAMS: ${{ github.event_name != 'pull_request' && '--prod' || ''}}
VERCEL_TOKEN: ${{ secrets.VERCEL_TOKEN }}
VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }}
VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }}