Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integrating continuous benchmarking from js-logger #47

Merged
merged 4 commits into from
Jul 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
169 changes: 97 additions & 72 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@ variables:
npm_config_cache: "${CI_PROJECT_DIR}/tmp/npm"
# Prefer offline node module installation
npm_config_prefer_offline: "true"
# `ts-node` has its own cache
TS_CACHED_TRANSPILE_CACHE: "${CI_PROJECT_DIR}/tmp/ts-node-cache"
TS_CACHED_TRANSPILE_PORTABLE: "true"
# Homebrew cache only used by macos runner
HOMEBREW_CACHE: "${CI_PROJECT_DIR}/tmp/Homebrew"

Expand All @@ -33,7 +30,6 @@ cache:
when: 'always'
paths:
- ./tmp/npm/
- ./tmp/ts-node-cache/
# Homebrew cache is only used by the macos runner
- ./tmp/Homebrew
# Chocolatey cache is only used by the windows runner
Expand All @@ -56,10 +52,11 @@ check:lint:
needs: []
script:
- >
nix-shell --run '
npm run lint;
npm run lint-native;
'
nix-shell --arg ci true --run $'
npm run lint;
npm run lint-native;
npm run lint-shell;
'
rules:
# Runs on feature and staging commits and ignores version commits
- if: $CI_COMMIT_BRANCH =~ /^(?:feature.*|staging)$/ && $CI_COMMIT_TITLE !~ /^[0-9]+\.[0-9]+\.[0-9]+(?:-.*[0-9]+)?$/
Expand All @@ -74,10 +71,10 @@ check:test:
needs: []
script:
- >
nix-shell --run '
npm run build --verbose;
npm test -- --ci --coverage;
'
nix-shell --arg ci true --run $'
npm run prebuild --verbose;
npm test -- --ci --coverage;
'
artifacts:
when: always
reports:
Expand All @@ -88,7 +85,7 @@ check:test:
path: ./tmp/coverage/cobertura-coverage.xml
coverage: '/All files[^|]*\|[^|]*\s+([\d\.]+)/'
rules:
# Runs on staging commits and ignores version commits
# Runs on feature commits and ignores version commits
- if: $CI_COMMIT_BRANCH =~ /^feature.*$/ && $CI_COMMIT_TITLE !~ /^[0-9]+\.[0-9]+\.[0-9]+(?:-.*[0-9]+)?$/
# Manually run on commits other than master and staging and ignore version commits
- if: $CI_COMMIT_BRANCH && $CI_COMMIT_BRANCH !~ /^(?:master|staging)$/ && $CI_COMMIT_TITLE !~ /^[0-9]+\.[0-9]+\.[0-9]+(?:-.*[0-9]+)?$/
Expand All @@ -102,20 +99,38 @@ build:merge:
# Required for `gh pr create`
- git remote add upstream "$GH_PROJECT_URL"
- >
nix-shell -I nixpkgs=./pkgs.nix --packages gitAndTools.gh --run '
gh pr create \
--head staging \
--base master \
--title "ci: merge staging to master" \
--body "This is an automatic PR generated by the pipeline CI/CD. This will be automatically fast-forward merged if successful." \
--assignee "@me" \
--no-maintainer-edit \
--repo "$GH_PROJECT_PATH" || true;
printf "Pipeline Attempt on ${CI_PIPELINE_ID} for ${CI_COMMIT_SHA}\n\n${CI_PIPELINE_URL}" \
| gh pr comment staging \
--body-file - \
--repo "$GH_PROJECT_PATH";
'
nix-shell --arg ci true --run $'
gh pr create \
--head staging \
--base master \
--title "ci: merge staging to master" \
--body "This is an automatic PR generated by the pipeline CI/CD. This will be automatically fast-forward merged if successful." \
--assignee "@me" \
--no-maintainer-edit \
--repo "$GH_PROJECT_PATH" || true;
printf "Pipeline Attempt on ${CI_PIPELINE_ID} for ${CI_COMMIT_SHA}\n\n${CI_PIPELINE_URL}" \
| gh pr comment staging \
--body-file - \
--repo "$GH_PROJECT_PATH";
'
rules:
# Runs on staging commits and ignores version commits
- if: $CI_COMMIT_BRANCH == 'staging' && $CI_COMMIT_TITLE !~ /^[0-9]+\.[0-9]+\.[0-9]+(?:-.*[0-9]+)?$/
# Runs on tag pipeline where the tag is a prerelease or release version
- if: $CI_COMMIT_TAG =~ /^v[0-9]+\.[0-9]+\.[0-9]+(?:-.*[0-9]+)?$/

build:dist:
stage: build
needs: []
script:
- >
nix-shell --arg ci true --run $'
npm run build --ignore-scripts --verbose;
'
artifacts:
when: always
paths:
- ./dist
rules:
# Runs on staging commits and ignores version commits
- if: $CI_COMMIT_BRANCH == 'staging' && $CI_COMMIT_TITLE !~ /^[0-9]+\.[0-9]+\.[0-9]+(?:-.*[0-9]+)?$/
Expand All @@ -130,10 +145,11 @@ build:linux:
npm_config_arch: "x64"
script:
- >
nix-shell --run '
npm run build --verbose;
npm test -- --ci --coverage;
'
nix-shell --arg ci true --run $'
npm run prebuild --verbose;
npm test -- --ci --coverage;
npm run bench;
'
artifacts:
when: always
reports:
Expand All @@ -142,10 +158,9 @@ build:linux:
coverage_report:
coverage_format: cobertura
path: ./tmp/coverage/cobertura-coverage.xml
metrics: ./benches/results/metrics.txt
paths:
- ./prebuilds/
# Only the build:linux preserves the dist
- ./dist
coverage: '/All files[^|]*\|[^|]*\s+([\d\.]+)/'
rules:
# Runs on staging commits and ignores version commits
Expand All @@ -170,13 +185,18 @@ build:windows:
- refreshenv
- npm install --ignore-scripts
- $env:Path = "$(npm bin);" + $env:Path
- npm run build --verbose
- npm test -- --ci
- npm run prebuild --verbose
- npm test -- --ci --coverage
- npm run bench
artifacts:
when: always
reports:
junit:
- ./tmp/junit/junit.xml
coverage_report:
coverage_format: cobertura
path: ./tmp/coverage/cobertura-coverage.xml
metrics: ./benches/results/metrics.txt
paths:
- ./prebuilds/
rules:
Expand All @@ -202,13 +222,18 @@ build:macos:
- hash -r
- npm install --ignore-scripts
- export PATH="$(npm bin):$PATH"
- npm run build --verbose
- npm test -- --ci
- npm run prebuild --verbose
- npm test -- --ci --coverage
- npm run bench
artifacts:
when: always
reports:
junit:
- ./tmp/junit/junit.xml
coverage_report:
coverage_format: cobertura
path: ./tmp/coverage/cobertura-coverage.xml
metrics: ./benches/results/metrics.txt
paths:
- ./prebuilds/
rules:
Expand All @@ -220,19 +245,19 @@ build:macos:
build:prerelease:
stage: build
needs:
- build:dist
- build:linux
- build:windows
- build:macos
# Don't interrupt publishing job
interruptible: false
before_script:
- echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" > ./.npmrc
script:
- echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" > ./.npmrc
- echo 'Publishing library prerelease'
- >
nix-shell --run '
npm publish --tag prerelease --access public;
'
nix-shell --arg ci true --run $'
npm publish --tag prerelease --access public;
'
- >
for d in prebuilds/*; do
tar \
Expand All @@ -243,16 +268,16 @@ build:prerelease:
"$(basename $d)";
done
- >
nix-shell -I nixpkgs=./pkgs.nix --packages gitAndTools.gh --run '
gh release \
create "$CI_COMMIT_TAG" \
prebuilds/*.tar \
--title "${CI_COMMIT_TAG}-$(date -u +"%Y-%m-%dT%H:%M:%SZ")" \
--notes "" \
--prerelease \
--target staging \
--repo "$GH_PROJECT_PATH";
'
nix-shell --arg ci true --run $'
gh release \
create "$CI_COMMIT_TAG" \
prebuilds/*.tar \
--title "${CI_COMMIT_TAG}-$(date -u +"%Y-%m-%dT%H:%M:%SZ")" \
--notes "" \
--prerelease \
--target staging \
--repo "$GH_PROJECT_PATH";
'
after_script:
- rm -f ./.npmrc
rules:
Expand Down Expand Up @@ -282,12 +307,12 @@ integration:merge:
GIT_DEPTH: 0
script:
- >
nix-shell -I nixpkgs=./pkgs.nix --packages gitAndTools.gh --run '
printf "Pipeline Succeeded on ${CI_PIPELINE_ID} for ${CI_COMMIT_SHA}\n\n${CI_PIPELINE_URL}" \
| gh pr comment staging \
--body-file - \
--repo "$GH_PROJECT_PATH";
'
nix-shell --arg ci true --run $'
printf "Pipeline Succeeded on ${CI_PIPELINE_ID} for ${CI_COMMIT_SHA}\n\n${CI_PIPELINE_URL}" \
| gh pr comment staging \
--body-file - \
--repo "$GH_PROJECT_PATH";
'
- git remote add upstream "$GH_PROJECT_URL"
- git checkout origin/master
# Merge up to the current commit (not the latest commit)
Expand All @@ -302,20 +327,20 @@ integration:merge:
release:distribution:
stage: release
needs:
- build:dist
- build:linux
- build:windows
- build:macos
- integration:merge
# Don't interrupt publishing job
interruptible: false
before_script:
- echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" > ./.npmrc
script:
- echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" > ./.npmrc
- echo 'Publishing library'
- >
nix-shell --run '
npm publish --access public;
'
nix-shell --arg ci true --run $'
npm publish --access public;
'
- >
for d in prebuilds/*; do
tar \
Expand All @@ -326,15 +351,15 @@ release:distribution:
"$(basename $d)";
done
- >
nix-shell -I nixpkgs=./pkgs.nix --packages gitAndTools.gh --run '
gh release \
create "$CI_COMMIT_TAG" \
prebuilds/*.tar \
--title "${CI_COMMIT_TAG}-$(date -u +"%Y-%m-%dT%H:%M:%SZ")" \
--notes "" \
--target master \
--repo "$GH_PROJECT_PATH";
'
nix-shell --arg ci true --run $'
gh release \
create "$CI_COMMIT_TAG" \
prebuilds/*.tar \
--title "${CI_COMMIT_TAG}-$(date -u +"%Y-%m-%dT%H:%M:%SZ")" \
--notes "" \
--target master \
--repo "$GH_PROJECT_PATH";
'
after_script:
- rm -f ./.npmrc
rules:
Expand Down
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,26 @@ See the docs at: https://matrixai.github.io/js-db/

### Publishing

Publishing is handled automatically by the staging pipeline.

Prerelease:

```sh
# npm login
npm version prepatch --preid alpha # premajor/preminor/prepatch
git push --follow-tags
```

Release:

```sh
# npm login
npm version patch # major/minor/patch
git push --follow-tags
```

Manually:

```sh
# npm login
npm version patch # major/minor/patch
Expand Down
22 changes: 5 additions & 17 deletions benches/DB1KiB.ts → benches/db_1KiB.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import os from 'os';
import crypto from 'crypto';
import path from 'path';
import fs from 'fs';
import path from 'path';
import crypto from 'crypto';
import b from 'benny';
import Logger, { LogLevel, StreamHandler } from '@matrixai/logger';
import DB from '@/DB';
import packageJson from '../package.json';
import { suiteCommon } from './utils';

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

Expand All @@ -18,7 +18,7 @@ async function main() {
const data0 = crypto.randomBytes(0);
const data1KiB = crypto.randomBytes(1024);
const summary = await b.suite(
'DB1KiB',
path.basename(__filename, path.extname(__filename)),
b.add('get 1 KiB of data', async () => {
await db.put('1kib', data1KiB, true);
return async () => {
Expand All @@ -35,19 +35,7 @@ async function main() {
await db.put('0', data0, true);
await db.del('0');
}),
b.cycle(),
b.complete(),
b.save({
file: 'DB1KiB',
folder: 'benches/results',
version: packageJson.version,
details: true,
}),
b.save({
file: 'DB1KiB',
folder: 'benches/results',
format: 'chart.html',
}),
...suiteCommon,
);
await db.stop();
await fs.promises.rm(dataDir, {
Expand Down
Loading