diff --git a/.gitignore b/.gitignore index 653a1f3f5da3..310fed97d736 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,2 @@ npm-debug.log* node_modules/ -.prettierrc diff --git a/.travis.yml b/.travis.yml index 259f683661a7..2e8dbfda23ad 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,4 +5,8 @@ cache: directories: - "node_modules" +before_script: + - "git log" + - "git diff --name-only --diff-filter=AM" + script: npm run-script build diff --git a/curations/npm/npmjs.org/glob.yaml b/curations/npm/npmjs.org/glob.yaml new file mode 100644 index 000000000000..f7ecab55b84c --- /dev/null +++ b/curations/npm/npmjs.org/glob.yaml @@ -0,0 +1,22 @@ +package: + name: lodash + provider: npmjs + type: npm + namespace: "-" +revisions: + 4.17.4: + described: + issueTracker: "https://foobar.com/baz/1" + licensed: + copyright: + statements: + - "foo" + - "bar" + holders: + - "foo" + - "bar" + license: + expression: "MIT" + 4.17.5: + described: + releaseDate: "2018-01-18T06:00:51.556Z" diff --git a/curations/npm/npmjs.org/redie.yaml b/curations/npm/npmjs.org/redie.yaml index 35ddef03f67a..f7ecab55b84c 100644 --- a/curations/npm/npmjs.org/redie.yaml +++ b/curations/npm/npmjs.org/redie.yaml @@ -1,4 +1,22 @@ -0.3.0: - copyright: bar -0.2.0: - copyright: bar +package: + name: lodash + provider: npmjs + type: npm + namespace: "-" +revisions: + 4.17.4: + described: + issueTracker: "https://foobar.com/baz/1" + licensed: + copyright: + statements: + - "foo" + - "bar" + holders: + - "foo" + - "bar" + license: + expression: "MIT" + 4.17.5: + described: + releaseDate: "2018-01-18T06:00:51.556Z" diff --git a/package-lock.json b/package-lock.json index 16e3d5cf7c32..953b44bb0a55 100644 --- a/package-lock.json +++ b/package-lock.json @@ -12,62 +12,19 @@ "sprintf-js": "1.0.3" } }, - "balanced-match": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.0.tgz", - "integrity": "sha1-ibTRmasr7kneFk6gK4nORi1xt2c=" - }, - "brace-expansion": { - "version": "1.1.8", - "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.8.tgz", - "integrity": "sha1-wHshHHyVLsH479Uad+8NHTmQopI=", + "debug": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/debug/-/debug-3.1.0.tgz", + "integrity": "sha512-OX8XqP7/1a9cqkxYw2yXss15f26NKWBpDXQd0/uK/KPqdQhxbPa994hnzjcE2VqQpDslf55723cKPUOGSmMY3g==", "requires": { - "balanced-match": "1.0.0", - "concat-map": "0.0.1" + "ms": "2.0.0" } }, - "concat-map": { - "version": "0.0.1", - "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", - "integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=" - }, "esprima": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/esprima/-/esprima-4.0.0.tgz", "integrity": "sha512-oftTcaMu/EGrEIu904mWteKIv8vMuOgGYo7EhVJJN00R/EED9DCua/xxHRdYnKtcECzVg7xOWhflvJMnqcFZjw==" }, - "fs.realpath": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz", - "integrity": "sha1-FQStJSMVjKpA20onh8sBQRmU6k8=" - }, - "glob": { - "version": "7.1.2", - "resolved": "https://registry.npmjs.org/glob/-/glob-7.1.2.tgz", - "integrity": "sha512-MJTUg1kjuLeQCJ+ccE4Vpa6kKVXkPYJ2mOCQyUuKLcLQsdrMCpBPUi8qVE6+YuaJkozeA9NusTAw3hLr8Xe5EQ==", - "requires": { - "fs.realpath": "1.0.0", - "inflight": "1.0.6", - "inherits": "2.0.3", - "minimatch": "3.0.4", - "once": "1.4.0", - "path-is-absolute": "1.0.1" - } - }, - "inflight": { - "version": "1.0.6", - "resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz", - "integrity": "sha1-Sb1jMdfQLQwJvJEKEHW6gWW1bfk=", - "requires": { - "once": "1.4.0", - "wrappy": "1.0.2" - } - }, - "inherits": { - "version": "2.0.3", - "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.3.tgz", - "integrity": "sha1-Yzwsg+PaQqUC9SRmAiSA9CCCYd4=" - }, "js-yaml": { "version": "3.10.0", "resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-3.10.0.tgz", @@ -77,36 +34,23 @@ "esprima": "4.0.0" } }, - "minimatch": { - "version": "3.0.4", - "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz", - "integrity": "sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA==", - "requires": { - "brace-expansion": "1.1.8" - } + "ms": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", + "integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g=" }, - "once": { - "version": "1.4.0", - "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz", - "integrity": "sha1-WDsap3WWHUsROsF9nFC6753Xa9E=", + "simple-git": { + "version": "1.85.0", + "resolved": "https://registry.npmjs.org/simple-git/-/simple-git-1.85.0.tgz", + "integrity": "sha1-VjrSke/IoSdzXo+815aWc3dhTNQ=", "requires": { - "wrappy": "1.0.2" + "debug": "3.1.0" } }, - "path-is-absolute": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz", - "integrity": "sha1-F0uSaHNVNP+8es5r9TpanhtcX18=" - }, "sprintf-js": { "version": "1.0.3", "resolved": "https://registry.npmjs.org/sprintf-js/-/sprintf-js-1.0.3.tgz", "integrity": "sha1-BOaSb2YolTVPPdAVIDYzuFcpfiw=" - }, - "wrappy": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz", - "integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=" } } } diff --git a/package.json b/package.json index 5695925d0779..0e13ae871993 100644 --- a/package.json +++ b/package.json @@ -11,7 +11,7 @@ "build": "node scripts/build.js" }, "dependencies": { - "glob": "^7.1.2", - "js-yaml": "^3.10.0" + "js-yaml": "^3.10.0", + "simple-git": "^1.85.0" } } diff --git a/scripts/build.js b/scripts/build.js index 2612e3445981..efb32f35ee92 100644 --- a/scripts/build.js +++ b/scripts/build.js @@ -1,10 +1,10 @@ // Copyright (c) 2017, The Linux Foundation. All rights reserved. // SPDX-License-Identifier: MIT -const glob = require('glob'); const yaml = require('js-yaml'); const fs = require('fs'); const {log} = require('console'); +const git = require('simple-git/promise')(__dirname); const ERROR = 1; const isCLI = require.main === module; @@ -14,11 +14,7 @@ const colors = { green: '\x1b[32m', yellow: '\x1b[33m' }; - -// @todo only load new/changed yaml - use git diff -function getYamlFilePaths() { - return glob.sync('{**/*.yaml,**/*.yml}'); -} +const TRAVIS_BRANCH = process.env.TRAVIS_BRANCH function failure(error = 'Error') { log(colors.red, `${error}`); @@ -40,19 +36,48 @@ function logYamlDoc({data, path}) { yaml.safeDump(data).split('\n').forEach(line => log(colors.green, line)); } -function run() { - let paths = getYamlFilePaths(); - if (!paths.length) { +function isCurationFile(path) { + return path.startsWith('curations/') + && (path.endsWith('.yml') || path.endsWith('.yaml')); +} + +async function getAddedAndChangedYamls(commitRange = `HEAD...${TRAVIS_BRANCH}`) { + let yamls = []; + + try { + let paths = await git.raw([ + 'diff', + '--name-only', + '--diff-filter=AM', + commitRange + ]); + yamls = paths ? paths.split('\n').filter(isCurationFile) : []; + } catch (error) { + failure(`Git error: ${error}`) + } + + return yamls; +} + +function processCurations(yamls) { + log('added', process.env.ADDED_CHANGED_FILES); + log('travisbranch', process.env.TRAVIS_BRANCH); + + if (!yamls.length) { return failure('0 yaml files'); } - let docs = paths.map(loadYamlFile).filter(x => x !== ERROR); + let docs = yamls.map(loadYamlFile).filter(x => x !== ERROR); if (docs.length) { - log(colors.yellow, 'Valid yaml file(s):'); + log(colors.yellow, 'Valid yaml files:'); } docs.forEach(logYamlDoc); } +function run() { + getAddedAndChangedYamls('').then(processCurations); +} + if (isCLI) { run(); }