From 777b891dd7a098318b353d8f1de5dc55878cdfac Mon Sep 17 00:00:00 2001 From: Morten Henriksen Date: Tue, 28 Nov 2017 19:17:58 +0100 Subject: [PATCH] chore(ci): add commit lint --- .travis.yml | 3 + bin/lint-commit.sh | 25 ++++ package-lock.json | 280 +++++++++++++++++++++++++++++++++++++++++++++ package.json | 7 ++ 4 files changed, 315 insertions(+) create mode 100755 bin/lint-commit.sh diff --git a/.travis.yml b/.travis.yml index 71fe18a..16af6bc 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,6 +9,8 @@ cache: node_js: - '8' +before_install: git fetch --unshallow + install: - npm install - curl https://install.meteor.com/ | sh @@ -19,6 +21,7 @@ stages: - release script: + - ./bin/lint-commit.sh - npm test - if [ "$TRAVIS_BRANCH" == "master" ]; then npm run semantic-release; fi diff --git a/bin/lint-commit.sh b/bin/lint-commit.sh new file mode 100755 index 0000000..5040f57 --- /dev/null +++ b/bin/lint-commit.sh @@ -0,0 +1,25 @@ +#!/bin/bash +set -e +set -u + +if [[ $TRAVIS_PULL_REQUEST_SLUG != "" && $TRAVIS_PULL_REQUEST_SLUG != $TRAVIS_REPO_SLUG ]]; then + # This is a Pull Request from a different slug, hence a forked repository + git remote add "$TRAVIS_PULL_REQUEST_SLUG" "https://github.com/$TRAVIS_PULL_REQUEST_SLUG.git" + git fetch "$TRAVIS_PULL_REQUEST_SLUG" + + # Use the fetched remote pointing to the source clone for comparison + TO="$TRAVIS_PULL_REQUEST_SLUG/$TRAVIS_PULL_REQUEST_BRANCH" +else + # This is a Pull Request from the same remote, no clone repository + TO=$TRAVIS_COMMIT +fi + +# Lint all commits in the PR +# - Covers fork pull requests (when TO=slug/branch) +# - Covers branch pull requests (when TO=branch) +./node_modules/.bin/commitlint --from="$TRAVIS_BRANCH" --to="$TO" + +# Always lint the triggerig commit +# - Covers direct commits +./node_modules/.bin/commitlint --from="$TRAVIS_COMMIT" +H diff --git a/package-lock.json b/package-lock.json index ecec5ea..11c7283 100644 --- a/package-lock.json +++ b/package-lock.json @@ -4,6 +4,118 @@ "lockfileVersion": 1, "requires": true, "dependencies": { + "@commitlint/cli": { + "version": "5.1.1", + "resolved": "https://registry.npmjs.org/@commitlint/cli/-/cli-5.1.1.tgz", + "integrity": "sha512-dO2GOL5rnnusnkBd5eWZ7irK0bDjOVpuwWHxqTamlxcf4Scy1uQEQXflWqcvW4ftq7VtZ+SAEEdDphe84elDkQ==", + "dev": true, + "requires": { + "@commitlint/core": "5.1.1", + "babel-polyfill": "6.26.0", + "chalk": "2.3.0", + "get-stdin": "5.0.1", + "lodash": "4.17.4", + "meow": "3.7.0" + }, + "dependencies": { + "get-stdin": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/get-stdin/-/get-stdin-5.0.1.tgz", + "integrity": "sha1-Ei4WFZHiH/TFJTAwVpPyDmOTo5g=", + "dev": true + } + } + }, + "@commitlint/config-conventional": { + "version": "5.1.3", + "resolved": "https://registry.npmjs.org/@commitlint/config-conventional/-/config-conventional-5.1.3.tgz", + "integrity": "sha512-8y5w4kmxBKK0Pz9XlaQ/3bfNNTyBCPsmdrz24K76vm8DYleGXEz/vV2n4nLqsKUPa7wiKWw/d1gxWM/msz0XeA==", + "dev": true + }, + "@commitlint/core": { + "version": "5.1.1", + "resolved": "https://registry.npmjs.org/@commitlint/core/-/core-5.1.1.tgz", + "integrity": "sha512-dIXsspjzruBcLyNqQLmPsGN0dN1sj318qq1KY5+KTHCHIs4TUnlWomDi2gvZ5SdgZEHahnpXf0RB9C0PAiRaZA==", + "dev": true, + "requires": { + "@marionebl/conventional-commits-parser": "3.0.0", + "@marionebl/git-raw-commits": "1.2.0", + "@marionebl/sander": "0.6.1", + "babel-runtime": "6.26.0", + "chalk": "2.3.0", + "conventional-changelog-angular": "1.5.2", + "cosmiconfig": "3.1.0", + "find-up": "2.1.0", + "lodash": "4.17.4", + "path-exists": "3.0.0", + "require-uncached": "1.0.3", + "resolve-from": "4.0.0", + "resolve-global": "0.1.0", + "semver": "5.4.1" + }, + "dependencies": { + "@marionebl/conventional-commits-parser": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/@marionebl/conventional-commits-parser/-/conventional-commits-parser-3.0.0.tgz", + "integrity": "sha1-naKbTSyPBcD5zdApNnE7gJbJWNM=", + "dev": true, + "requires": { + "JSONStream": "1.3.1", + "is-text-path": "1.0.1", + "lodash": "4.17.4", + "meow": "3.7.0", + "split2": "2.2.0", + "through2": "2.0.3", + "trim-off-newlines": "1.0.1" + } + }, + "find-up": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/find-up/-/find-up-2.1.0.tgz", + "integrity": "sha1-RdG35QbHF93UgndaK3eSCjwMV6c=", + "dev": true, + "requires": { + "locate-path": "2.0.0" + } + }, + "path-exists": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/path-exists/-/path-exists-3.0.0.tgz", + "integrity": "sha1-zg6+ql94yxiSXqfYENe1mwEP1RU=", + "dev": true + }, + "resolve-from": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/resolve-from/-/resolve-from-4.0.0.tgz", + "integrity": "sha512-pb/MYmXstAkysRFx8piNI1tGFNQIFA3vkE3Gq4EuA1dF6gHp/+vgZqsCGJapvy8N3Q+4o7FwvquPJcnZ7RYy4g==", + "dev": true + } + } + }, + "@marionebl/git-raw-commits": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/@marionebl/git-raw-commits/-/git-raw-commits-1.2.0.tgz", + "integrity": "sha512-kI7s1W+GFMLJkuesgBdMgr1NCkChqfhP+wT6REoPsgtJGGwN0L/84gSw9pyH3u1bAK3uHjAkGZQ2bileBVVWtg==", + "dev": true, + "requires": { + "dargs": "4.1.0", + "lodash.template": "4.4.0", + "meow": "3.7.0", + "split2": "2.2.0", + "through2": "2.0.3" + } + }, + "@marionebl/sander": { + "version": "0.6.1", + "resolved": "https://registry.npmjs.org/@marionebl/sander/-/sander-0.6.1.tgz", + "integrity": "sha1-GViWWHTyS8Ub5Ih1/rUNZC/EH3s=", + "dev": true, + "requires": { + "graceful-fs": "4.1.11", + "mkdirp": "0.5.1", + "rimraf": "2.6.2" + } + }, "@semantic-release/commit-analyzer": { "version": "4.0.1", "resolved": "https://registry.npmjs.org/@semantic-release/commit-analyzer/-/commit-analyzer-4.0.1.tgz", @@ -317,6 +429,35 @@ } } }, + "babel-polyfill": { + "version": "6.26.0", + "resolved": "https://registry.npmjs.org/babel-polyfill/-/babel-polyfill-6.26.0.tgz", + "integrity": "sha1-N5k3q8Z9eJWXCtxiHyhM2WbPIVM=", + "dev": true, + "requires": { + "babel-runtime": "6.26.0", + "core-js": "2.5.1", + "regenerator-runtime": "0.10.5" + }, + "dependencies": { + "regenerator-runtime": { + "version": "0.10.5", + "resolved": "https://registry.npmjs.org/regenerator-runtime/-/regenerator-runtime-0.10.5.tgz", + "integrity": "sha1-M2w+/BIgrc7dosn6tntaeVWjNlg=", + "dev": true + } + } + }, + "babel-runtime": { + "version": "6.26.0", + "resolved": "https://registry.npmjs.org/babel-runtime/-/babel-runtime-6.26.0.tgz", + "integrity": "sha1-llxwWGaOgrVde/4E/yM3vItWR/4=", + "dev": true, + "requires": { + "core-js": "2.5.1", + "regenerator-runtime": "0.11.0" + } + }, "balanced-match": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.0.tgz", @@ -490,6 +631,12 @@ "integrity": "sha1-C74TVaxE16PtSpJXB8TvcPgZD2w=", "dev": true }, + "ci-info": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/ci-info/-/ci-info-1.1.2.tgz", + "integrity": "sha512-uTGIPNx/nSpBdsF6xnseRXLLtfr9VLqkz8ZqHXr3Y7b6SftyRxBGjwMtJj1OhNbmlc1wZzLNAlAcvyIiE8a6ZA==", + "dev": true + }, "circular-json": { "version": "0.3.3", "resolved": "https://registry.npmjs.org/circular-json/-/circular-json-0.3.3.tgz", @@ -691,12 +838,41 @@ "trim-off-newlines": "1.0.1" } }, + "core-js": { + "version": "2.5.1", + "resolved": "https://registry.npmjs.org/core-js/-/core-js-2.5.1.tgz", + "integrity": "sha1-rmh03GaTd4m4B1T/VCjfZoGcpQs=", + "dev": true + }, "core-util-is": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.2.tgz", "integrity": "sha1-tf1UIgqivFq1eqtxQMlAdUUDwac=", "dev": true }, + "cosmiconfig": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/cosmiconfig/-/cosmiconfig-3.1.0.tgz", + "integrity": "sha512-zedsBhLSbPBms+kE7AH4vHg6JsKDz6epSv2/+5XHs8ILHlgDciSJfSWf8sX9aQ52Jb7KI7VswUTsLpR/G0cr2Q==", + "dev": true, + "requires": { + "is-directory": "0.3.1", + "js-yaml": "3.10.0", + "parse-json": "3.0.0", + "require-from-string": "2.0.1" + }, + "dependencies": { + "parse-json": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/parse-json/-/parse-json-3.0.0.tgz", + "integrity": "sha1-+m9HsY4jgm6tMvJj50TQ4ehH+xM=", + "dev": true, + "requires": { + "error-ex": "1.3.1" + } + } + } + }, "cross-spawn": { "version": "5.1.0", "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-5.1.0.tgz", @@ -726,6 +902,15 @@ "array-find-index": "1.0.2" } }, + "dargs": { + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/dargs/-/dargs-4.1.0.tgz", + "integrity": "sha1-A6nbtLXC8Tm/FK5T8LiipqhvThc=", + "dev": true, + "requires": { + "number-is-nan": "1.0.1" + } + }, "dashdash": { "version": "1.14.1", "resolved": "https://registry.npmjs.org/dashdash/-/dashdash-1.14.1.tgz", @@ -1488,6 +1673,15 @@ "path-is-absolute": "1.0.1" } }, + "global-dirs": { + "version": "0.1.1", + "resolved": "https://registry.npmjs.org/global-dirs/-/global-dirs-0.1.1.tgz", + "integrity": "sha1-sxnA3UYH81PzvpzKTHL8FIxJ9EU=", + "dev": true, + "requires": { + "ini": "1.3.5" + } + }, "globals": { "version": "9.18.0", "resolved": "https://registry.npmjs.org/globals/-/globals-9.18.0.tgz", @@ -1657,6 +1851,25 @@ } } }, + "husky": { + "version": "0.14.3", + "resolved": "https://registry.npmjs.org/husky/-/husky-0.14.3.tgz", + "integrity": "sha512-e21wivqHpstpoiWA/Yi8eFti8E+sQDSS53cpJsPptPs295QTOQR0ZwnHo2TXy1XOpZFD9rPOd3NpmqTK6uMLJA==", + "dev": true, + "requires": { + "is-ci": "1.0.10", + "normalize-path": "1.0.0", + "strip-indent": "2.0.0" + }, + "dependencies": { + "strip-indent": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/strip-indent/-/strip-indent-2.0.0.tgz", + "integrity": "sha1-XvjbKV0B5u1sv3qrlpmNeCJSe2g=", + "dev": true + } + } + }, "iconv-lite": { "version": "0.4.19", "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.4.19.tgz", @@ -1776,6 +1989,21 @@ "builtin-modules": "1.1.1" } }, + "is-ci": { + "version": "1.0.10", + "resolved": "https://registry.npmjs.org/is-ci/-/is-ci-1.0.10.tgz", + "integrity": "sha1-9zkzayYyNlBhqdSCcM1WrjNpMY4=", + "dev": true, + "requires": { + "ci-info": "1.1.2" + } + }, + "is-directory": { + "version": "0.3.1", + "resolved": "https://registry.npmjs.org/is-directory/-/is-directory-0.3.1.tgz", + "integrity": "sha1-YTObbyR1/Hcv2cnYP1yFddwVSuE=", + "dev": true + }, "is-finite": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/is-finite/-/is-finite-1.0.2.tgz", @@ -2065,6 +2293,12 @@ "integrity": "sha1-eCA6TRwyiuHYbcpkYONptX9AVa4=", "dev": true }, + "lodash._reinterpolate": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/lodash._reinterpolate/-/lodash._reinterpolate-3.0.0.tgz", + "integrity": "sha1-DM8tiRZq8Ds2Y8eWU4t1rG4RTZ0=", + "dev": true + }, "lodash.assign": { "version": "4.2.0", "resolved": "https://registry.npmjs.org/lodash.assign/-/lodash.assign-4.2.0.tgz", @@ -2077,6 +2311,25 @@ "integrity": "sha1-9HGh2khr5g9quVXRcRVSPdHSVdU=", "dev": true }, + "lodash.template": { + "version": "4.4.0", + "resolved": "https://registry.npmjs.org/lodash.template/-/lodash.template-4.4.0.tgz", + "integrity": "sha1-5zoDhcg1VZF0bgILmWecaQ5o+6A=", + "dev": true, + "requires": { + "lodash._reinterpolate": "3.0.0", + "lodash.templatesettings": "4.1.0" + } + }, + "lodash.templatesettings": { + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/lodash.templatesettings/-/lodash.templatesettings-4.1.0.tgz", + "integrity": "sha1-K01OlbpEDZFf8IvImeRVNmZxMxY=", + "dev": true, + "requires": { + "lodash._reinterpolate": "3.0.0" + } + }, "lodash.toarray": { "version": "4.4.0", "resolved": "https://registry.npmjs.org/lodash.toarray/-/lodash.toarray-4.4.0.tgz", @@ -2308,6 +2561,12 @@ "validate-npm-package-license": "3.0.1" } }, + "normalize-path": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/normalize-path/-/normalize-path-1.0.0.tgz", + "integrity": "sha1-MtDkcvkf80VwHBWoMRAY07CpA3k=", + "dev": true + }, "npm-conf": { "version": "1.1.3", "resolved": "https://registry.npmjs.org/npm-conf/-/npm-conf-1.1.3.tgz", @@ -2762,6 +3021,12 @@ } } }, + "regenerator-runtime": { + "version": "0.11.0", + "resolved": "https://registry.npmjs.org/regenerator-runtime/-/regenerator-runtime-0.11.0.tgz", + "integrity": "sha512-/aA0kLeRb5N9K0d4fw7ooEbI+xDe+DKD499EQqygGqeS8N3xto15p09uY2xj7ixP81sNPXvRLnAQIqdVStgb1A==", + "dev": true + }, "registry-auth-token": { "version": "3.3.1", "resolved": "https://registry.npmjs.org/registry-auth-token/-/registry-auth-token-3.3.1.tgz", @@ -2816,6 +3081,12 @@ "tunnel-agent": "0.4.3" } }, + "require-from-string": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/require-from-string/-/require-from-string-2.0.1.tgz", + "integrity": "sha1-xUUjPp19pmFunVmt+zn8n1iGdv8=", + "dev": true + }, "require-uncached": { "version": "1.0.3", "resolved": "https://registry.npmjs.org/require-uncached/-/require-uncached-1.0.3.tgz", @@ -2841,6 +3112,15 @@ "integrity": "sha1-Jsv+k10a7uq7Kbw/5a6wHpPUQiY=", "dev": true }, + "resolve-global": { + "version": "0.1.0", + "resolved": "https://registry.npmjs.org/resolve-global/-/resolve-global-0.1.0.tgz", + "integrity": "sha1-j7As/Vt9sgEY6IYxHxWvlb0V+9k=", + "dev": true, + "requires": { + "global-dirs": "0.1.1" + } + }, "restore-cursor": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/restore-cursor/-/restore-cursor-2.0.0.tgz", diff --git a/package.json b/package.json index 2b71679..8dc37d6 100644 --- a/package.json +++ b/package.json @@ -5,6 +5,7 @@ "main": "index.js", "scripts": { "test": "echo \"Tests not implemented\" && exit 0", + "commitmsg": "commitlint -e $GIT_PARAMS", "semantic-release": "semantic-release" }, "release": { @@ -18,6 +19,9 @@ "@semantic-release/github" ] }, + "commitlint": { + "extends": ["@commitlint/config-conventional"] + }, "repository": "https://github.com/raix/push.git", "author": "", "license": "MIT", @@ -26,6 +30,9 @@ }, "homepage": "https://github.com/raix/push#readme", "devDependencies": { + "@commitlint/cli": "^5.1.1", + "@commitlint/config-conventional": "^5.1.3", + "husky": "^0.14.3", "meteor-ci": "0.3.1", "semantic-release": "^10.0.1", "semantic-release-meteor": "^0.0.7",