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

ci: simplified commitlint script #151

Merged
merged 28 commits into from
Nov 24, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
6973c6b
build: switch to independent mode
marionebl Nov 22, 2017
58fdd3e
ci: draft shareable travis script
marionebl Nov 22, 2017
a7ad565
ci: relink after building
marionebl Nov 22, 2017
ec62b22
feat(cli): expose cli path
marionebl Nov 23, 2017
0ea70f1
test(travis-cli): cover invocations
marionebl Nov 23, 2017
f7dbac4
style: ensure consistent json indent
marionebl Nov 23, 2017
6436911
fix(travis-cli): remove unneeded meow dep
marionebl Nov 23, 2017
661fa7d
test(travis-cli): skip invocation tests on win32
marionebl Nov 23, 2017
4fa8744
style: simplify catch branch
marionebl Nov 23, 2017
de96e8d
style: avoid Promise constructor
marionebl Nov 23, 2017
2561a31
refactor: use babel to use async/await
marionebl Nov 23, 2017
4d6fb5c
ci: build everything
marionebl Nov 23, 2017
5c15e9e
fix: use Object.assign instead of spread
marionebl Nov 23, 2017
3a8fc35
fix: integrate dogfed tools robustly
marionebl Nov 23, 2017
51c850b
test: add babel build to ava
marionebl Nov 23, 2017
291792e
build(travis-cli): ensure node <8 compat
marionebl Nov 23, 2017
08597d4
fix(travis-cli): be less noisy
marionebl Nov 24, 2017
b37ca41
build: remove npx for speed and simplicity
marionebl Nov 24, 2017
ac4ebc0
build: simplify root level scripts
marionebl Nov 24, 2017
333f287
fix(travis-cli): remove faulty flag
marionebl Nov 24, 2017
e1e1897
build: remove independent mode
marionebl Nov 24, 2017
09f63d7
fix(cli): resolve to artifacts
marionebl Nov 24, 2017
da852e9
fix(travis-cli): stash if git wd is dirty
marionebl Nov 24, 2017
1faa70a
test(travis-cli): increase git coverage
marionebl Nov 24, 2017
ae3b87a
test(travis-cli): explicitly disable Travis CI
marionebl Nov 24, 2017
f8fafa3
test(travis-cli): check if Travis CI on our own
marionebl Nov 24, 2017
930487c
fix(travis-cli): remove obsolete dep
marionebl Nov 24, 2017
9c0f3cd
fix(travis-cli): readd as depdev
marionebl Nov 24, 2017
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
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ insert_final_newline = true
trim_trailing_whitespace = true
indent_style = tab

[{.*rc,*.yml,*.md,package.json,*.svg}]
[{.*rc,*.yml,*.md,package.json,lerna.json,*.svg}]
indent_style = space

[*.md]
Expand Down
11 changes: 6 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@ node_js:
install:
- npm install -g npx
- npx yarn install
- npx lerna bootstrap --since $TRAVIS_BRANCH --include-filtered-dependencies --stream
- npx lerna bootstrap
- npm --version
- yarn --version
- npx --version
script:
- npx yarn build --since $TRAVIS_BRANCH --include-filtered-dependencies --stream
- npx yarn lint --since $TRAVIS_BRANCH --include-filtered-dependencies --stream
- npx yarn deps --since $TRAVIS_BRANCH --include-filtered-dependencies --stream
- npx yarn test --since $TRAVIS_BRANCH --include-filtered-dependencies --stream
- npx yarn build
- node @commitlint/travis-cli/lib/cli.js
- npx yarn lint
- npx yarn deps
- npx yarn test
3 changes: 3 additions & 0 deletions @commitlint/cli/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const path = require('path');

module.exports = path.join(__dirname, 'lib/cli.js');
10 changes: 5 additions & 5 deletions @commitlint/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
"commitlint": "./lib/cli.js"
},
"scripts": {
"build": "npx cross-env NODE_ENV=production npx -p babel-cli babel src --out-dir lib --source-maps",
"build": "cross-env NODE_ENV=production babel src --out-dir lib --source-maps",
"clean": "npx rimraf lib",
"deps": "dep-check",
"lint": "npx xo",
"start": "npx concurrently \"npx ava -c 4 --verbose --watch\" \"npx yarn run watch\"",
"test": "npx ava -c 4 --verbose",
"watch": "npx -p babel-cli babel src --out-dir lib --watch --source-maps"
"lint": "xo",
"start": "concurrently \"ava -c 4 --verbose --watch\" \"yarn run watch\"",
"test": "ava -c 4 --verbose",
"watch": "babel src --out-dir lib --watch --source-maps"
},
"ava": {
"files": [
Expand Down
2 changes: 1 addition & 1 deletion @commitlint/config-angular-type-enum/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"scripts": {
"clean": "exit 0",
"deps": "dep-check",
"lint": "npx xo",
"lint": "xo",
"start": "exit 0",
"test": "exit 0"
},
Expand Down
2 changes: 1 addition & 1 deletion @commitlint/config-angular/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"scripts": {
"clean": "exit 0",
"deps": "dep-check",
"lint": "npx xo",
"lint": "xo",
"start": "exit 0",
"test": "exit 0"
},
Expand Down
6 changes: 3 additions & 3 deletions @commitlint/config-lerna-scopes/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
"description": "Shareable commitlint config enforcing lerna package names as scopes",
"scripts": {
"clean": "exit 0",
"lint": "npx xo",
"start": "npx ava --watch --verbose",
"test": "npx ava --verbose"
"lint": "xo",
"start": "ava --watch --verbose",
"test": "ava --verbose"
},
"xo": false,
"ava": {
Expand Down
2 changes: 1 addition & 1 deletion @commitlint/config-patternplate/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"scripts": {
"clean": "exit 0",
"deps": "dep-check",
"lint": "npx xo",
"lint": "xo",
"start": "exit 0",
"test": "exit 0"
},
Expand Down
10 changes: 5 additions & 5 deletions @commitlint/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
"description": "Lint your commit messages",
"main": "lib/index.js",
"scripts": {
"build": "npx cross-env NODE_ENV=production npx -p babel-cli babel src --out-dir lib --source-maps",
"build": "cross-env NODE_ENV=production babel src --out-dir lib --source-maps",
"clean": "npx rimraf lib",
"deps": "dep-check",
"lint": "npx xo",
"start": "npx concurrently \"npx ava -c 4 --verbose --watch\" \"npx yarn run watch\"",
"test": "npx ava -c 4 --verbose && npx ava \"src/*.serial-test.js\" --verbose",
"watch": "npx -p babel-cli babel src --out-dir lib --watch --source-maps"
"lint": "xo",
"start": "concurrently \"ava -c 4 --verbose --watch\" \"yarn run watch\"",
"test": "ava -c 4 --verbose && ava \"src/*.serial-test.js\" --verbose",
"watch": "babel src --out-dir lib --watch --source-maps"
},
"ava": {
"files": [
Expand Down
2 changes: 1 addition & 1 deletion @commitlint/prompt-cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"clean": "npx rimraf lib",
"commit": "$npm_package_bin_commit",
"deps": "dep-check",
"lint": "npx xo"
"lint": "xo"
},
"xo": false,
"repository": {
Expand Down
12 changes: 6 additions & 6 deletions @commitlint/prompt/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
"description": "commitizen prompt using commitlint.config.js",
"main": "./lib/index.js",
"scripts": {
"build": "npx cross-env NODE_ENV=production npx -p babel-cli babel src --out-dir lib --source-maps",
"build": "cross-env NODE_ENV=production babel src --out-dir lib --source-maps",
"clean": "npx rimraf lib",
"commit": "npx git-cz",
"commit": "git-cz",
"deps": "dep-check",
"lint": "npx xo",
"start": "npx concurrently \"npx ava --watch --verbose\" \"npx yarn run watch\"",
"test": "npx ava --verbose",
"watch": "npx -p babel-cli babel src --out-dir lib --watch --source-maps"
"lint": "xo",
"start": "concurrently \"ava --watch --verbose\" \"yarn run watch\"",
"test": "ava --verbose",
"watch": "babel src --out-dir lib --watch --source-maps"
},
"ava": {
"babel": "inherit",
Expand Down
19 changes: 19 additions & 0 deletions @commitlint/travis-cli/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
> Lint all relevant commits for a change or PR on Travis CI

# @commitlint/travis-cli

This package is a convenience wrapper around `commitlint`,
providing zero-configuration linting of all relevant commits
for a given change/build combination.

## Getting started

```
npm install --save-dev @commitlint/travis-cli
```

```yml
# .travis.yml
script
- commitlint-travis
```
2 changes: 2 additions & 0 deletions @commitlint/travis-cli/fixtures/commitlint.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/usr/bin/env node
console.log(process.argv);
2 changes: 2 additions & 0 deletions @commitlint/travis-cli/fixtures/git.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/usr/bin/env node
console.log(process.argv);
72 changes: 72 additions & 0 deletions @commitlint/travis-cli/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
{
"name": "@commitlint/travis-cli",
"version": "5.0.1",
"description": "Lint all relevant commits for a change or PR on Travis CI",
"bin": {
"commitlint-travis": "./lib/cli.js"
},
"scripts": {
"build": "cross-env NODE_ENV=production babel src --out-dir lib --source-maps",
"clean": "npx rimraf lib",
"deps": "dep-check",
"lint": "xo",
"start": "ava -c 4 --verbose --watch",
"test": "ava -c 4 --verbose",
"watch": "babel src --out-dir lib --watch --source-maps"
},
"ava": {
"files": [
"src/**/*.test.js"
],
"source": [
"lib/**/*.js"
],
"babel": "inherit",
"require": [
"babel-register"
]
},
"babel": {
"presets": [
"babel-preset-commitlint"
]
},
"xo": false,
"engines": {
"node": ">=4"
},
"repository": {
"type": "git",
"url": "https://github.com/marionebl/commitlint.git"
},
"bugs": {
"url": "https://github.com/marionebl/commitlint/issues"
},
"homepage": "https://github.com/marionebl/commitlint#readme",
"keywords": [
"conventional-changelog",
"commitlint",
"cli"
],
"author": {
"name": "Mario Nebl",
"email": "[email protected]"
},
"license": "MIT",
"devDependencies": {
"@commitlint/utils": "^5.0.1",
"@commitlint/test": "^5.0.1",
"ava": "0.18.2",
"babel-cli": "6.26.0",
"babel-preset-commitlint": "^5.0.1",
"babel-register": "6.26.0",
"cross-env": "5.1.1",
"which": "^1.3.0"
},
"dependencies": {
"@commitlint/cli": "^5.0.1",
"@marionebl/sander": "^0.6.1",
"execa": "^0.8.0",
"find-up": "^2.1.0"
}
}
78 changes: 78 additions & 0 deletions @commitlint/travis-cli/src/cli.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
#!/usr/bin/env node
const sander = require('@marionebl/sander');
const execa = require('execa');
const findUp = require('find-up');

// Allow to override used bins for testing purposes
const GIT = process.env.TRAVIS_COMMITLINT_GIT_BIN || 'git';
const COMMITLINT =
process.env.TRAVIS_COMMITLINT_BIN || require('@commitlint/cli'); // eslint-disable-line import/newline-after-import
const REQUIRED = ['TRAVIS_COMMIT', 'TRAVIS_BRANCH'];

const TRAVIS_BRANCH = process.env.TRAVIS_BRANCH;
const TRAVIS_COMMIT = process.env.TRAVIS_COMMIT;

main().catch(err => {
console.log(err);
process.exit(1);
});

async function main() {
if (process.env.CI !== 'true' || process.env.TRAVIS !== 'true') {
throw new Error(
`@commitlint/travis-cli is inteded to be used on Travis CI`
);
}

const gitRoot = await findUp('.git');
const missing = REQUIRED.filter(envVar => !(envVar in process.env));

if (missing.length > 0) {
const stanza = missing.length > 1 ? 'they were not' : 'it was not';
throw new Error(
`Expected ${missing.join(', ')} to be defined globally, ${stanza}.`
);
}

const pop = await stash();

await git(['remote', 'set-branches', 'origin', TRAVIS_BRANCH]);

if (await sander.exists(gitRoot, 'shallow')) {
await git(['fetch', '--unshallow', '--quiet']);
}

await git(['checkout', TRAVIS_BRANCH, '--quiet']);
await git(['checkout', '-', '--quiet']);

await pop();

await lint(['--from', TRAVIS_BRANCH, '--to', TRAVIS_COMMIT]);
}

async function git(args, options) {
return execa(GIT, args, Object.assign({}, {stdio: 'inherit'}, options));
}

async function isClean() {
const result = await git(['status', '--porcelain'], {
stdio: ['pipe', 'pipe', 'pipe']
});
return !(result.stdout && result.stdout.trim());
}

async function lint(args, options) {
return execa(
COMMITLINT,
args,
Object.assign({}, {stdio: 'inherit'}, options)
);
}

async function stash() {
if (await isClean()) {
return async () => {};
}
await git(['stash']);
return () => git(['stash', 'pop']);
}
Loading