diff --git a/.github/workflows/daily.yml b/.github/workflows/daily.yml index 043ee2a..73c1e93 100644 --- a/.github/workflows/daily.yml +++ b/.github/workflows/daily.yml @@ -12,7 +12,7 @@ jobs: - uses: actions/checkout@v2 - name: install dependencies run: npm ci - - uses: oke-py/npm-audit-action@v1.5.2 + - uses: oke-py/npm-audit-action@v1.6.0 with: github_token: ${{ secrets.GITHUB_TOKEN }} issue_assignees: oke-py diff --git a/README.md b/README.md index 07baa82..1299bda 100644 --- a/README.md +++ b/README.md @@ -58,7 +58,7 @@ jobs: - uses: actions/checkout@v2 - name: install dependencies run: npm ci - - uses: oke-py/npm-audit-action@v1.5.2 + - uses: oke-py/npm-audit-action@v1.6.0 with: audit_level: moderate github_token: ${{ secrets.GITHUB_TOKEN }} diff --git a/dist/index.js b/dist/index.js index dc7a7a6..cd469cd 100644 --- a/dist/index.js +++ b/dist/index.js @@ -556,9 +556,13 @@ class Audit { this.stdout = ''; this.status = null; } - run(auditLevel) { + run(auditLevel, productionFlag) { try { - const result = child_process_1.spawnSync('npm', ['audit', '--audit-level', auditLevel], { + const auditOptions = ['audit', '--audit-level', auditLevel]; + if (productionFlag === 'true') { + auditOptions.push('--production'); + } + const result = child_process_1.spawnSync('npm', auditOptions, { encoding: 'utf-8', maxBuffer: SPAWN_PROCESS_BUFFER_SIZE }); @@ -1427,9 +1431,13 @@ function run() { if (!['critical', 'high', 'moderate', 'low'].includes(auditLevel)) { throw new Error('Invalid input: audit_level'); } + const productionFlag = core.getInput('production_flag', { required: false }); + if (!['true', 'false'].includes(productionFlag)) { + throw new Error('Invalid input: production_flag'); + } // run `npm audit` const audit = new audit_1.Audit(); - audit.run(auditLevel); + audit.run(auditLevel, productionFlag); core.info(audit.stdout); if (audit.foundVulnerability()) { // vulnerabilities are found diff --git a/src/audit.ts b/src/audit.ts index 1d46b7b..b43d574 100644 --- a/src/audit.ts +++ b/src/audit.ts @@ -9,20 +9,16 @@ export class Audit { public run(auditLevel: string, productionFlag: string): void { try { - const auditOptions: Array =['audit', '--audit-level', auditLevel]; - - if(productionFlag === 'true') { - auditOptions.push('--production'); + const auditOptions: Array = ['audit', '--audit-level', auditLevel] + + if (productionFlag === 'true') { + auditOptions.push('--production') } - const result: SpawnSyncReturns = spawnSync( - 'npm', - auditOptions, - { - encoding: 'utf-8', - maxBuffer: SPAWN_PROCESS_BUFFER_SIZE - } - ) + const result: SpawnSyncReturns = spawnSync('npm', auditOptions, { + encoding: 'utf-8', + maxBuffer: SPAWN_PROCESS_BUFFER_SIZE + }) if (result.error) { throw result.error diff --git a/src/main.ts b/src/main.ts index 36abfe0..ca4a9b1 100644 --- a/src/main.ts +++ b/src/main.ts @@ -25,7 +25,7 @@ export async function run(): Promise { throw new Error('Invalid input: audit_level') } - const productionFlag = core.getInput('production_flag', {required: false}); + const productionFlag = core.getInput('production_flag', {required: false}) if (!['true', 'false'].includes(productionFlag)) { throw new Error('Invalid input: production_flag') }