-
Notifications
You must be signed in to change notification settings - Fork 23
283 lines (239 loc) · 9.7 KB
/
build.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
name: build
on:
push:
branches:
- master
- /^\d+\.\d+\.x$/
tags:
- "*"
pull_request:
branches:
- master
- /^\d+\.\d+\.x$/
env:
TZ: "Europe/Brussels"
MAIN_NODEJS: "18"
NPM_VERSION: "10.1.0"
LOGS_DIR: /tmp/stark/logs
LOGS_FILE: /tmp/stark/logs/build-perf.log
HUSKY: 0
jobs:
build-and-test:
name: Build and test on Node.js ${{ matrix.node_version }} and ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
matrix:
node_version: ["18", "20"]
os: [ubuntu-latest]
steps:
# Some actions should be executed only in one environment.
# This variable determines if it is the main environment, it means the same than the one we have internally.
- name: Set environment variable 'IS_MAIN_ENVIRONMENT'
run: |
if [[ '${{ matrix.node_version }}' == '${{ env.MAIN_NODEJS }}' ]] && [[ '${{ matrix.os }}' == 'ubuntu-latest' ]]; then
echo "IS_MAIN_ENVIRONMENT=1" >> $GITHUB_ENV
else
echo "IS_MAIN_ENVIRONMENT=0" >> $GITHUB_ENV
fi
# See: https://github.com/marketplace/actions/checkout
- uses: actions/checkout@v4
with:
fetch-depth: |
if [[ '${{ github.event_name != 'pull_request' }}' ]]; then
1
else
git rev-list --count ${{ github.event.pull_request.base.sha }}..HEAD
fi
# See: https://github.com/marketplace/actions/setup-node-js-environment
- name: Use Node.js ${{ matrix.node_version }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node_version }}
# See: https://github.com/marketplace/actions/cache
# See doc: https://docs.github.com/en/actions/guides/caching-dependencies-to-speed-up-workflows
- name: Cache node modules
uses: actions/cache@v4
env:
cache-name: cache-node-modules-${{ matrix.node_version }}-${{ matrix.os }}
with:
# npm cache files are stored in `~/.npm` on Linux
path: ~/.npm
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-build-${{ env.cache-name }}-
${{ runner.os }}-build-
${{ runner.os }}-
- name: Install npm ${{ env.NPM_VERSION }}
run: npm i -g npm@${{ env.NPM_VERSION }}
- name: Get tag name if exists
run: |
TAG_NAME=$(echo $GITHUB_REF | sed -n "s/^refs\/tags\/\(\S*\).*$/\1/p")
echo "GH_ACTIONS_TAG=${TAG_NAME}" >> $GITHUB_ENV
- name: List main variables
run: |
echo "Commit SHA : ${GITHUB_SHA}"
echo "Tag name : ${{ env.GH_ACTIONS_TAG }}"
echo "Reference : ${GITHUB_REF}"
echo "Head branch : ${GITHUB_HEAD_REF}"
echo "Base branch : ${GITHUB_BASE_REF}"
echo "Build number: ${GITHUB_RUN_NUMBER}"
echo "Repository : ${GITHUB_REPOSITORY}"
echo "Event : ${GITHUB_EVENT_NAME}"
echo "Author : ${GITHUB_ACTOR}"
echo "Main ENV : ${{ env.IS_MAIN_ENVIRONMENT }}"
NODE_VERSION="$(node -v)"
echo "Node version: $NODE_VERSION"
# This ensures that we are authenticated without requiring to have an actual .npmrc file within the project
# echo "//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}" >> ~/.npmrc
- name: Check if dependencies are in sync between root and packages
run: "npm run check:packages-dependencies"
- name: Create file & folder for GitHub Actions logs
run: |
# cfr scripts/_ghactions-group.sh
mkdir -p ${{ env.LOGS_DIR }}
touch ${{ env.LOGS_FILE }}
- name: Install dependencies
run: npm ci
- name: Prettier check
run: |
npx prettier $(git diff-tree --no-commit-id --name-only --stat --diff-filter=ACM -r ${{ github.event.pull_request.base.sha }} HEAD) --check
if: github.event_name == 'pull_request'
- name: Build packages
run: npm run build:trace
- name: Linting packages
run: npm run lint:packages
- name: Testing packages
run: npm run test:ci:packages
# See: https://github.com/marketplace/actions/upload-a-build-artifact
- name: Upload stark packages-dist folder
uses: actions/upload-artifact@v3
with:
name: stark-dist
path: dist/packages-dist
if: env.IS_MAIN_ENVIRONMENT == 1
- name: Generate docs coverage
run: npm run docs:coverage:packages
if: env.IS_MAIN_ENVIRONMENT == 1
- name: Combine coveralls reports
run: node combine-packages-coverage.js
if: env.IS_MAIN_ENVIRONMENT == 1
- name: Coveralls
uses: coverallsapp/github-action@master
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
path-to-lcov: "combined-lcov.info"
if: env.IS_MAIN_ENVIRONMENT == 1
- name: Clean root node_modules
run: rm -rf ./node_modules
- name: Install starter
run: npm i
working-directory: starter
- name: "Install showcase with install command"
if: github.actor == 'nbb-bot' && startsWith(github.ref_head, 'dependabot/npm_and_yarn')
run: |
rm package-lock.json
npm install
working-directory: showcase
- name: "Install showcase with ci command"
if: github.actor != 'nbb-bot' || !startsWith(github.ref_head, 'dependabot/npm_and_yarn')
run: npm ci
working-directory: showcase
- name: Linting showcase & starter
run: |
npm run lint:showcase
npm run lint:starter
- name: Testing showcase & starter
run: |
npm run test:ci:showcase
npm run test:ci:starter
- name: "Build showcase:ghpages"
run: npm run build:showcase:ghpages
# See: https://github.com/marketplace/actions/upload-a-build-artifact
- name: Upload showcase dist folder
uses: actions/upload-artifact@v3
with:
name: showcase-dist
path: showcase/dist
if: env.IS_MAIN_ENVIRONMENT == 1
# - name: BrowserStack Env Setup
# uses: browserstack/github-actions/setup-env@master
# with:
# username: ${{ secrets.BROWSERSTACK_USERNAME }}
# access-key: ${{ secrets.BROWSERSTACK_ACCESS_KEY }}
# project-name: "Stark Showcase"
# if: env.IS_MAIN_ENVIRONMENT == 1 && github.event_name == 'push'
#
# - name: BrowserStack Local Tunnel Setup
# uses: browserstack/github-actions/setup-local@master
# with:
# local-testing: "start"
# local-logging-level: "all-logs"
# local-identifier: "github-actions-${{ github.run_number }}"
# if: env.IS_MAIN_ENVIRONMENT == 1 && github.event_name == 'push'
#
# - name: Running application under test
# run: npm run server:prod:ci &
# if: env.IS_MAIN_ENVIRONMENT == 1 && github.event_name == 'push'
# working-directory: showcase
#
# - name: Running test on BrowserStack
# run: npm run protractor:browserstack
# if: env.IS_MAIN_ENVIRONMENT == 1 && github.event_name == 'push'
# working-directory: showcase
#
# - name: BrowserStackLocal Stop
# uses: browserstack/github-actions/setup-local@master
# with:
# local-testing: stop
# if: env.IS_MAIN_ENVIRONMENT == 1 && github.event_name == 'push'
- name: Generate starter docs coverage
run: npm run docs:starter:coverage
if: env.IS_MAIN_ENVIRONMENT == 1
- name: Save logs
run: bash ./scripts/ci/print-logs.sh
release:
name: Release
runs-on: "ubuntu-latest"
needs: build-and-test
if: (startsWith(github.ref, 'refs/tags/') || github.event_name == 'schedule') && github.repository == 'NationalBankBelgium/stark'
steps:
- name: Get tag name if exists
run: |
TAG_NAME=$(echo $GITHUB_REF | sed -n "s/^refs\/tags\/\(\S*\).*$/\1/p")
echo "GH_ACTIONS_TAG=${TAG_NAME}" >> $GITHUB_ENV
# See: https://github.com/marketplace/actions/checkout
- uses: actions/checkout@v4
# See: https://github.com/marketplace/actions/setup-node-js-environment
- name: Use Node.js ${{ env.MAIN_NODEJS }}
uses: actions/setup-node@v4
with:
node-version: ${{ env.MAIN_NODEJS }}
- name: Install npm ${{ env.NPM_VERSION }}
run: npm i -g npm@${{ env.NPM_VERSION }}
- name: Create file & folder for GitHub Actions logs
run: |
# cfr scripts/_ghactions-group.sh
mkdir -p ${{ env.LOGS_DIR }}
touch ${{ env.LOGS_FILE }}
# See: https://github.com/marketplace/actions/download-a-build-artifact
- uses: actions/download-artifact@v3
with:
name: stark-dist
path: dist/packages-dist
# See: https://github.com/marketplace/actions/download-a-build-artifact
- uses: actions/download-artifact@v3
with:
name: showcase-dist
path: showcase/dist
- name: Install Stark dependencies
run: npm ci
if: github.event_name != 'schedule'
- name: Generate docs
run: npm run docs:publish -- --github-api-key=${{ secrets.GITHUB_TOKEN }}
if: github.event_name != 'schedule'
- name: Set npm token
run: echo "//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}" >> ~/.npmrc
- name: Release stark
run: npm run release:publish
- name: Save logs
run: bash ./scripts/ci/print-logs.sh