Skip to content
This repository has been archived by the owner on Oct 13, 2023. It is now read-only.

Add an input for passing additional arguments to cargo audit call #133

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
3 changes: 3 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ inputs:
token:
description: GitHub Actions token
required: true
args:
description: Arguments for the audit command
required: false

runs:
using: 'node12'
Expand Down
5 changes: 5 additions & 0 deletions package-lock.json

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

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@
"@actions/core": "^1.2.4",
"@actions/github": "^2.1.1",
"npm-check-updates": "^4.1.2",
"nunjucks": "^3.2.1"
"nunjucks": "^3.2.1",
"string-argv": "^0.3.1"
},
"devDependencies": {
"@typescript-eslint/eslint-plugin": "^2.31.0",
Expand Down
4 changes: 4 additions & 0 deletions src/input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,17 @@

import { input } from '@actions-rs/core';

import stringArgv from 'string-argv';

// Parsed action input
export interface Input {
token: string;
args: string[];
}

export function get(): Input {
return {
token: input.getInput('token', { required: true }),
args: stringArgv(input.getInput('args')),
};
}
7 changes: 4 additions & 3 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const pkg = require('../package.json'); // eslint-disable-line @typescript-eslin

const USER_AGENT = `${pkg.name}/${pkg.version} (${pkg.bugs.url})`;

async function getData(): Promise<interfaces.Report> {
async function getData(args: string[]): Promise<interfaces.Report> {
const cargo = await Cargo.get();
await cargo.findOrInstall('cargo-audit');

Expand All @@ -23,7 +23,8 @@ async function getData(): Promise<interfaces.Report> {
let stdout = '';
try {
core.startGroup('Calling cargo-audit (JSON output)');
await cargo.call(['audit', '--json'], {
const fullArgs = ['audit', '--json'].concat(args);
await cargo.call(fullArgs, {
ignoreReturnCode: true,
listeners: {
stdout: (buffer) => {
Expand All @@ -44,7 +45,7 @@ async function getData(): Promise<interfaces.Report> {
}

export async function run(actionInput: input.Input): Promise<void> {
const report = await getData();
const report = await getData(actionInput.args);
let shouldReport = false;
if (!report.vulnerabilities.found) {
core.info('No vulnerabilities were found');
Expand Down