Added support for working-directory (#21)

This commit is contained in:
Ross
2024-07-08 10:14:45 -06:00
committed by GitHub
parent 6dc762e804
commit b7dc4ebf0c
5 changed files with 32 additions and 16 deletions
+3 -2
View File
@@ -26,7 +26,7 @@ jobs:
security_audit: security_audit:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: actions/checkout@v3 - uses: actions/checkout@v4
- uses: rustsec/audit-check@v1.4.1 - uses: rustsec/audit-check@v1.4.1
with: with:
token: ${{ secrets.GITHUB_TOKEN }} token: ${{ secrets.GITHUB_TOKEN }}
@@ -86,7 +86,7 @@ jobs:
audit: audit:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: actions/checkout@v3 - uses: actions/checkout@v4
- uses: rustsec/audit-check@v1.4.1 - uses: rustsec/audit-check@v1.4.1
with: with:
token: ${{ secrets.GITHUB_TOKEN }} token: ${{ secrets.GITHUB_TOKEN }}
@@ -104,5 +104,6 @@ For each new advisory (including informal) an issue will be created:
| ------------| -------- | ---------------------------------------------------------------------------| ------ | --------| | ------------| -------- | ---------------------------------------------------------------------------| ------ | --------|
| `token` | ✓ | [GitHub token], usually a `${{ secrets.GITHUB_TOKEN }}` | string | | | `token` | ✓ | [GitHub token], usually a `${{ secrets.GITHUB_TOKEN }}` | string | |
| `ignore` | | Comma-separated list of advisory ids to ignore | 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 [GitHub token]: https://help.github.com/en/actions/configuring-and-managing-workflows/authenticating-with-the-github_token
+4
View File
@@ -11,6 +11,10 @@ inputs:
ignore: ignore:
description: Comma-separated list of advisory ids to ignore description: Comma-separated list of advisory ids to ignore
required: false required: false
working-directory:
description: The directory of the Cargo.toml / Cargo.lock files to scan.
required: false
default: .
runs: runs:
using: 'node20' using: 'node20'
+12 -13
View File
File diff suppressed because one or more lines are too long
+2
View File
@@ -8,11 +8,13 @@ import { input } from '@clechasseur/rs-actions-core';
export interface Input { export interface Input {
token: string; token: string;
ignore: string[]; ignore: string[];
workingDirectory: string;
} }
export function get(): Input { export function get(): Input {
return { return {
token: input.getInput('token', { required: true }), token: input.getInput('token', { required: true }),
ignore: input.getInputList('ignore', { required: false }), ignore: input.getInputList('ignore', { required: false }),
workingDirectory: input.getInput('working-directory', { required: false }) ?? '.',
}; };
} }
+11 -1
View File
@@ -12,6 +12,7 @@ import * as reporter from './reporter';
async function getData( async function getData(
ignore: string[] | undefined, ignore: string[] | undefined,
workingDirectory: string,
): Promise<interfaces.Report> { ): Promise<interfaces.Report> {
const cargo = await Cargo.get(); const cargo = await Cargo.get();
await cargo.findOrInstall('cargo-audit'); await cargo.findOrInstall('cargo-audit');
@@ -24,6 +25,7 @@ async function getData(
commandArray.push('--ignore', item); commandArray.push('--ignore', item);
} }
commandArray.push('--json'); commandArray.push('--json');
commandArray.push('--file', `${workingDirectory}/Cargo.lock`);
await cargo.call(commandArray, { await cargo.call(commandArray, {
ignoreReturnCode: true, ignoreReturnCode: true,
listeners: { listeners: {
@@ -44,9 +46,17 @@ async function getData(
return JSON.parse(stdout); 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> { export async function run(actionInput: input.Input): Promise<void> {
const ignore = actionInput.ignore; const ignore = actionInput.ignore;
const report = await getData(ignore); const workingDirectory = removeTrailingSlash(actionInput.workingDirectory);
const report = await getData(ignore, workingDirectory);
let shouldReport = false; let shouldReport = false;
if (!report.vulnerabilities.found) { if (!report.vulnerabilities.found) {
core.info('No vulnerabilities were found'); core.info('No vulnerabilities were found');