actions-warden 0.3.0 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AGENTS.md +60 -12
- package/CONTRIBUTING.md +6 -2
- package/README.md +180 -58
- package/RELEASING.md +3 -2
- package/SECURITY.md +23 -8
- package/docs/AI-AGENTS.md +125 -29
- package/docs/CLI.md +346 -69
- package/docs/CONFIGURATION.md +34 -11
- package/docs/DEVELOPMENT.md +114 -18
- package/docs/GITHUB-ACTION.md +163 -29
- package/docs/JAVASCRIPT-API.md +177 -11
- package/docs/OUTPUTS.md +408 -40
- package/docs/README.md +1 -1
- package/examples/README.md +21 -0
- package/examples/baseline-adoption/README.md +79 -0
- package/examples/baseline-adoption/github-actions.yml +56 -0
- package/examples/baseline-adoption/policy.yml +7 -0
- package/examples/ci-violation-reporting/README.md +82 -0
- package/examples/ci-violation-reporting/github-actions.yml +55 -0
- package/examples/ci-violation-reporting/policy.yml +7 -0
- package/examples/ci-violation-reporting/violating-workflow.yml +17 -0
- package/examples/csv-reporting/README.md +50 -0
- package/examples/csv-reporting/github-actions.yml +59 -0
- package/examples/html-organization-report/README.md +35 -0
- package/examples/html-organization-report/github-actions.yml +61 -0
- package/examples/notifications/README.md +67 -0
- package/examples/notifications/github-actions.yml +163 -0
- package/examples/org-scan.yml +24 -5
- package/examples/sarif-code-scanning/README.md +42 -0
- package/examples/sarif-code-scanning/github-actions.yml +66 -0
- package/examples/upgrade-pr.yml +1 -1
- package/llms.txt +14 -5
- package/package.json +8 -4
- package/skills/actions-warden/SKILL.md +91 -39
- package/src/action.js +353 -187
- package/src/cli.js +416 -209
- package/src/commands/audit.js +17 -30
- package/src/commands/org-scan.js +452 -286
- package/src/commands/pin.js +9 -5
- package/src/commands/report.js +7 -2
- package/src/commands/upgrade.js +9 -5
- package/src/commands/verify.js +24 -4
- package/src/index.js +5 -1
- package/src/lib/action-summary.js +656 -0
- package/src/lib/annotations.js +4 -6
- package/src/lib/baseline.js +11 -1
- package/src/lib/config.js +10 -5
- package/src/lib/destination.js +98 -0
- package/src/lib/execution.js +5 -1
- package/src/lib/formats/csv.js +125 -0
- package/src/lib/formats/html.js +394 -0
- package/src/lib/formats/json.js +17 -0
- package/src/lib/formats/sarif.js +229 -0
- package/src/lib/formats/text.js +30 -0
- package/src/lib/formats/toon.js +50 -0
- package/src/lib/formatter.js +25 -192
- package/src/lib/github-org.js +208 -102
- package/src/lib/org-artifacts.js +211 -0
- package/src/lib/org-checkpoint.js +159 -35
- package/src/lib/org-progress.js +182 -4
- package/src/lib/org-report-comparison.js +505 -0
- package/src/lib/org-report-directory.js +251 -0
- package/src/lib/org-report.js +223 -0
- package/src/lib/org-run.js +305 -0
- package/src/lib/org-schema.js +89 -0
- package/src/lib/org-source-links.js +39 -0
- package/src/lib/parser.js +5 -0
- package/src/lib/path-equality.js +30 -0
- package/src/lib/paths.js +18 -1
- package/src/lib/redact.js +58 -7
- package/src/lib/resolver.js +66 -9
- package/src/lib/types.js +137 -0
- package/src/lib/writer.js +3 -0
- package/src/rules/pull-request-target-checkout.js +5 -0
- package/src/rules/unpinned-action.js +2 -3
- package/src/rules/workflow-structure.js +2 -4
- package/src/version.js +1 -1
- package/src/lib/agent-mode.js +0 -175
package/src/action.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
|
-
import { appendFile
|
|
4
|
-
import {
|
|
3
|
+
import { appendFile } from 'node:fs/promises';
|
|
4
|
+
import { resolve } from 'node:path';
|
|
5
5
|
import { randomUUID } from 'node:crypto';
|
|
6
6
|
import { audit, renderAudit } from './commands/audit.js';
|
|
7
7
|
import { pin, renderPin } from './commands/pin.js';
|
|
@@ -14,193 +14,358 @@ import { format as renderFormat } from './lib/formatter.js';
|
|
|
14
14
|
import { redact } from './lib/redact.js';
|
|
15
15
|
import { writeFileGuarded } from './lib/writer.js';
|
|
16
16
|
import { shouldFailAction } from './lib/action-status.js';
|
|
17
|
-
import {
|
|
17
|
+
import { createOrganizationProgressReporter } from './lib/org-progress.js';
|
|
18
|
+
import { runOrganizationScan } from './lib/org-run.js';
|
|
19
|
+
import { SEVERITIES, VISIBILITIES } from './lib/org-schema.js';
|
|
20
|
+
import { loadConfig } from './lib/config.js';
|
|
21
|
+
import { loadBaseline } from './lib/baseline.js';
|
|
22
|
+
import {
|
|
23
|
+
assertDestinationsDoNotReplaceControls,
|
|
24
|
+
assertDestinationsUseSafeNames,
|
|
25
|
+
validateWriteDestination,
|
|
26
|
+
} from './lib/destination.js';
|
|
27
|
+
import {
|
|
28
|
+
ACTION_NUMERIC_OUTPUTS,
|
|
29
|
+
collectActionMetrics,
|
|
30
|
+
emptyActionMetrics,
|
|
31
|
+
renderActionFailureSummary,
|
|
32
|
+
renderActionSummary,
|
|
33
|
+
} from './lib/action-summary.js';
|
|
18
34
|
import {
|
|
19
35
|
collectAnnotations,
|
|
20
36
|
limitAnnotations,
|
|
21
37
|
renderAnnotationCommands,
|
|
22
38
|
} from './lib/annotations.js';
|
|
23
39
|
|
|
24
|
-
const FORMATS = new Set(['toon', 'json', 'text', 'sarif']);
|
|
40
|
+
const FORMATS = new Set(['toon', 'json', 'text', 'csv', 'sarif', 'html']);
|
|
25
41
|
const MODES = new Set(['major', 'minor', 'patch']);
|
|
26
|
-
const SEVERITIES = new Set(['low', 'medium', 'high', 'critical']);
|
|
27
|
-
const VISIBILITIES = new Set(['all', 'public', 'private', 'internal']);
|
|
28
42
|
|
|
29
43
|
async function main() {
|
|
44
|
+
const inputs = readInputs();
|
|
45
|
+
assertInputCombinations(inputs);
|
|
46
|
+
const outcome = await runCommand(inputs);
|
|
47
|
+
await publishOutcome(inputs, outcome);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function readInputs() {
|
|
30
51
|
const command = input('command') || 'audit';
|
|
31
|
-
const
|
|
32
|
-
const
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
52
|
+
const requestedFormat = input('format') || 'auto';
|
|
53
|
+
const format = requestedFormat === 'auto'
|
|
54
|
+
? (command === 'org-scan' ? 'json' : 'toon')
|
|
55
|
+
: requestedFormat;
|
|
56
|
+
return {
|
|
57
|
+
command,
|
|
58
|
+
format,
|
|
59
|
+
...readRepositoryInputs(),
|
|
60
|
+
...readOrganizationInputs(),
|
|
61
|
+
requestedOutput: input('output-path') || undefined,
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function readRepositoryInputs() {
|
|
66
|
+
return {
|
|
67
|
+
cwd: resolve(input('working-directory') || process.env.GITHUB_WORKSPACE || process.cwd()),
|
|
68
|
+
workflows: parseStringList(input('workflow'), 'workflow'),
|
|
69
|
+
token: input('token') || undefined,
|
|
70
|
+
severity: optionalChoice(input('severity'), SEVERITIES, 'severity'),
|
|
71
|
+
mode: choice(input('mode') || 'minor', MODES, 'mode'),
|
|
72
|
+
minAgeDays: nonNegativeInteger(input('min-age') || '7', 'min-age'),
|
|
73
|
+
explain: booleanInput('explain', false),
|
|
74
|
+
offline: booleanInput('offline', false),
|
|
75
|
+
write: booleanInput('write', false),
|
|
76
|
+
failOnFindings: booleanInput('fail-on-findings', true),
|
|
77
|
+
annotationsEnabled: booleanInput('annotations', true),
|
|
78
|
+
fix: input('fix') || undefined,
|
|
79
|
+
configPath: input('config') || undefined,
|
|
80
|
+
ignoreConfig: booleanInput('ignore-config', false),
|
|
81
|
+
baseline: input('baseline') || undefined,
|
|
82
|
+
};
|
|
83
|
+
}
|
|
58
84
|
|
|
85
|
+
function readOrganizationInputs() {
|
|
86
|
+
return {
|
|
87
|
+
organization: input('organization') || undefined,
|
|
88
|
+
repositories: parseStringList(input('repository'), 'repository'),
|
|
89
|
+
visibility: choice(input('visibility') || 'all', VISIBILITIES, 'visibility'),
|
|
90
|
+
includeArchived: booleanInput('include-archived', false),
|
|
91
|
+
includeDisabled: booleanInput('include-disabled', false),
|
|
92
|
+
includeForks: booleanInput('include-forks', false),
|
|
93
|
+
maxRepositories: optionalPositiveInteger(input('max-repos'), 'max-repos'),
|
|
94
|
+
concurrency: positiveInteger(input('concurrency') || '4', 'concurrency'),
|
|
95
|
+
checkpointPath: input('checkpoint-path') || undefined,
|
|
96
|
+
resumeFrom: input('resume-from') || undefined,
|
|
97
|
+
previousReportPath: input('previous-report') || undefined,
|
|
98
|
+
progress: booleanInput('progress', true),
|
|
99
|
+
fresh: booleanInput('fresh', false),
|
|
100
|
+
autoCheckpoint: booleanInput('auto-checkpoint', true),
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
function assertInputCombinations({ command, format, requestedOutput, previousReportPath }) {
|
|
59
105
|
if (!FORMATS.has(format)) throw new Error(`invalid format: ${format}`);
|
|
106
|
+
if (command !== 'org-scan' && ['csv', 'html'].includes(format) && !requestedOutput) {
|
|
107
|
+
throw new Error(`output-path is required when format is ${format}`);
|
|
108
|
+
}
|
|
109
|
+
if (previousReportPath && command !== 'org-scan') {
|
|
110
|
+
throw new Error('previous-report applies only to org-scan');
|
|
111
|
+
}
|
|
112
|
+
if (previousReportPath && format === 'sarif') {
|
|
113
|
+
throw new Error('previous-report cannot be used with format sarif');
|
|
114
|
+
}
|
|
115
|
+
}
|
|
60
116
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
117
|
+
const COMMAND_RUNNERS = new Map([
|
|
118
|
+
['audit', runAuditCommand],
|
|
119
|
+
['pin', runPinCommand],
|
|
120
|
+
['upgrade', runUpgradeCommand],
|
|
121
|
+
['report', runReportCommand],
|
|
122
|
+
['verify', runVerifyCommand],
|
|
123
|
+
['org-scan', runOrganizationCommand],
|
|
124
|
+
['rules', runRulesCommand],
|
|
125
|
+
]);
|
|
64
126
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
127
|
+
async function runCommand(inputs) {
|
|
128
|
+
const reportPath = inputs.command === 'org-scan' ? '' : await guardRepositoryOutput(inputs);
|
|
129
|
+
const runner = COMMAND_RUNNERS.get(inputs.command);
|
|
130
|
+
if (!runner) throw new Error(`unknown command: ${inputs.command}`);
|
|
131
|
+
return {
|
|
132
|
+
reportPath,
|
|
133
|
+
requestedOutput: inputs.requestedOutput,
|
|
134
|
+
checkpointPath: '',
|
|
135
|
+
checkpointResumed: false,
|
|
136
|
+
repositoriesReused: 0,
|
|
137
|
+
...await runner(inputs),
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
async function guardRepositoryOutput({
|
|
142
|
+
requestedOutput,
|
|
143
|
+
cwd,
|
|
144
|
+
ignoreConfig,
|
|
145
|
+
configPath,
|
|
146
|
+
baseline,
|
|
147
|
+
workflows,
|
|
148
|
+
}) {
|
|
149
|
+
if (!requestedOutput) return '';
|
|
150
|
+
const outputDestination = await validateWriteDestination({
|
|
151
|
+
label: 'output-path',
|
|
152
|
+
path: requestedOutput,
|
|
153
|
+
cwd,
|
|
154
|
+
});
|
|
155
|
+
await assertDestinationsUseSafeNames([outputDestination], cwd);
|
|
156
|
+
const config = await loadConfig({
|
|
157
|
+
cwd,
|
|
158
|
+
path: ignoreConfig ? false : configPath,
|
|
159
|
+
ruleIds: listRules().map(rule => rule.id),
|
|
160
|
+
});
|
|
161
|
+
const baselinePath = baseline ?? config.baseline;
|
|
162
|
+
const baselineData = baselinePath
|
|
163
|
+
? await loadBaseline({ path: baselinePath, cwd })
|
|
164
|
+
: { path: null };
|
|
165
|
+
await assertDestinationsDoNotReplaceControls(
|
|
166
|
+
[outputDestination],
|
|
167
|
+
[
|
|
168
|
+
{ label: 'active config', path: config.path },
|
|
169
|
+
{ label: 'active baseline', path: baselineData.path },
|
|
170
|
+
...workflows.map(wf => ({ label: 'workflow file', path: resolve(cwd, wf) })),
|
|
171
|
+
],
|
|
172
|
+
);
|
|
173
|
+
return outputDestination.path;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
async function runAuditCommand(inputs) {
|
|
177
|
+
const { cwd, workflows, severity, explain, baseline, format } = inputs;
|
|
178
|
+
const result = await audit({
|
|
179
|
+
cwd,
|
|
180
|
+
workflows,
|
|
181
|
+
severity,
|
|
182
|
+
explain,
|
|
183
|
+
configPath: inputs.ignoreConfig ? false : inputs.configPath,
|
|
184
|
+
baseline,
|
|
185
|
+
});
|
|
186
|
+
return { result, payload: renderAudit(result, { format, explain, cwd }) };
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
async function runPinCommand({ cwd, workflows, write, token, fix, format }) {
|
|
190
|
+
const result = await pin({ cwd, workflows, dryRun: !write, token, fix });
|
|
191
|
+
return { result, payload: renderPin(result, { format, dryRun: !write, cwd }) };
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
async function runUpgradeCommand(inputs) {
|
|
195
|
+
const { cwd, workflows, write, token, mode, minAgeDays, fix, format } = inputs;
|
|
196
|
+
const result = await upgrade({
|
|
197
|
+
cwd,
|
|
198
|
+
workflows,
|
|
199
|
+
dryRun: !write,
|
|
200
|
+
token,
|
|
201
|
+
mode,
|
|
202
|
+
minAgeDays,
|
|
203
|
+
fix,
|
|
204
|
+
});
|
|
205
|
+
return { result, payload: renderUpgrade(result, { format, dryRun: !write, mode, cwd }) };
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
async function runReportCommand(inputs) {
|
|
209
|
+
const { cwd, workflows, token, mode, severity, explain, offline, minAgeDays } = inputs;
|
|
210
|
+
const result = await report({
|
|
211
|
+
cwd,
|
|
212
|
+
workflows,
|
|
213
|
+
token,
|
|
214
|
+
mode,
|
|
215
|
+
severity,
|
|
216
|
+
explain,
|
|
217
|
+
skipResolve: offline,
|
|
218
|
+
minAgeDays,
|
|
219
|
+
configPath: inputs.ignoreConfig ? false : inputs.configPath,
|
|
220
|
+
baseline: inputs.baseline,
|
|
221
|
+
});
|
|
222
|
+
return { result, payload: renderReport(result, { format: inputs.format, mode, cwd }) };
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
async function runVerifyCommand({ cwd, workflows, token, format }) {
|
|
226
|
+
const result = await verify({ cwd, workflows, token });
|
|
227
|
+
return { result, payload: renderVerify(result, { format, cwd }) };
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
function runRulesCommand({ format }) {
|
|
231
|
+
const rules = listRules();
|
|
232
|
+
return {
|
|
233
|
+
result: { status: 'OK' },
|
|
234
|
+
payload: renderFormat(
|
|
235
|
+
format,
|
|
236
|
+
rules.map(rule => ({ label: 'RULE', fields: rule })),
|
|
237
|
+
{
|
|
238
|
+
status: 'OK',
|
|
239
|
+
title: 'Audit rule catalog',
|
|
240
|
+
json: { schemaVersion: '1.0', rules, status: 'OK' },
|
|
241
|
+
},
|
|
242
|
+
),
|
|
243
|
+
};
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
async function runOrganizationCommand(inputs) {
|
|
247
|
+
const { organization, cwd, format } = inputs;
|
|
248
|
+
if (!organization) throw new Error('organization is required for org-scan');
|
|
249
|
+
if (inputs.checkpointPath && inputs.resumeFrom) {
|
|
250
|
+
throw new Error('checkpoint-path and resume-from cannot be used together');
|
|
251
|
+
}
|
|
252
|
+
if (inputs.fresh && inputs.resumeFrom) {
|
|
253
|
+
throw new Error('fresh and resume-from cannot be used together');
|
|
254
|
+
}
|
|
255
|
+
let progressReporter;
|
|
256
|
+
try {
|
|
257
|
+
const run = await runOrganizationScan({
|
|
258
|
+
scan: {
|
|
128
259
|
organization,
|
|
129
260
|
cwd,
|
|
130
|
-
token,
|
|
131
|
-
repositories,
|
|
132
|
-
visibility,
|
|
133
|
-
includeArchived,
|
|
134
|
-
includeDisabled,
|
|
135
|
-
includeForks,
|
|
136
|
-
maxRepositories,
|
|
137
|
-
concurrency,
|
|
138
|
-
severity,
|
|
139
|
-
explain,
|
|
140
|
-
configPath: ignoreConfig ? false : configPath,
|
|
141
|
-
baseline,
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
261
|
+
token: inputs.token,
|
|
262
|
+
repositories: inputs.repositories,
|
|
263
|
+
visibility: inputs.visibility,
|
|
264
|
+
includeArchived: inputs.includeArchived,
|
|
265
|
+
includeDisabled: inputs.includeDisabled,
|
|
266
|
+
includeForks: inputs.includeForks,
|
|
267
|
+
maxRepositories: inputs.maxRepositories,
|
|
268
|
+
concurrency: inputs.concurrency,
|
|
269
|
+
severity: inputs.severity,
|
|
270
|
+
explain: inputs.explain,
|
|
271
|
+
configPath: inputs.ignoreConfig ? false : inputs.configPath,
|
|
272
|
+
baseline: inputs.baseline,
|
|
273
|
+
},
|
|
274
|
+
scanOrganization,
|
|
275
|
+
format,
|
|
276
|
+
output: 'file',
|
|
277
|
+
outputPath: inputs.requestedOutput,
|
|
278
|
+
checkpointPath: inputs.checkpointPath,
|
|
279
|
+
resumePath: inputs.resumeFrom,
|
|
280
|
+
fresh: inputs.fresh,
|
|
281
|
+
autoCheckpoint: inputs.autoCheckpoint,
|
|
282
|
+
previousReportPath: inputs.previousReportPath,
|
|
283
|
+
labels: { output: 'output-path', checkpoint: 'checkpoint-path', resume: 'resume-from' },
|
|
284
|
+
openProgress: () => {
|
|
285
|
+
progressReporter = createOrganizationProgressReporter({
|
|
286
|
+
mode: inputs.progress ? 'plain' : 'none',
|
|
287
|
+
context: 'ci',
|
|
288
|
+
stream: process.stderr,
|
|
289
|
+
});
|
|
290
|
+
return progressReporter;
|
|
291
|
+
},
|
|
292
|
+
});
|
|
293
|
+
return {
|
|
294
|
+
result: run.result,
|
|
295
|
+
payload: renderOrganizationScan(run.result, { format, cwd }),
|
|
296
|
+
reportPath: run.outputDestination.path,
|
|
297
|
+
requestedOutput: run.reportPath,
|
|
298
|
+
checkpointPath: run.checkpointDestination?.path ?? '',
|
|
299
|
+
checkpointResumed: run.resumed,
|
|
300
|
+
repositoriesReused: run.repositoriesReused,
|
|
301
|
+
};
|
|
302
|
+
} finally {
|
|
303
|
+
progressReporter?.close();
|
|
166
304
|
}
|
|
305
|
+
}
|
|
167
306
|
|
|
168
|
-
|
|
169
|
-
const
|
|
307
|
+
async function publishOutcome(inputs, outcome) {
|
|
308
|
+
const { command, format, cwd } = inputs;
|
|
309
|
+
const { result, payload, requestedOutput } = outcome;
|
|
310
|
+
if (command !== 'org-scan' && (!['csv', 'html'].includes(format) || !requestedOutput)) {
|
|
311
|
+
process.stdout.write(payload);
|
|
312
|
+
}
|
|
313
|
+
const annotationResult = inputs.annotationsEnabled
|
|
170
314
|
? limitAnnotations(collectAnnotations({ command, result, cwd }))
|
|
171
315
|
: { emitted: [], omitted: 0 };
|
|
172
316
|
const annotationCommands = renderAnnotationCommands(annotationResult.emitted);
|
|
173
317
|
if (annotationCommands) process.stdout.write(annotationCommands);
|
|
318
|
+
const reportPath = await writeReportOutput(inputs, outcome);
|
|
319
|
+
await publishActionOutputs(inputs, { ...outcome, reportPath }, annotationResult);
|
|
320
|
+
if (shouldFailAction({ command, result, failOnFindings: inputs.failOnFindings })) {
|
|
321
|
+
process.exitCode = 1;
|
|
322
|
+
}
|
|
323
|
+
}
|
|
174
324
|
|
|
175
|
-
|
|
176
|
-
const requestedOutput =
|
|
177
|
-
if (requestedOutput)
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
325
|
+
async function writeReportOutput({ command, format, cwd }, outcome) {
|
|
326
|
+
const { requestedOutput, payload } = outcome;
|
|
327
|
+
if (!requestedOutput) return outcome.reportPath;
|
|
328
|
+
const reportPath = outcome.reportPath || resolve(cwd, requestedOutput);
|
|
329
|
+
await writeFileGuarded({ path: reportPath, content: payload, dryRun: false, cwd });
|
|
330
|
+
if (command === 'org-scan') {
|
|
331
|
+
process.stdout.write(
|
|
332
|
+
`Organization ${format.toUpperCase()} report written to ${actionLogText(requestedOutput)}\n`,
|
|
333
|
+
);
|
|
334
|
+
} else if (['csv', 'html'].includes(format)) {
|
|
335
|
+
process.stdout.write(
|
|
336
|
+
`${format.toUpperCase()} report written to ${actionLogText(requestedOutput)}\n`,
|
|
337
|
+
);
|
|
185
338
|
}
|
|
339
|
+
return reportPath;
|
|
340
|
+
}
|
|
186
341
|
|
|
342
|
+
async function publishActionOutputs(inputs, outcome, annotationResult) {
|
|
343
|
+
const { command, cwd, write } = inputs;
|
|
344
|
+
const { result, reportPath, checkpointPath, checkpointResumed, repositoriesReused } = outcome;
|
|
345
|
+
const metrics = collectActionMetrics({ command, result, repositoriesReused });
|
|
187
346
|
await setOutput('status', result.status);
|
|
188
|
-
await
|
|
347
|
+
await setNumericOutputs(metrics);
|
|
348
|
+
await setOutput(
|
|
349
|
+
'coverage-complete',
|
|
350
|
+
command === 'org-scan' ? String(result.coverage?.complete === true) : '',
|
|
351
|
+
);
|
|
189
352
|
await setOutput('annotations', String(annotationResult.emitted.length));
|
|
190
353
|
await setOutput('annotations-skipped', String(annotationResult.omitted));
|
|
191
|
-
|
|
192
|
-
await
|
|
354
|
+
await setOutput('report-path', reportPath);
|
|
355
|
+
await setOutput('checkpoint-path', checkpointPath);
|
|
356
|
+
await appendSummary(renderActionSummary({
|
|
193
357
|
command,
|
|
194
|
-
|
|
195
|
-
|
|
358
|
+
result,
|
|
359
|
+
cwd,
|
|
360
|
+
metrics,
|
|
196
361
|
annotations: annotationResult.emitted.length,
|
|
197
362
|
annotationsSkipped: annotationResult.omitted,
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
}
|
|
363
|
+
reportPath,
|
|
364
|
+
checkpointPath,
|
|
365
|
+
checkpointResumed,
|
|
366
|
+
repositoriesReused,
|
|
367
|
+
write,
|
|
368
|
+
}));
|
|
204
369
|
}
|
|
205
370
|
|
|
206
371
|
function input(name) {
|
|
@@ -254,18 +419,6 @@ function optionalPositiveInteger(value, name) {
|
|
|
254
419
|
return value ? positiveInteger(value, name) : undefined;
|
|
255
420
|
}
|
|
256
421
|
|
|
257
|
-
async function samePath(left, right) {
|
|
258
|
-
const [leftParent, rightParent] = await Promise.all([
|
|
259
|
-
realpath(dirname(left)),
|
|
260
|
-
realpath(dirname(right)),
|
|
261
|
-
]);
|
|
262
|
-
const leftTarget = join(leftParent, basename(left));
|
|
263
|
-
const rightTarget = join(rightParent, basename(right));
|
|
264
|
-
return process.platform === 'win32'
|
|
265
|
-
? leftTarget.toLowerCase() === rightTarget.toLowerCase()
|
|
266
|
-
: leftTarget === rightTarget;
|
|
267
|
-
}
|
|
268
|
-
|
|
269
422
|
async function setOutput(name, value) {
|
|
270
423
|
if (!process.env.GITHUB_OUTPUT) return;
|
|
271
424
|
const delimiter = `actions_warden_${randomUUID().replaceAll('-', '')}`;
|
|
@@ -276,29 +429,33 @@ async function setOutput(name, value) {
|
|
|
276
429
|
);
|
|
277
430
|
}
|
|
278
431
|
|
|
279
|
-
async function
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
}) {
|
|
432
|
+
async function setNumericOutputs(metrics) {
|
|
433
|
+
for (const [output, key] of ACTION_NUMERIC_OUTPUTS) {
|
|
434
|
+
await setOutput(output, String(metrics[key]));
|
|
435
|
+
}
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
async function appendSummary(markdown) {
|
|
287
439
|
if (!process.env.GITHUB_STEP_SUMMARY) return;
|
|
288
|
-
const indented = payload
|
|
289
|
-
.slice(0, 8000)
|
|
290
|
-
.split('\n')
|
|
291
|
-
.map(line => ` ${line}`)
|
|
292
|
-
.join('\n');
|
|
293
440
|
await appendFile(
|
|
294
441
|
process.env.GITHUB_STEP_SUMMARY,
|
|
295
|
-
|
|
442
|
+
markdown,
|
|
296
443
|
'utf8',
|
|
297
444
|
);
|
|
298
445
|
}
|
|
299
446
|
|
|
447
|
+
/** Redact and visibly escape control bytes before writing ordinary Action logs. */
|
|
448
|
+
function actionLogText(value) {
|
|
449
|
+
return [...redact(value)].map(character => {
|
|
450
|
+
const codePoint = character.codePointAt(0);
|
|
451
|
+
return codePoint <= 0x1f || (codePoint >= 0x7f && codePoint <= 0x9f)
|
|
452
|
+
? `\\u${codePoint.toString(16).padStart(4, '0')}`
|
|
453
|
+
: character;
|
|
454
|
+
}).join('');
|
|
455
|
+
}
|
|
456
|
+
|
|
300
457
|
main().catch(async error => {
|
|
301
|
-
const message =
|
|
458
|
+
const message = actionLogText(String(error?.message ?? error));
|
|
302
459
|
process.stderr.write(`error: ${message}\n`);
|
|
303
460
|
const annotationsEnabled = input('annotations') !== 'false';
|
|
304
461
|
if (annotationsEnabled) {
|
|
@@ -309,9 +466,18 @@ main().catch(async error => {
|
|
|
309
466
|
message,
|
|
310
467
|
}]));
|
|
311
468
|
}
|
|
469
|
+
const annotations = annotationsEnabled ? 1 : 0;
|
|
312
470
|
await setOutput('status', 'FAIL').catch(() => {});
|
|
313
|
-
await
|
|
314
|
-
await setOutput('
|
|
471
|
+
await setNumericOutputs(emptyActionMetrics({ errors: 1 })).catch(() => {});
|
|
472
|
+
await setOutput('coverage-complete', '').catch(() => {});
|
|
473
|
+
await setOutput('annotations', String(annotations)).catch(() => {});
|
|
315
474
|
await setOutput('annotations-skipped', '0').catch(() => {});
|
|
475
|
+
await setOutput('report-path', '').catch(() => {});
|
|
476
|
+
await setOutput('checkpoint-path', '').catch(() => {});
|
|
477
|
+
await appendSummary(renderActionFailureSummary({
|
|
478
|
+
command: input('command') || 'audit',
|
|
479
|
+
message,
|
|
480
|
+
annotations,
|
|
481
|
+
})).catch(() => {});
|
|
316
482
|
process.exitCode = 2;
|
|
317
483
|
});
|