-
Notifications
You must be signed in to change notification settings - Fork 913
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(travis-cli): add reusable travis command line interface
* related #99
- Loading branch information
Showing
22 changed files
with
431 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
#!/usr/bin/env node | ||
console.log(process.argv); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
#!/usr/bin/env node | ||
console.log(process.argv); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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']); | ||
} |
Oops, something went wrong.