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.
Files changed (78) hide show
  1. package/AGENTS.md +60 -12
  2. package/CONTRIBUTING.md +6 -2
  3. package/README.md +180 -58
  4. package/RELEASING.md +3 -2
  5. package/SECURITY.md +23 -8
  6. package/docs/AI-AGENTS.md +125 -29
  7. package/docs/CLI.md +346 -69
  8. package/docs/CONFIGURATION.md +34 -11
  9. package/docs/DEVELOPMENT.md +114 -18
  10. package/docs/GITHUB-ACTION.md +163 -29
  11. package/docs/JAVASCRIPT-API.md +177 -11
  12. package/docs/OUTPUTS.md +408 -40
  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 +91 -39
  35. package/src/action.js +353 -187
  36. package/src/cli.js +416 -209
  37. package/src/commands/audit.js +17 -30
  38. package/src/commands/org-scan.js +452 -286
  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 +159 -35
  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/path-equality.js +30 -0
  69. package/src/lib/paths.js +18 -1
  70. package/src/lib/redact.js +58 -7
  71. package/src/lib/resolver.js +66 -9
  72. package/src/lib/types.js +137 -0
  73. package/src/lib/writer.js +3 -0
  74. package/src/rules/pull-request-target-checkout.js +5 -0
  75. package/src/rules/unpinned-action.js +2 -3
  76. package/src/rules/workflow-structure.js +2 -4
  77. package/src/version.js +1 -1
  78. 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, realpath } from 'node:fs/promises';
4
- import { basename, dirname, join, resolve } from 'node:path';
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 { formatOrganizationProgress } from './lib/org-progress.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';
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 format = input('format') || 'toon';
32
- const cwd = resolve(input('working-directory') || process.env.GITHUB_WORKSPACE || process.cwd());
33
- const workflows = parseStringList(input('workflow'), 'workflow');
34
- const token = input('token') || undefined;
35
- const severity = optionalChoice(input('severity'), SEVERITIES, 'severity');
36
- const mode = choice(input('mode') || 'minor', MODES, 'mode');
37
- const minAgeDays = nonNegativeInteger(input('min-age') || '7', 'min-age');
38
- const explain = booleanInput('explain', false);
39
- const offline = booleanInput('offline', false);
40
- const write = booleanInput('write', false);
41
- const failOnFindings = booleanInput('fail-on-findings', true);
42
- const annotationsEnabled = booleanInput('annotations', true);
43
- const fix = input('fix') || undefined;
44
- const configPath = input('config') || undefined;
45
- const ignoreConfig = booleanInput('ignore-config', false);
46
- const baseline = input('baseline') || undefined;
47
- const organization = input('organization') || undefined;
48
- const repositories = parseStringList(input('repository'), 'repository');
49
- const visibility = choice(input('visibility') || 'all', VISIBILITIES, 'visibility');
50
- const includeArchived = booleanInput('include-archived', false);
51
- const includeDisabled = booleanInput('include-disabled', false);
52
- const includeForks = booleanInput('include-forks', false);
53
- const maxRepositories = optionalPositiveInteger(input('max-repos'), 'max-repos');
54
- const concurrency = positiveInteger(input('concurrency') || '4', 'concurrency');
55
- const checkpointPath = input('checkpoint-path') || undefined;
56
- const resumeFrom = input('resume-from') || undefined;
57
- 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
+ }
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
- let result;
62
- let payload;
63
- 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
+ ]);
64
126
 
65
- switch (command) {
66
- case 'audit':
67
- result = await audit({
68
- cwd,
69
- workflows,
70
- severity,
71
- explain,
72
- configPath: ignoreConfig ? false : configPath,
73
- baseline,
74
- });
75
- payload = renderAudit(result, { format, explain, cwd });
76
- findings = result.summary.findings;
77
- break;
78
- case 'pin':
79
- result = await pin({ cwd, workflows, dryRun: !write, token, fix });
80
- payload = renderPin(result, { format, dryRun: !write, cwd });
81
- break;
82
- case 'upgrade':
83
- result = await upgrade({
84
- cwd,
85
- workflows,
86
- dryRun: !write,
87
- token,
88
- mode,
89
- minAgeDays,
90
- fix,
91
- });
92
- payload = renderUpgrade(result, { format, dryRun: !write, mode, cwd });
93
- break;
94
- case 'report':
95
- result = await report({
96
- cwd,
97
- workflows,
98
- token,
99
- mode,
100
- severity,
101
- explain,
102
- skipResolve: offline,
103
- minAgeDays,
104
- configPath: ignoreConfig ? false : configPath,
105
- baseline,
106
- });
107
- payload = renderReport(result, { format, mode, cwd });
108
- findings = result.audit.summary.findings;
109
- break;
110
- case 'verify':
111
- result = await verify({ cwd, workflows, token });
112
- payload = renderVerify(result, { format, cwd });
113
- break;
114
- case 'org-scan':
115
- if (!organization) throw new Error('organization is required for org-scan');
116
- if (checkpointPath && resumeFrom) {
117
- throw new Error('checkpoint-path and resume-from cannot be used together');
118
- }
119
- if (
120
- (resumeFrom ?? checkpointPath)
121
- && input('output-path')
122
- && await samePath(
123
- resolve(cwd, resumeFrom ?? checkpointPath),
124
- resolve(cwd, input('output-path')),
125
- )
126
- ) throw new Error('checkpoint and report output paths must be different');
127
- 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: {
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
- checkpointPath: resumeFrom ?? checkpointPath,
143
- resume: Boolean(resumeFrom),
144
- onProgress: progress
145
- ? event => {
146
- const message = formatOrganizationProgress(event);
147
- if (message) process.stderr.write(message);
148
- }
149
- : undefined,
150
- });
151
- payload = renderOrganizationScan(result, { format, cwd });
152
- findings = result.summary.findings;
153
- break;
154
- case 'rules': {
155
- const rules = listRules();
156
- result = { status: 'OK' };
157
- payload = renderFormat(
158
- format,
159
- rules.map(rule => ({ label: 'RULE', fields: rule })),
160
- { status: 'OK', json: { schemaVersion: '1.0', rules, status: 'OK' } },
161
- );
162
- break;
163
- }
164
- default:
165
- 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();
166
304
  }
305
+ }
167
306
 
168
- process.stdout.write(payload);
169
- 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
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
- let reportPath = '';
176
- const requestedOutput = input('output-path');
177
- if (requestedOutput) {
178
- reportPath = resolve(cwd, requestedOutput);
179
- await writeFileGuarded({
180
- path: reportPath,
181
- content: payload,
182
- dryRun: false,
183
- cwd,
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 setOutput('findings', String(findings));
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
- if (reportPath) await setOutput('report-path', reportPath);
192
- await writeSummary({
354
+ await setOutput('report-path', reportPath);
355
+ await setOutput('checkpoint-path', checkpointPath);
356
+ await appendSummary(renderActionSummary({
193
357
  command,
194
- status: result.status,
195
- findings,
358
+ result,
359
+ cwd,
360
+ metrics,
196
361
  annotations: annotationResult.emitted.length,
197
362
  annotationsSkipped: annotationResult.omitted,
198
- payload,
199
- });
200
-
201
- if (shouldFailAction({ command, result, failOnFindings })) {
202
- process.exitCode = 1;
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 writeSummary({
280
- command,
281
- status,
282
- findings,
283
- annotations,
284
- annotationsSkipped,
285
- payload,
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
- `### actions-warden (${command})\n\nstatus: \`${status}\` findings: \`${findings}\` annotations: \`${annotations}\` skipped: \`${annotationsSkipped}\`\n\n${indented}\n`,
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 = redact(String(error?.message ?? error));
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 setOutput('findings', '0').catch(() => {});
314
- 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(() => {});
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
  });