-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
34 lines (32 loc) · 1.14 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
const core = require('@actions/core');
const github = require('@actions/github');
const { runner } = require('graphql-schema-linter');
function lintSchemas(schemas) {
const args = [null, __dirname, ...schemas];
console.log("Linting schemas: ", schemas.join())
return runner.run(process.stdout, process.stdin, process.stderr, args)
}
async function main() {
const payload = JSON.stringify(github.context.payload, undefined, 2)
console.log(`The event payload: ${payload}`);
try {
const schemaFiles = core.getInput('files').split(',');
const combined = core.getInput('combined');
if (combined) {
const exitCode = await lintSchemas(schemaFiles);
if (exitCode !== 0) {
throw new Error(`Invalid Schemas ${schemas}`);
}
} else {
for (const schema of schemaFiles) {
const exitCode = await lintSchemas([schema]);
if (exitCode !== 0) {
throw new Error(`Invalid Schema ${schema}`);
}
}
}
} catch (error) {
core.setFailed(error.message);
}
}
main();