Skip to content

Commit 1f88ae2

Browse files
authored
Optional Warning (or dry run) instead of an error (#21)
* Update index.js * Initial commit
1 parent 1f00dd2 commit 1f88ae2

File tree

5 files changed

+29
-7
lines changed

5 files changed

+29
-7
lines changed

Diff for: README.md

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ For more information on these inputs, see the [Workflow syntax for GitHub Action
1616
aws-actions/ # Trust all actions published by aws-actions
1717
docker/login-action # Trust docker's login-action only
1818
```
19+
- `dry_run`: Set to `true` to show warnings instead of failing. Optional. Default: `false` (fail on any error)
1920

2021
### Outputs
2122
None. This action will throw an error if it finds GitHub Actions that are not pinned to full length commit SHAs.

Diff for: action.yml

+3
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,6 @@ branding:
1212
inputs:
1313
allowlist:
1414
description: 'The list of owners or repositories that will be ignored and will not throw an error. Each entry must be on a new line. Optional. Default: `` (deny all)'
15+
dry_run:
16+
description: 'Set to `true` to show warnings instead of failing. Optional. Default: `false` (fail on any error)'
17+
default: false

Diff for: dist/index.js

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

Diff for: dist/index.js.map

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

Diff for: src/index.js

+12-3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ const yaml = require('yaml');
88
async function run() {
99
try {
1010
const allowlist = core.getInput('allowlist');
11+
const isDryRun = core.getInput('dry_run') === 'true' ? true : false;
1112
const workflowsPath = process.env['ZG_WORKFLOWS_PATH'] || '.github/workflows';
1213
const globber = await glob.create([workflowsPath + '/*.yaml', workflowsPath + '/*.yml'].join('\n'));
1314
let actionHasError = false;
@@ -34,7 +35,7 @@ async function run() {
3435
actionHasError = true;
3536
fileHasError = true;
3637

37-
core.error(`${uses} is not pinned to a full length commit SHA.`);
38+
reportError(`${uses} is not pinned to a full length commit SHA.`, isDryRun);
3839
}
3940
} else if (steps !== undefined) {
4041
for (const step of steps) {
@@ -44,7 +45,7 @@ async function run() {
4445
actionHasError = true;
4546
fileHasError = true;
4647

47-
core.error(`${uses} is not pinned to a full length commit SHA.`);
48+
reportError(`${uses} is not pinned to a full length commit SHA.`, isDryRun);
4849
}
4950
}
5051
} else {
@@ -59,7 +60,7 @@ async function run() {
5960
core.endGroup();
6061
}
6162

62-
if (actionHasError) {
63+
if (!isDryRun && actionHasError) {
6364
throw new Error('At least one workflow contains an unpinned GitHub Action version.');
6465
}
6566
} catch (error) {
@@ -91,3 +92,11 @@ function assertUsesAllowlist(uses, allowlist) {
9192

9293
return isAllowed;
9394
}
95+
96+
function reportError(message, isDryRun) {
97+
if (isDryRun) {
98+
core.warning(message);
99+
} else {
100+
core.error(message);
101+
}
102+
}

0 commit comments

Comments
 (0)