Files
npm-audit-action/src/main.ts

29 lines
598 B
TypeScript
Raw Normal View History

2019-12-08 19:17:13 +09:00
import * as core from '@actions/core'
2019-12-08 22:10:35 +09:00
import { spawnSync, SpawnSyncReturns } from 'child_process';
2019-12-08 19:17:13 +09:00
async function run(): Promise<void> {
try {
2019-12-08 22:10:35 +09:00
const result: SpawnSyncReturns<string> = spawnSync('npm', ['audit'], {
encoding: 'utf-8',
});
2019-12-08 19:17:13 +09:00
2019-12-08 22:10:35 +09:00
if (result.stderr && result.stderr.length > 0) {
throw new Error(result.stderr)
}
2019-12-08 19:17:13 +09:00
2019-12-08 22:10:35 +09:00
core.info(result.stdout)
if (result.status === 0) {
// vulnerabilities are not found
return
}
// TODO: open an issue
core.debug('open an issue')
2019-12-08 19:17:13 +09:00
} catch (error) {
core.setFailed(error.message)
}
}
run()