-
Notifications
You must be signed in to change notification settings - Fork 3.6k
238 lines (232 loc) · 9.05 KB
/
ci-cd.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
name: CI/CD
on:
workflow_dispatch:
push:
concurrency:
group: "${{ github.workflow }} @ ${{ github.head_ref || github.ref }}"
cancel-in-progress: true
permissions:
contents: write # publish a GitHub release
pages: write # deploy to GitHub Pages
issues: write # comment on released issues
pull-requests: write # comment on released pull requests
jobs:
setup:
runs-on: ubuntu-latest
env:
DETECT_CHROMEDRIVER_VERSION: "true"
JEST_JUNIT_OUTPUT_DIR: test-results
NODE_OPTIONS: --max-old-space-size=4000
steps:
- uses: actions/checkout@v4
- uses: wagoid/commitlint-github-action@v5
if: github.ref_name == 'develop'
- uses: actions/setup-node@v3
with:
cache: "npm"
node-version-file: ".nvmrc"
- name: Info
run: |
cat <<EOF
Node version: $(node --version)
NPM version: $(npm --version)
GitHub ref: ${{ github.ref }}
GitHub head ref: ${{ github.head_ref }}
EOF
- name: Install Dependencies
run: npm ci
- name: Lint
run: |
npm run test:lint -- --quiet --output-file test-results/eslint/results.xml --format junit
- name: Store Lint Results
uses: actions/upload-artifact@v3
with:
name: lint-output
path: ./test-results/*
- name: Cache node_modules
id: cache-nodemodules
uses: actions/cache@v3
with:
path:
node_modules
key: ${{ runner.os }}-node-${{ hashFiles('package-lock.json') }}
- name: Cache src/generated
id: cache-generated
uses: actions/cache@v3
with:
path:
src/generated
key: ${{ runner.os }}-generated-${{ hashFiles('package-lock.json') }}
- name: Cache static/microbit
id: cache-static
uses: actions/cache@v3
with:
path:
static/microbit
key: ${{ runner.os }}-microbit-${{ hashFiles('package-lock.json') }}
test-unit:
needs: setup
runs-on: ubuntu-latest
env:
JEST_JUNIT_OUTPUT_NAME: unit-results.xml
JEST_JUNIT_OUTPUT_DIR: test-results/unit
steps:
- uses: actions/checkout@v4
- name: Cache NPM dependencies
uses: actions/cache@v3
with:
path:
node_modules
key: ${{ runner.os }}-node-${{ hashFiles('package-lock.json') }}
- name: Run Unit Tests
run: npm run test:unit -- --reporters="default" --reporters="jest-junit" --coverage --coverageReporters=text --coverageReporters=lcov --maxWorkers="2"
- name: Store Unit Test Results
uses: actions/upload-artifact@v3
with:
name: unit-test-output
path: ./test-results/*
build:
needs: [setup, test-unit]
env:
NODE_OPTIONS: --max-old-space-size=4000
DETECT_CHROMEDRIVER_VERSION: "true"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v3
with:
cache: "npm"
node-version-file: ".nvmrc"
- name: Retrieve node_modules
uses: actions/cache@v3
with:
path:
node_modules
key: ${{ runner.os }}-node-${{ hashFiles('package-lock.json') }}
- name: Retrieve src/generated
uses: actions/cache@v3
with:
path:
src/generated
key: ${{ runner.os }}-generated-${{ hashFiles('package-lock.json') }}
- name: Retireve static/microbit
uses: actions/cache@v3
with:
path:
static/microbit
key: ${{ runner.os }}-microbit-${{ hashFiles('package-lock.json') }}
- name: Run Build
env:
NODE_ENV: production
run: npm run build
- name: Cache Build Directory
uses: actions/cache@v3
with:
path:
./build
key: ${{ runner.os }}-build-${{ hashFiles('package-lock.json') }}
- name: Cache Dist Directory
uses: actions/cache@v3
with:
path:
./dist
key: ${{ runner.os }}-dist-${{ hashFiles('package-lock.json') }}
- name: Store Build Output
uses: actions/upload-artifact@v3
with:
name: build-output
path: ./build
- name: Store Dist Output
uses: actions/upload-artifact@v3
with:
name: dist-output
path: ./dist
test-integration:
needs: build
runs-on: ubuntu-latest
env:
JEST_JUNIT_OUTPUT_NAME: results.txt
JEST_JUNIT_OUTPUT_DIR: test-results/integration
steps:
- uses: actions/checkout@v4
- name: Install Chrome Dependencies
run: |
sudo apt-get update
sudo apt-get install -y libgconf-2-4 libatk1.0-0 libatk-bridge2.0-0 libgdk-pixbuf2.0-0 libgtk-3-0 libgbm-dev libnss3-dev libxss-dev libasound2
- name: Retrieve npm dependencies
uses: actions/cache@v3
with:
path:
node_modules
key: ${{ runner.os }}-node-${{ hashFiles('package-lock.json') }}
- name: Retrieve Build
uses: actions/cache@v3
with:
path:
./build
key: ${{ runner.os }}-build-${{ hashFiles('package-lock.json') }}
- uses: browser-actions/setup-chrome@v1
with:
chrome-version: stable
id: setup-chrome
- run: |
echo Installed chromium version: ${{ steps.setup-chrome.outputs.chrome-version }}
${{ steps.setup-chrome.outputs.chrome-path }} --version
- name: Run Integration Tests
run: npm run test:integration -- --reporters="default" --reporters="jest-junit"
- name: Store Integration Test Results
uses: actions/upload-artifact@v3
with:
name: integration-test-output
path: ./test-results/*
deploy-npm:
needs: [test-integration, test-unit]
if: ${{ startsWith(github.ref, 'refs/heads/master') || startsWith(github.ref, 'refs/heads/hotfix') || startsWith(github.ref, 'refs/heads/beta') }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Retrieve npm dependencies
uses: actions/cache@v3
with:
path:
node_modules
key: ${{ runner.os }}-node-${{ hashFiles('package-lock.json') }}
- name: Retrieve Dist Directory
uses: actions/cache@v3
with:
path:
./dist
key: ${{ runner.os }}-dist-${{ hashFiles('package-lock.json') }}
- run: |
if [[ ${{contains(github.ref, 'hotfix')}} ]]; then
sed -e "s|hotfix/REPLACE|${{ github.ref_name }}|" --in-place release.config.js
fi
- name: Semantic Release
env:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: npx --no -- semantic-release
deploy-gh-pages:
needs: [test-integration, test-unit]
if: ${{ startsWith(github.ref, 'refs/heads/master') || startsWith(github.ref, 'refs/heads/hotfix') || startsWith(github.ref, 'refs/heads/beta') }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Retrieve npm dependencies
uses: actions/cache@v3
with:
path:
node_modules
key: ${{ runner.os }}-node-${{ hashFiles('package-lock.json') }}
- name: Retrieve Build Directory
uses: actions/cache@v3
with:
path:
./build
key: ${{ runner.os }}-build-${{ hashFiles('package-lock.json') }}
- name: Deploy playground to GitHub Pages
uses: peaceiris/actions-gh-pages@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./build
full_commit_message: "Build for ${{ github.sha }} ${{ github.event.head_commit.message }}"