Skip to content

Commit fa5007f

Browse files
authored
Merge pull request #47 from MatrixAI/feature-benchmarking-refactor
Integrating continuous benchmarking from js-logger
2 parents 11342f3 + cd1ab84 commit fa5007f

24 files changed

+3973
-4300
lines changed

.gitlab-ci.yml

+97-72
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,6 @@ variables:
1313
npm_config_cache: "${CI_PROJECT_DIR}/tmp/npm"
1414
# Prefer offline node module installation
1515
npm_config_prefer_offline: "true"
16-
# `ts-node` has its own cache
17-
TS_CACHED_TRANSPILE_CACHE: "${CI_PROJECT_DIR}/tmp/ts-node-cache"
18-
TS_CACHED_TRANSPILE_PORTABLE: "true"
1916
# Homebrew cache only used by macos runner
2017
HOMEBREW_CACHE: "${CI_PROJECT_DIR}/tmp/Homebrew"
2118

@@ -33,7 +30,6 @@ cache:
3330
when: 'always'
3431
paths:
3532
- ./tmp/npm/
36-
- ./tmp/ts-node-cache/
3733
# Homebrew cache is only used by the macos runner
3834
- ./tmp/Homebrew
3935
# Chocolatey cache is only used by the windows runner
@@ -56,10 +52,11 @@ check:lint:
5652
needs: []
5753
script:
5854
- >
59-
nix-shell --run '
60-
npm run lint;
61-
npm run lint-native;
62-
'
55+
nix-shell --arg ci true --run $'
56+
npm run lint;
57+
npm run lint-native;
58+
npm run lint-shell;
59+
'
6360
rules:
6461
# Runs on feature and staging commits and ignores version commits
6562
- if: $CI_COMMIT_BRANCH =~ /^(?:feature.*|staging)$/ && $CI_COMMIT_TITLE !~ /^[0-9]+\.[0-9]+\.[0-9]+(?:-.*[0-9]+)?$/
@@ -74,10 +71,10 @@ check:test:
7471
needs: []
7572
script:
7673
- >
77-
nix-shell --run '
78-
npm run build --verbose;
79-
npm test -- --ci --coverage;
80-
'
74+
nix-shell --arg ci true --run $'
75+
npm run prebuild --verbose;
76+
npm test -- --ci --coverage;
77+
'
8178
artifacts:
8279
when: always
8380
reports:
@@ -88,7 +85,7 @@ check:test:
8885
path: ./tmp/coverage/cobertura-coverage.xml
8986
coverage: '/All files[^|]*\|[^|]*\s+([\d\.]+)/'
9087
rules:
91-
# Runs on staging commits and ignores version commits
88+
# Runs on feature commits and ignores version commits
9289
- if: $CI_COMMIT_BRANCH =~ /^feature.*$/ && $CI_COMMIT_TITLE !~ /^[0-9]+\.[0-9]+\.[0-9]+(?:-.*[0-9]+)?$/
9390
# Manually run on commits other than master and staging and ignore version commits
9491
- if: $CI_COMMIT_BRANCH && $CI_COMMIT_BRANCH !~ /^(?:master|staging)$/ && $CI_COMMIT_TITLE !~ /^[0-9]+\.[0-9]+\.[0-9]+(?:-.*[0-9]+)?$/
@@ -102,20 +99,38 @@ build:merge:
10299
# Required for `gh pr create`
103100
- git remote add upstream "$GH_PROJECT_URL"
104101
- >
105-
nix-shell -I nixpkgs=./pkgs.nix --packages gitAndTools.gh --run '
106-
gh pr create \
107-
--head staging \
108-
--base master \
109-
--title "ci: merge staging to master" \
110-
--body "This is an automatic PR generated by the pipeline CI/CD. This will be automatically fast-forward merged if successful." \
111-
--assignee "@me" \
112-
--no-maintainer-edit \
113-
--repo "$GH_PROJECT_PATH" || true;
114-
printf "Pipeline Attempt on ${CI_PIPELINE_ID} for ${CI_COMMIT_SHA}\n\n${CI_PIPELINE_URL}" \
115-
| gh pr comment staging \
116-
--body-file - \
117-
--repo "$GH_PROJECT_PATH";
118-
'
102+
nix-shell --arg ci true --run $'
103+
gh pr create \
104+
--head staging \
105+
--base master \
106+
--title "ci: merge staging to master" \
107+
--body "This is an automatic PR generated by the pipeline CI/CD. This will be automatically fast-forward merged if successful." \
108+
--assignee "@me" \
109+
--no-maintainer-edit \
110+
--repo "$GH_PROJECT_PATH" || true;
111+
printf "Pipeline Attempt on ${CI_PIPELINE_ID} for ${CI_COMMIT_SHA}\n\n${CI_PIPELINE_URL}" \
112+
| gh pr comment staging \
113+
--body-file - \
114+
--repo "$GH_PROJECT_PATH";
115+
'
116+
rules:
117+
# Runs on staging commits and ignores version commits
118+
- if: $CI_COMMIT_BRANCH == 'staging' && $CI_COMMIT_TITLE !~ /^[0-9]+\.[0-9]+\.[0-9]+(?:-.*[0-9]+)?$/
119+
# Runs on tag pipeline where the tag is a prerelease or release version
120+
- if: $CI_COMMIT_TAG =~ /^v[0-9]+\.[0-9]+\.[0-9]+(?:-.*[0-9]+)?$/
121+
122+
build:dist:
123+
stage: build
124+
needs: []
125+
script:
126+
- >
127+
nix-shell --arg ci true --run $'
128+
npm run build --ignore-scripts --verbose;
129+
'
130+
artifacts:
131+
when: always
132+
paths:
133+
- ./dist
119134
rules:
120135
# Runs on staging commits and ignores version commits
121136
- if: $CI_COMMIT_BRANCH == 'staging' && $CI_COMMIT_TITLE !~ /^[0-9]+\.[0-9]+\.[0-9]+(?:-.*[0-9]+)?$/
@@ -130,10 +145,11 @@ build:linux:
130145
npm_config_arch: "x64"
131146
script:
132147
- >
133-
nix-shell --run '
134-
npm run build --verbose;
135-
npm test -- --ci --coverage;
136-
'
148+
nix-shell --arg ci true --run $'
149+
npm run prebuild --verbose;
150+
npm test -- --ci --coverage;
151+
npm run bench;
152+
'
137153
artifacts:
138154
when: always
139155
reports:
@@ -142,10 +158,9 @@ build:linux:
142158
coverage_report:
143159
coverage_format: cobertura
144160
path: ./tmp/coverage/cobertura-coverage.xml
161+
metrics: ./benches/results/metrics.txt
145162
paths:
146163
- ./prebuilds/
147-
# Only the build:linux preserves the dist
148-
- ./dist
149164
coverage: '/All files[^|]*\|[^|]*\s+([\d\.]+)/'
150165
rules:
151166
# Runs on staging commits and ignores version commits
@@ -170,13 +185,18 @@ build:windows:
170185
- refreshenv
171186
- npm install --ignore-scripts
172187
- $env:Path = "$(npm bin);" + $env:Path
173-
- npm run build --verbose
174-
- npm test -- --ci
188+
- npm run prebuild --verbose
189+
- npm test -- --ci --coverage
190+
- npm run bench
175191
artifacts:
176192
when: always
177193
reports:
178194
junit:
179195
- ./tmp/junit/junit.xml
196+
coverage_report:
197+
coverage_format: cobertura
198+
path: ./tmp/coverage/cobertura-coverage.xml
199+
metrics: ./benches/results/metrics.txt
180200
paths:
181201
- ./prebuilds/
182202
rules:
@@ -202,13 +222,18 @@ build:macos:
202222
- hash -r
203223
- npm install --ignore-scripts
204224
- export PATH="$(npm bin):$PATH"
205-
- npm run build --verbose
206-
- npm test -- --ci
225+
- npm run prebuild --verbose
226+
- npm test -- --ci --coverage
227+
- npm run bench
207228
artifacts:
208229
when: always
209230
reports:
210231
junit:
211232
- ./tmp/junit/junit.xml
233+
coverage_report:
234+
coverage_format: cobertura
235+
path: ./tmp/coverage/cobertura-coverage.xml
236+
metrics: ./benches/results/metrics.txt
212237
paths:
213238
- ./prebuilds/
214239
rules:
@@ -220,19 +245,19 @@ build:macos:
220245
build:prerelease:
221246
stage: build
222247
needs:
248+
- build:dist
223249
- build:linux
224250
- build:windows
225251
- build:macos
226252
# Don't interrupt publishing job
227253
interruptible: false
228-
before_script:
229-
- echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" > ./.npmrc
230254
script:
255+
- echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" > ./.npmrc
231256
- echo 'Publishing library prerelease'
232257
- >
233-
nix-shell --run '
234-
npm publish --tag prerelease --access public;
235-
'
258+
nix-shell --arg ci true --run $'
259+
npm publish --tag prerelease --access public;
260+
'
236261
- >
237262
for d in prebuilds/*; do
238263
tar \
@@ -243,16 +268,16 @@ build:prerelease:
243268
"$(basename $d)";
244269
done
245270
- >
246-
nix-shell -I nixpkgs=./pkgs.nix --packages gitAndTools.gh --run '
247-
gh release \
248-
create "$CI_COMMIT_TAG" \
249-
prebuilds/*.tar \
250-
--title "${CI_COMMIT_TAG}-$(date -u +"%Y-%m-%dT%H:%M:%SZ")" \
251-
--notes "" \
252-
--prerelease \
253-
--target staging \
254-
--repo "$GH_PROJECT_PATH";
255-
'
271+
nix-shell --arg ci true --run $'
272+
gh release \
273+
create "$CI_COMMIT_TAG" \
274+
prebuilds/*.tar \
275+
--title "${CI_COMMIT_TAG}-$(date -u +"%Y-%m-%dT%H:%M:%SZ")" \
276+
--notes "" \
277+
--prerelease \
278+
--target staging \
279+
--repo "$GH_PROJECT_PATH";
280+
'
256281
after_script:
257282
- rm -f ./.npmrc
258283
rules:
@@ -282,12 +307,12 @@ integration:merge:
282307
GIT_DEPTH: 0
283308
script:
284309
- >
285-
nix-shell -I nixpkgs=./pkgs.nix --packages gitAndTools.gh --run '
286-
printf "Pipeline Succeeded on ${CI_PIPELINE_ID} for ${CI_COMMIT_SHA}\n\n${CI_PIPELINE_URL}" \
287-
| gh pr comment staging \
288-
--body-file - \
289-
--repo "$GH_PROJECT_PATH";
290-
'
310+
nix-shell --arg ci true --run $'
311+
printf "Pipeline Succeeded on ${CI_PIPELINE_ID} for ${CI_COMMIT_SHA}\n\n${CI_PIPELINE_URL}" \
312+
| gh pr comment staging \
313+
--body-file - \
314+
--repo "$GH_PROJECT_PATH";
315+
'
291316
- git remote add upstream "$GH_PROJECT_URL"
292317
- git checkout origin/master
293318
# Merge up to the current commit (not the latest commit)
@@ -302,20 +327,20 @@ integration:merge:
302327
release:distribution:
303328
stage: release
304329
needs:
330+
- build:dist
305331
- build:linux
306332
- build:windows
307333
- build:macos
308334
- integration:merge
309335
# Don't interrupt publishing job
310336
interruptible: false
311-
before_script:
312-
- echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" > ./.npmrc
313337
script:
338+
- echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" > ./.npmrc
314339
- echo 'Publishing library'
315340
- >
316-
nix-shell --run '
317-
npm publish --access public;
318-
'
341+
nix-shell --arg ci true --run $'
342+
npm publish --access public;
343+
'
319344
- >
320345
for d in prebuilds/*; do
321346
tar \
@@ -326,15 +351,15 @@ release:distribution:
326351
"$(basename $d)";
327352
done
328353
- >
329-
nix-shell -I nixpkgs=./pkgs.nix --packages gitAndTools.gh --run '
330-
gh release \
331-
create "$CI_COMMIT_TAG" \
332-
prebuilds/*.tar \
333-
--title "${CI_COMMIT_TAG}-$(date -u +"%Y-%m-%dT%H:%M:%SZ")" \
334-
--notes "" \
335-
--target master \
336-
--repo "$GH_PROJECT_PATH";
337-
'
354+
nix-shell --arg ci true --run $'
355+
gh release \
356+
create "$CI_COMMIT_TAG" \
357+
prebuilds/*.tar \
358+
--title "${CI_COMMIT_TAG}-$(date -u +"%Y-%m-%dT%H:%M:%SZ")" \
359+
--notes "" \
360+
--target master \
361+
--repo "$GH_PROJECT_PATH";
362+
'
338363
after_script:
339364
- rm -f ./.npmrc
340365
rules:

README.md

+20
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,26 @@ See the docs at: https://matrixai.github.io/js-db/
112112

113113
### Publishing
114114

115+
Publishing is handled automatically by the staging pipeline.
116+
117+
Prerelease:
118+
119+
```sh
120+
# npm login
121+
npm version prepatch --preid alpha # premajor/preminor/prepatch
122+
git push --follow-tags
123+
```
124+
125+
Release:
126+
127+
```sh
128+
# npm login
129+
npm version patch # major/minor/patch
130+
git push --follow-tags
131+
```
132+
133+
Manually:
134+
115135
```sh
116136
# npm login
117137
npm version patch # major/minor/patch

benches/DB1KiB.ts renamed to benches/db_1KiB.ts

+5-17
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import os from 'os';
2-
import crypto from 'crypto';
3-
import path from 'path';
42
import fs from 'fs';
3+
import path from 'path';
4+
import crypto from 'crypto';
55
import b from 'benny';
66
import Logger, { LogLevel, StreamHandler } from '@matrixai/logger';
77
import DB from '@/DB';
8-
import packageJson from '../package.json';
8+
import { suiteCommon } from './utils';
99

1010
const logger = new Logger('DB1KiB Bench', LogLevel.WARN, [new StreamHandler()]);
1111

@@ -18,7 +18,7 @@ async function main() {
1818
const data0 = crypto.randomBytes(0);
1919
const data1KiB = crypto.randomBytes(1024);
2020
const summary = await b.suite(
21-
'DB1KiB',
21+
path.basename(__filename, path.extname(__filename)),
2222
b.add('get 1 KiB of data', async () => {
2323
await db.put('1kib', data1KiB, true);
2424
return async () => {
@@ -35,19 +35,7 @@ async function main() {
3535
await db.put('0', data0, true);
3636
await db.del('0');
3737
}),
38-
b.cycle(),
39-
b.complete(),
40-
b.save({
41-
file: 'DB1KiB',
42-
folder: 'benches/results',
43-
version: packageJson.version,
44-
details: true,
45-
}),
46-
b.save({
47-
file: 'DB1KiB',
48-
folder: 'benches/results',
49-
format: 'chart.html',
50-
}),
38+
...suiteCommon,
5139
);
5240
await db.stop();
5341
await fs.promises.rm(dataDir, {

0 commit comments

Comments
 (0)