Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
npm-debug.log*
node_modules/
.prettierrc
4 changes: 4 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,8 @@ cache:
directories:
- "node_modules"

before_script:
- "git log"
- "git diff --name-only --diff-filter=AM"

script: npm run-script build
22 changes: 22 additions & 0 deletions curations/npm/npmjs.org/glob.yaml
Original file line number Diff line number Diff line change
@@ -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"
26 changes: 22 additions & 4 deletions curations/npm/npmjs.org/redie.yaml
Original file line number Diff line number Diff line change
@@ -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"
84 changes: 14 additions & 70 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
47 changes: 36 additions & 11 deletions scripts/build.js
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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}`);
Expand All @@ -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();
}