actions-warden 0.4.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 +46 -8
- package/CONTRIBUTING.md +6 -2
- package/README.md +171 -61
- package/RELEASING.md +3 -2
- package/SECURITY.md +15 -5
- package/docs/AI-AGENTS.md +109 -29
- package/docs/CLI.md +284 -60
- package/docs/CONFIGURATION.md +34 -11
- package/docs/DEVELOPMENT.md +97 -24
- package/docs/GITHUB-ACTION.md +157 -27
- package/docs/JAVASCRIPT-API.md +172 -8
- package/docs/OUTPUTS.md +399 -36
- 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 +78 -35
- package/src/action.js +351 -174
- package/src/cli.js +191 -177
- package/src/commands/audit.js +17 -30
- package/src/commands/org-scan.js +451 -280
- 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 +137 -96
- 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/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/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 -174
package/src/action.js
CHANGED
|
@@ -14,194 +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 {
|
|
18
|
-
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';
|
|
19
34
|
import {
|
|
20
35
|
collectAnnotations,
|
|
21
36
|
limitAnnotations,
|
|
22
37
|
renderAnnotationCommands,
|
|
23
38
|
} from './lib/annotations.js';
|
|
24
39
|
|
|
25
|
-
const FORMATS = new Set(['toon', 'json', 'text', 'sarif']);
|
|
40
|
+
const FORMATS = new Set(['toon', 'json', 'text', 'csv', 'sarif', 'html']);
|
|
26
41
|
const MODES = new Set(['major', 'minor', 'patch']);
|
|
27
|
-
const SEVERITIES = new Set(['low', 'medium', 'high', 'critical']);
|
|
28
|
-
const VISIBILITIES = new Set(['all', 'public', 'private', 'internal']);
|
|
29
42
|
|
|
30
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() {
|
|
31
51
|
const command = input('command') || 'audit';
|
|
32
|
-
const
|
|
33
|
-
const
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
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
|
+
}
|
|
59
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 }) {
|
|
60
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
|
+
}
|
|
61
116
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
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
|
+
]);
|
|
65
126
|
|
|
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
|
-
|
|
128
|
-
|
|
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: {
|
|
129
259
|
organization,
|
|
130
260
|
cwd,
|
|
131
|
-
token,
|
|
132
|
-
repositories,
|
|
133
|
-
visibility,
|
|
134
|
-
includeArchived,
|
|
135
|
-
includeDisabled,
|
|
136
|
-
includeForks,
|
|
137
|
-
maxRepositories,
|
|
138
|
-
concurrency,
|
|
139
|
-
severity,
|
|
140
|
-
explain,
|
|
141
|
-
configPath: ignoreConfig ? false : configPath,
|
|
142
|
-
baseline,
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
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();
|
|
167
304
|
}
|
|
305
|
+
}
|
|
168
306
|
|
|
169
|
-
|
|
170
|
-
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
|
|
171
314
|
? limitAnnotations(collectAnnotations({ command, result, cwd }))
|
|
172
315
|
: { emitted: [], omitted: 0 };
|
|
173
316
|
const annotationCommands = renderAnnotationCommands(annotationResult.emitted);
|
|
174
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
|
+
}
|
|
175
324
|
|
|
176
|
-
|
|
177
|
-
const requestedOutput =
|
|
178
|
-
if (requestedOutput)
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
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
|
+
);
|
|
186
338
|
}
|
|
339
|
+
return reportPath;
|
|
340
|
+
}
|
|
187
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 });
|
|
188
346
|
await setOutput('status', result.status);
|
|
189
|
-
await
|
|
347
|
+
await setNumericOutputs(metrics);
|
|
348
|
+
await setOutput(
|
|
349
|
+
'coverage-complete',
|
|
350
|
+
command === 'org-scan' ? String(result.coverage?.complete === true) : '',
|
|
351
|
+
);
|
|
190
352
|
await setOutput('annotations', String(annotationResult.emitted.length));
|
|
191
353
|
await setOutput('annotations-skipped', String(annotationResult.omitted));
|
|
192
|
-
|
|
193
|
-
await
|
|
354
|
+
await setOutput('report-path', reportPath);
|
|
355
|
+
await setOutput('checkpoint-path', checkpointPath);
|
|
356
|
+
await appendSummary(renderActionSummary({
|
|
194
357
|
command,
|
|
195
|
-
|
|
196
|
-
|
|
358
|
+
result,
|
|
359
|
+
cwd,
|
|
360
|
+
metrics,
|
|
197
361
|
annotations: annotationResult.emitted.length,
|
|
198
362
|
annotationsSkipped: annotationResult.omitted,
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
}
|
|
363
|
+
reportPath,
|
|
364
|
+
checkpointPath,
|
|
365
|
+
checkpointResumed,
|
|
366
|
+
repositoriesReused,
|
|
367
|
+
write,
|
|
368
|
+
}));
|
|
205
369
|
}
|
|
206
370
|
|
|
207
371
|
function input(name) {
|
|
@@ -265,29 +429,33 @@ async function setOutput(name, value) {
|
|
|
265
429
|
);
|
|
266
430
|
}
|
|
267
431
|
|
|
268
|
-
async function
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
}) {
|
|
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) {
|
|
276
439
|
if (!process.env.GITHUB_STEP_SUMMARY) return;
|
|
277
|
-
const indented = payload
|
|
278
|
-
.slice(0, 8000)
|
|
279
|
-
.split('\n')
|
|
280
|
-
.map(line => ` ${line}`)
|
|
281
|
-
.join('\n');
|
|
282
440
|
await appendFile(
|
|
283
441
|
process.env.GITHUB_STEP_SUMMARY,
|
|
284
|
-
|
|
442
|
+
markdown,
|
|
285
443
|
'utf8',
|
|
286
444
|
);
|
|
287
445
|
}
|
|
288
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
|
+
|
|
289
457
|
main().catch(async error => {
|
|
290
|
-
const message =
|
|
458
|
+
const message = actionLogText(String(error?.message ?? error));
|
|
291
459
|
process.stderr.write(`error: ${message}\n`);
|
|
292
460
|
const annotationsEnabled = input('annotations') !== 'false';
|
|
293
461
|
if (annotationsEnabled) {
|
|
@@ -298,9 +466,18 @@ main().catch(async error => {
|
|
|
298
466
|
message,
|
|
299
467
|
}]));
|
|
300
468
|
}
|
|
469
|
+
const annotations = annotationsEnabled ? 1 : 0;
|
|
301
470
|
await setOutput('status', 'FAIL').catch(() => {});
|
|
302
|
-
await
|
|
303
|
-
await setOutput('
|
|
471
|
+
await setNumericOutputs(emptyActionMetrics({ errors: 1 })).catch(() => {});
|
|
472
|
+
await setOutput('coverage-complete', '').catch(() => {});
|
|
473
|
+
await setOutput('annotations', String(annotations)).catch(() => {});
|
|
304
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(() => {});
|
|
305
482
|
process.exitCode = 2;
|
|
306
483
|
});
|