Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for working-directory #21

Merged
merged 6 commits into from
Jul 8, 2024
Merged
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
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/[email protected]
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/[email protected]
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