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.
Files changed (76) hide show
  1. package/AGENTS.md +46 -8
  2. package/CONTRIBUTING.md +6 -2
  3. package/README.md +171 -61
  4. package/RELEASING.md +3 -2
  5. package/SECURITY.md +15 -5
  6. package/docs/AI-AGENTS.md +109 -29
  7. package/docs/CLI.md +284 -60
  8. package/docs/CONFIGURATION.md +34 -11
  9. package/docs/DEVELOPMENT.md +97 -24
  10. package/docs/GITHUB-ACTION.md +157 -27
  11. package/docs/JAVASCRIPT-API.md +172 -8
  12. package/docs/OUTPUTS.md +399 -36
  13. package/docs/README.md +1 -1
  14. package/examples/README.md +21 -0
  15. package/examples/baseline-adoption/README.md +79 -0
  16. package/examples/baseline-adoption/github-actions.yml +56 -0
  17. package/examples/baseline-adoption/policy.yml +7 -0
  18. package/examples/ci-violation-reporting/README.md +82 -0
  19. package/examples/ci-violation-reporting/github-actions.yml +55 -0
  20. package/examples/ci-violation-reporting/policy.yml +7 -0
  21. package/examples/ci-violation-reporting/violating-workflow.yml +17 -0
  22. package/examples/csv-reporting/README.md +50 -0
  23. package/examples/csv-reporting/github-actions.yml +59 -0
  24. package/examples/html-organization-report/README.md +35 -0
  25. package/examples/html-organization-report/github-actions.yml +61 -0
  26. package/examples/notifications/README.md +67 -0
  27. package/examples/notifications/github-actions.yml +163 -0
  28. package/examples/org-scan.yml +24 -5
  29. package/examples/sarif-code-scanning/README.md +42 -0
  30. package/examples/sarif-code-scanning/github-actions.yml +66 -0
  31. package/examples/upgrade-pr.yml +1 -1
  32. package/llms.txt +14 -5
  33. package/package.json +8 -4
  34. package/skills/actions-warden/SKILL.md +78 -35
  35. package/src/action.js +351 -174
  36. package/src/cli.js +191 -177
  37. package/src/commands/audit.js +17 -30
  38. package/src/commands/org-scan.js +451 -280
  39. package/src/commands/pin.js +9 -5
  40. package/src/commands/report.js +7 -2
  41. package/src/commands/upgrade.js +9 -5
  42. package/src/commands/verify.js +24 -4
  43. package/src/index.js +5 -1
  44. package/src/lib/action-summary.js +656 -0
  45. package/src/lib/annotations.js +4 -6
  46. package/src/lib/baseline.js +11 -1
  47. package/src/lib/config.js +10 -5
  48. package/src/lib/destination.js +98 -0
  49. package/src/lib/execution.js +5 -1
  50. package/src/lib/formats/csv.js +125 -0
  51. package/src/lib/formats/html.js +394 -0
  52. package/src/lib/formats/json.js +17 -0
  53. package/src/lib/formats/sarif.js +229 -0
  54. package/src/lib/formats/text.js +30 -0
  55. package/src/lib/formats/toon.js +50 -0
  56. package/src/lib/formatter.js +25 -192
  57. package/src/lib/github-org.js +208 -102
  58. package/src/lib/org-artifacts.js +211 -0
  59. package/src/lib/org-checkpoint.js +137 -96
  60. package/src/lib/org-progress.js +182 -4
  61. package/src/lib/org-report-comparison.js +505 -0
  62. package/src/lib/org-report-directory.js +251 -0
  63. package/src/lib/org-report.js +223 -0
  64. package/src/lib/org-run.js +305 -0
  65. package/src/lib/org-schema.js +89 -0
  66. package/src/lib/org-source-links.js +39 -0
  67. package/src/lib/parser.js +5 -0
  68. package/src/lib/paths.js +18 -1
  69. package/src/lib/redact.js +58 -7
  70. package/src/lib/resolver.js +66 -9
  71. package/src/lib/types.js +137 -0
  72. package/src/rules/pull-request-target-checkout.js +5 -0
  73. package/src/rules/unpinned-action.js +2 -3
  74. package/src/rules/workflow-structure.js +2 -4
  75. package/src/version.js +1 -1
  76. 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 { formatOrganizationProgress } from './lib/org-progress.js';
18
- import { sameFilePath } from './lib/path-equality.js';
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 format = input('format') || 'toon';
33
- const cwd = resolve(input('working-directory') || process.env.GITHUB_WORKSPACE || process.cwd());
34
- const workflows = parseStringList(input('workflow'), 'workflow');
35
- const token = input('token') || undefined;
36
- const severity = optionalChoice(input('severity'), SEVERITIES, 'severity');
37
- const mode = choice(input('mode') || 'minor', MODES, 'mode');
38
- const minAgeDays = nonNegativeInteger(input('min-age') || '7', 'min-age');
39
- const explain = booleanInput('explain', false);
40
- const offline = booleanInput('offline', false);
41
- const write = booleanInput('write', false);
42
- const failOnFindings = booleanInput('fail-on-findings', true);
43
- const annotationsEnabled = booleanInput('annotations', true);
44
- const fix = input('fix') || undefined;
45
- const configPath = input('config') || undefined;
46
- const ignoreConfig = booleanInput('ignore-config', false);
47
- const baseline = input('baseline') || undefined;
48
- const organization = input('organization') || undefined;
49
- const repositories = parseStringList(input('repository'), 'repository');
50
- const visibility = choice(input('visibility') || 'all', VISIBILITIES, 'visibility');
51
- const includeArchived = booleanInput('include-archived', false);
52
- const includeDisabled = booleanInput('include-disabled', false);
53
- const includeForks = booleanInput('include-forks', false);
54
- const maxRepositories = optionalPositiveInteger(input('max-repos'), 'max-repos');
55
- const concurrency = positiveInteger(input('concurrency') || '4', 'concurrency');
56
- const checkpointPath = input('checkpoint-path') || undefined;
57
- const resumeFrom = input('resume-from') || undefined;
58
- const progress = booleanInput('progress', true);
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
- let result;
63
- let payload;
64
- let findings = 0;
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
- switch (command) {
67
- case 'audit':
68
- result = await audit({
69
- cwd,
70
- workflows,
71
- severity,
72
- explain,
73
- configPath: ignoreConfig ? false : configPath,
74
- baseline,
75
- });
76
- payload = renderAudit(result, { format, explain, cwd });
77
- findings = result.summary.findings;
78
- break;
79
- case 'pin':
80
- result = await pin({ cwd, workflows, dryRun: !write, token, fix });
81
- payload = renderPin(result, { format, dryRun: !write, cwd });
82
- break;
83
- case 'upgrade':
84
- result = await upgrade({
85
- cwd,
86
- workflows,
87
- dryRun: !write,
88
- token,
89
- mode,
90
- minAgeDays,
91
- fix,
92
- });
93
- payload = renderUpgrade(result, { format, dryRun: !write, mode, cwd });
94
- break;
95
- case 'report':
96
- result = await report({
97
- cwd,
98
- workflows,
99
- token,
100
- mode,
101
- severity,
102
- explain,
103
- skipResolve: offline,
104
- minAgeDays,
105
- configPath: ignoreConfig ? false : configPath,
106
- baseline,
107
- });
108
- payload = renderReport(result, { format, mode, cwd });
109
- findings = result.audit.summary.findings;
110
- break;
111
- case 'verify':
112
- result = await verify({ cwd, workflows, token });
113
- payload = renderVerify(result, { format, cwd });
114
- break;
115
- case 'org-scan':
116
- if (!organization) throw new Error('organization is required for org-scan');
117
- if (checkpointPath && resumeFrom) {
118
- throw new Error('checkpoint-path and resume-from cannot be used together');
119
- }
120
- if (
121
- (resumeFrom ?? checkpointPath)
122
- && input('output-path')
123
- && await sameFilePath(
124
- resolve(cwd, resumeFrom ?? checkpointPath),
125
- resolve(cwd, input('output-path')),
126
- )
127
- ) throw new Error('checkpoint and report output paths must be different');
128
- result = await scanOrganization({
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
- checkpointPath: resumeFrom ?? checkpointPath,
144
- resume: Boolean(resumeFrom),
145
- onProgress: progress
146
- ? event => {
147
- const message = formatOrganizationProgress(event);
148
- if (message) process.stderr.write(message);
149
- }
150
- : undefined,
151
- });
152
- payload = renderOrganizationScan(result, { format, cwd });
153
- findings = result.summary.findings;
154
- break;
155
- case 'rules': {
156
- const rules = listRules();
157
- result = { status: 'OK' };
158
- payload = renderFormat(
159
- format,
160
- rules.map(rule => ({ label: 'RULE', fields: rule })),
161
- { status: 'OK', json: { schemaVersion: '1.0', rules, status: 'OK' } },
162
- );
163
- break;
164
- }
165
- default:
166
- throw new Error(`unknown command: ${command}`);
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
- process.stdout.write(payload);
170
- const annotationResult = annotationsEnabled
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
- let reportPath = '';
177
- const requestedOutput = input('output-path');
178
- if (requestedOutput) {
179
- reportPath = resolve(cwd, requestedOutput);
180
- await writeFileGuarded({
181
- path: reportPath,
182
- content: payload,
183
- dryRun: false,
184
- cwd,
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 setOutput('findings', String(findings));
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
- if (reportPath) await setOutput('report-path', reportPath);
193
- await writeSummary({
354
+ await setOutput('report-path', reportPath);
355
+ await setOutput('checkpoint-path', checkpointPath);
356
+ await appendSummary(renderActionSummary({
194
357
  command,
195
- status: result.status,
196
- findings,
358
+ result,
359
+ cwd,
360
+ metrics,
197
361
  annotations: annotationResult.emitted.length,
198
362
  annotationsSkipped: annotationResult.omitted,
199
- payload,
200
- });
201
-
202
- if (shouldFailAction({ command, result, failOnFindings })) {
203
- process.exitCode = 1;
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 writeSummary({
269
- command,
270
- status,
271
- findings,
272
- annotations,
273
- annotationsSkipped,
274
- payload,
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
- `### actions-warden (${command})\n\nstatus: \`${status}\` findings: \`${findings}\` annotations: \`${annotations}\` skipped: \`${annotationsSkipped}\`\n\n${indented}\n`,
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 = redact(String(error?.message ?? error));
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 setOutput('findings', '0').catch(() => {});
303
- await setOutput('annotations', annotationsEnabled ? '1' : '0').catch(() => {});
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
  });