Skip to content

Commit

Permalink
Added support for working-directory (#21)
Browse files Browse the repository at this point in the history
  • Loading branch information
ranger-ross authored Jul 8, 2024
1 parent 6dc762e commit b7dc4eb
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 16 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
security_audit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: rustsec/audit-check@v1.4.1
with:
token: ${{ secrets.GITHUB_TOKEN }}
Expand Down Expand Up @@ -86,7 +86,7 @@ jobs:
audit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: rustsec/audit-check@v1.4.1
with:
token: ${{ secrets.GITHUB_TOKEN }}
Expand All @@ -104,5 +104,6 @@ For each new advisory (including informal) an issue will be created:
| ------------| -------- | ---------------------------------------------------------------------------| ------ | --------|
| `token` | ✓ | [GitHub token], usually a `${{ secrets.GITHUB_TOKEN }}` | string | |
| `ignore` | | Comma-separated list of advisory ids to ignore | string | |
| `working-directory`| | The directory of the Cargo.toml / Cargo.lock files to scan. | string | `.` |

[GitHub token]: https://help.github.com/en/actions/configuring-and-managing-workflows/authenticating-with-the-github_token
4 changes: 4 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ inputs:
ignore:
description: Comma-separated list of advisory ids to ignore
required: false
working-directory:
description: The directory of the Cargo.toml / Cargo.lock files to scan.
required: false
default: .

runs:
using: 'node20'
Expand Down
25 changes: 12 additions & 13 deletions dist/index.js

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions src/input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@ import { input } from '@clechasseur/rs-actions-core';
export interface Input {
token: string;
ignore: string[];
workingDirectory: string;
}

export function get(): Input {
return {
token: input.getInput('token', { required: true }),
ignore: input.getInputList('ignore', { required: false }),
workingDirectory: input.getInput('working-directory', { required: false }) ?? '.',
};
}
12 changes: 11 additions & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import * as reporter from './reporter';

async function getData(
ignore: string[] | undefined,
workingDirectory: string,
): Promise<interfaces.Report> {
const cargo = await Cargo.get();
await cargo.findOrInstall('cargo-audit');
Expand All @@ -24,6 +25,7 @@ async function getData(
commandArray.push('--ignore', item);
}
commandArray.push('--json');
commandArray.push('--file', `${workingDirectory}/Cargo.lock`);
await cargo.call(commandArray, {
ignoreReturnCode: true,
listeners: {
Expand All @@ -44,9 +46,17 @@ async function getData(
return JSON.parse(stdout);
}

function removeTrailingSlash(str) {
if (str[str.length - 1] === '/') {
return str.substr(0, str.length - 1);
}
return str;
}

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

0 comments on commit b7dc4eb

Please sign in to comment.