Skip to content
This repository was archived by the owner on Nov 23, 2019. It is now read-only.

Commit 4e3116f

Browse files
authored
build: update tooling (#57)
This updates a variety of tooling we use to build and releaase the library, such as: * Update to circle ci v2 as v1 is deprecated * Use commitlint and commitizen to maintain clean commit history * Update Karma configuration so we can use it with codecov to report coverage (see segmentio/analytics.js-core#75 for notes on implementation) * Use np to simplify the releasing process
1 parent 35b24a7 commit 4e3116f

File tree

10 files changed

+9246
-9772
lines changed

10 files changed

+9246
-9772
lines changed

.circleci/config.yml

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
defaults: &defaults
2+
working_directory: ~/analytics.js-core
3+
docker:
4+
- image: circleci/node:8-browsers
5+
6+
version: 2
7+
jobs:
8+
test:
9+
<<: *defaults
10+
steps:
11+
- checkout
12+
- run: npm config set "//registry.npmjs.org/:_authToken" $NPM_AUTH
13+
- restore_cache:
14+
key: yarn-dependency-cache-{{ checksum "yarn.lock" }}
15+
- run: yarn install --frozen-lockfile
16+
- save_cache:
17+
key: yarn-dependency-cache-{{ checksum "yarn.lock" }}
18+
paths:
19+
- node_modules
20+
- run: yarn commitlint-circle
21+
- run: make test
22+
- store_test_results:
23+
path: junit-reports
24+
coverage:
25+
<<: *defaults
26+
steps:
27+
- checkout
28+
- run: npm config set "//registry.npmjs.org/:_authToken" $NPM_AUTH
29+
- restore_cache:
30+
key: yarn-dependency-cache-{{ checksum "yarn.lock" }}
31+
- run: yarn install --frozen-lockfile
32+
- save_cache:
33+
key: yarn-dependency-cache-{{ checksum "yarn.lock" }}
34+
paths:
35+
- node_modules
36+
- run: yarn run karma start karma.conf.coverage.js
37+
- store_test_results:
38+
path: junit-reports
39+
- run: yarn run codecov
40+
- persist_to_workspace:
41+
root: .
42+
paths:
43+
- .
44+
snyk:
45+
<<: *defaults
46+
steps:
47+
- checkout
48+
- attach_workspace: { at: . }
49+
- run: yarn run snyk test --severity-threshold=high
50+
- run: yarn run snyk monitor
51+
52+
publish:
53+
<<: *defaults
54+
steps:
55+
- checkout
56+
- attach_workspace: { at: . }
57+
- run: npm config set "//registry.npmjs.org/:_authToken" $NPM_AUTH
58+
- run: npm publish .
59+
60+
workflows:
61+
version: 2
62+
test_and_publish:
63+
jobs:
64+
- test:
65+
filters:
66+
tags:
67+
only: /.*/
68+
- coverage:
69+
filters:
70+
tags:
71+
only: /.*/
72+
- snyk:
73+
context: snyk
74+
requires:
75+
- coverage
76+
- publish:
77+
requires:
78+
- test
79+
filters:
80+
tags:
81+
only: /[0-9]+(\.[0-9]+)*(-.+)?/
82+
branches:
83+
ignore: /.*/

Makefile

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,9 @@ GREP ?= .
4242
# Tasks
4343
##
4444

45-
# Install node modules.
46-
node_modules: package.json $(wildcard node_modules/*/package.json)
47-
@npm install
48-
@touch $@
49-
5045
# Install dependencies.
51-
install: node_modules
46+
install:
47+
@yarn
5248

5349
# Remove temporary files and build artifacts.
5450
clean:
@@ -62,7 +58,7 @@ distclean: clean
6258

6359
# Lint JavaScript source files.
6460
lint: install
65-
@$(ESLINT) $(ALL_FILES)
61+
@$(ESLINT) $(LIBS) $(TESTS)
6662
.PHONY: lint
6763

6864
# Attempt to fix linting errors.

RELEASING.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# RELEASING
2+
3+
We automatically publish Github tagged releases from our CI to NPM.
4+
5+
We use [`np`](https://github.com/sindresorhus/np) to prepare a release.
6+
7+
`np` will be automatically installed by running `yarn`, and you can run it with `yarn run np`. You can pass flags to it just as you would with `np`, e.g. you can run `yarn np minor`.
8+
9+
If you run `np` directly, take care to use the [`--no-publish`](https://github.com/sindresorhus/np#publish-with-a-ci) flag. This ensures that we don't directly publish to NPM from a local dev machine.

circle.yml

Lines changed: 0 additions & 31 deletions
This file was deleted.

karma.conf.ci.js

Lines changed: 26 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -33,23 +33,11 @@ var customLaunchers = {
3333
browserName: 'safari',
3434
version: '9.0'
3535
},
36-
// FIXME(ndhoule): Bad IE7/8 support in testing packages make these fail
37-
// sl_ie_7: {
38-
// base: 'SauceLabs',
39-
// browserName: 'internet explorer',
40-
// version: '7'
41-
// },
42-
// sl_ie_8: {
43-
// base: 'SauceLabs',
44-
// browserName: 'internet explorer',
45-
// version: '8'
46-
// },
47-
// FIXME(): IE9 tests are failing pre-Browserification
48-
// sl_ie_9: {
49-
// base: 'SauceLabs',
50-
// browserName: 'internet explorer',
51-
// version: '9'
52-
// },
36+
sl_ie_9: {
37+
base: 'SauceLabs',
38+
browserName: 'internet explorer',
39+
version: '9'
40+
},
5341
sl_ie_10: {
5442
base: 'SauceLabs',
5543
browserName: 'internet explorer',
@@ -70,35 +58,41 @@ module.exports = function(config) {
7058
baseConfig(config);
7159

7260
if (!process.env.SAUCE_USERNAME || !process.env.SAUCE_ACCESS_KEY) {
73-
throw new Error('SAUCE_USERNAME and SAUCE_ACCESS_KEY environment variables are required but are missing');
61+
throw new Error(
62+
'SAUCE_USERNAME and SAUCE_ACCESS_KEY environment variables are required but are missing'
63+
);
7464
}
7565

7666
config.set({
77-
browserDisconnectTolerance: 2,
78-
browserDisconnectTimeout: 30000,
79-
browserNoActivityTimeout: 30000,
67+
browserDisconnectTolerance: 1,
68+
69+
browserDisconnectTimeout: 60000,
70+
71+
browserNoActivityTimeout: 60000,
8072

8173
singleRun: true,
8274

83-
reporters: ['progress', 'junit', 'coverage'],
75+
concurrency: 2,
8476

85-
browsers: ['PhantomJS'].concat(Object.keys(customLaunchers)),
77+
retryLimit: 5,
8678

87-
customLaunchers: customLaunchers,
79+
reporters: ['spec', 'summary', 'junit'],
80+
81+
specReporter: {
82+
suppressPassed: true
83+
},
8884

8985
junitReporter: {
90-
outputDir: process.env.TEST_REPORTS_DIR,
86+
outputDir: 'junit-reports',
9187
suite: require('./package.json').name
9288
},
9389

90+
browsers: ['PhantomJS'].concat(Object.keys(customLaunchers)),
91+
92+
customLaunchers: customLaunchers,
93+
9494
sauceLabs: {
9595
testName: require('./package.json').name
96-
},
97-
98-
coverageReporter: {
99-
reporters: [
100-
{ type: 'lcov' }
101-
]
10296
}
10397
});
104-
};
98+
};

karma.conf.coverage.js

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/* eslint-env node */
2+
'use strict';
3+
4+
var baseConfig = require('./karma.conf');
5+
6+
module.exports = function(config) {
7+
baseConfig(config);
8+
9+
config.set({
10+
singleRun: true,
11+
12+
reporters: ['spec', 'summary', 'junit', 'coverage'],
13+
14+
specReporter: {
15+
suppressPassed: true
16+
},
17+
18+
junitReporter: {
19+
outputDir: 'junit-reports',
20+
suite: require('./package.json').name
21+
},
22+
23+
coverageReporter: {
24+
reporters: [
25+
{ type: 'lcovonly', subdir: '.' },
26+
{ type: 'json', subdir: '.' }
27+
]
28+
},
29+
30+
browserify: {
31+
debug: true,
32+
transform: [
33+
[
34+
'browserify-istanbul',
35+
{
36+
instrumenterConfig: {
37+
embedSource: true
38+
}
39+
}
40+
]
41+
]
42+
}
43+
});
44+
};

karma.conf.js

Lines changed: 9 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
/* eslint-env node */
2-
/* eslint-disable no-restricted-globals */
32
'use strict';
43

4+
// 10 minutes
5+
var TEST_TIMEOUT = 10 * 60 * 1000;
6+
57
module.exports = function(config) {
68
config.set({
79
files: [
810
'test/**/*.test.js'
911
],
10-
1112
browsers: ['PhantomJS'],
1213

1314
middleware: ['server'],
@@ -47,40 +48,23 @@ module.exports = function(config) {
4748

4849
frameworks: ['browserify', 'mocha'],
4950

50-
reporters: ['spec', 'coverage'],
51+
reporters: ['spec'],
5152

5253
preprocessors: {
5354
'test/**/*.js': 'browserify'
5455
},
5556

57+
browserNoActivityTimeout: TEST_TIMEOUT,
58+
5659
client: {
5760
mocha: {
5861
grep: process.env.GREP,
59-
reporter: 'html',
60-
timeout: 10000
62+
timeout: TEST_TIMEOUT
6163
}
6264
},
6365

6466
browserify: {
65-
debug: true,
66-
transform: [
67-
[
68-
'browserify-istanbul',
69-
{
70-
instrumenterConfig: {
71-
embedSource: true
72-
}
73-
}
74-
]
75-
]
76-
},
77-
78-
coverageReporter: {
79-
reporters: [
80-
{ type: 'text' },
81-
{ type: 'html' },
82-
{ type: 'json' }
83-
]
67+
debug: true
8468
}
8569
});
86-
};
70+
};

0 commit comments

Comments
 (0)