Skip to content

Commit b7dc4eb

Browse files
authored
Added support for working-directory (#21)
1 parent 6dc762e commit b7dc4eb

File tree

5 files changed

+32
-16
lines changed

5 files changed

+32
-16
lines changed

Diff for: README.md

+3-2
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ jobs:
2626
security_audit:
2727
runs-on: ubuntu-latest
2828
steps:
29-
- uses: actions/checkout@v3
29+
- uses: actions/checkout@v4
3030
- uses: rustsec/[email protected]
3131
with:
3232
token: ${{ secrets.GITHUB_TOKEN }}
@@ -86,7 +86,7 @@ jobs:
8686
audit:
8787
runs-on: ubuntu-latest
8888
steps:
89-
- uses: actions/checkout@v3
89+
- uses: actions/checkout@v4
9090
- uses: rustsec/[email protected]
9191
with:
9292
token: ${{ secrets.GITHUB_TOKEN }}
@@ -104,5 +104,6 @@ For each new advisory (including informal) an issue will be created:
104104
| ------------| -------- | ---------------------------------------------------------------------------| ------ | --------|
105105
| `token` | ✓ | [GitHub token], usually a `${{ secrets.GITHUB_TOKEN }}` | string | |
106106
| `ignore` | | Comma-separated list of advisory ids to ignore | string | |
107+
| `working-directory`| | The directory of the Cargo.toml / Cargo.lock files to scan. | string | `.` |
107108

108109
[GitHub token]: https://help.github.com/en/actions/configuring-and-managing-workflows/authenticating-with-the-github_token

Diff for: action.yml

+4
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ inputs:
1111
ignore:
1212
description: Comma-separated list of advisory ids to ignore
1313
required: false
14+
working-directory:
15+
description: The directory of the Cargo.toml / Cargo.lock files to scan.
16+
required: false
17+
default: .
1418

1519
runs:
1620
using: 'node20'

Diff for: dist/index.js

+12-13
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: src/input.ts

+2
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,13 @@ import { input } from '@clechasseur/rs-actions-core';
88
export interface Input {
99
token: string;
1010
ignore: string[];
11+
workingDirectory: string;
1112
}
1213

1314
export function get(): Input {
1415
return {
1516
token: input.getInput('token', { required: true }),
1617
ignore: input.getInputList('ignore', { required: false }),
18+
workingDirectory: input.getInput('working-directory', { required: false }) ?? '.',
1719
};
1820
}

Diff for: src/main.ts

+11-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import * as reporter from './reporter';
1212

1313
async function getData(
1414
ignore: string[] | undefined,
15+
workingDirectory: string,
1516
): Promise<interfaces.Report> {
1617
const cargo = await Cargo.get();
1718
await cargo.findOrInstall('cargo-audit');
@@ -24,6 +25,7 @@ async function getData(
2425
commandArray.push('--ignore', item);
2526
}
2627
commandArray.push('--json');
28+
commandArray.push('--file', `${workingDirectory}/Cargo.lock`);
2729
await cargo.call(commandArray, {
2830
ignoreReturnCode: true,
2931
listeners: {
@@ -44,9 +46,17 @@ async function getData(
4446
return JSON.parse(stdout);
4547
}
4648

49+
function removeTrailingSlash(str) {
50+
if (str[str.length - 1] === '/') {
51+
return str.substr(0, str.length - 1);
52+
}
53+
return str;
54+
}
55+
4756
export async function run(actionInput: input.Input): Promise<void> {
4857
const ignore = actionInput.ignore;
49-
const report = await getData(ignore);
58+
const workingDirectory = removeTrailingSlash(actionInput.workingDirectory);
59+
const report = await getData(ignore, workingDirectory);
5060
let shouldReport = false;
5161
if (!report.vulnerabilities.found) {
5262
core.info('No vulnerabilities were found');

0 commit comments

Comments
 (0)