setup repo & run npm audit (#1)

This commit is contained in:
Naoki Oketani
2019-12-08 22:10:35 +09:00
committed by GitHub
parent 284541286f
commit 2167fa39e5
9 changed files with 39 additions and 169 deletions

View File

@@ -1,16 +1,25 @@
import * as core from '@actions/core'
import {wait} from './wait'
import { spawnSync, SpawnSyncReturns } from 'child_process';
async function run(): Promise<void> {
try {
const ms: string = core.getInput('milliseconds')
core.debug(`Waiting ${ms} milliseconds ...`)
const result: SpawnSyncReturns<string> = spawnSync('npm', ['audit'], {
encoding: 'utf-8',
});
core.debug(new Date().toTimeString())
await wait(parseInt(ms, 10))
core.debug(new Date().toTimeString())
if (result.stderr && result.stderr.length > 0) {
throw new Error(result.stderr)
}
core.setOutput('time', new Date().toTimeString())
core.info(result.stdout)
if (result.status === 0) {
// vulnerabilities are not found
return
}
// TODO: open an issue
core.debug('open an issue')
} catch (error) {
core.setFailed(error.message)
}

View File

@@ -1,9 +0,0 @@
export async function wait(milliseconds: number): Promise<string> {
return new Promise(resolve => {
if (isNaN(milliseconds)) {
throw new Error('milliseconds not a number')
}
setTimeout(() => resolve('done!'), milliseconds)
})
}