strict.mjs RawHistoryFolder
1// SPDX-License-Identifier: MIT
2//
3// Generates testdata/strict.json: for each file in testdata/cases/*.yml, the
4// errors that @actions/workflow-parser 0.3.61 (MIT, GitHub,
5// actions/languageservices) reports when it parses the file with parseAction
6// (schema "action-root-strict") and converts it with convertActionTemplate
7// (which validates the pre-if and post-if conditions and the step conditions).
8// strict_test.go replays the answers against ParseStrict.
9//
10// action/gen/regen.sh
11
12import { pathToFileURL } from "node:url";
13import path from "node:path";
14import fs from "node:fs";
15
16const dist = path.resolve(process.argv[2] ?? new URL("../../gen/node_modules/@actions/workflow-parser/dist", import.meta.url).pathname);
17const imp = p => import(pathToFileURL(path.join(dist, p)).href);
18const { parseAction } = await imp("actions/action-parser.js");
19const { convertActionTemplate } = await imp("actions/action-template.js");
20const { NoOperationTraceWriter } = await imp("templates/trace-writer.js");
21
22const dir = new URL("../testdata/cases/", import.meta.url);
23const out = {};
24for (const f of fs.readdirSync(dir).sort()) {
25 if (!f.endsWith(".yml")) continue;
26 const content = fs.readFileSync(new URL(f, dir), "utf8");
27 const r = parseAction({ name: f, content }, new NoOperationTraceWriter());
28 const res = { errors: [] };
29 if (r.value) {
30 // Default error policy: the conversion only runs on a document without
31 // schema errors, and adds its own (pre-if, post-if, step conditions).
32 const t = convertActionTemplate(r.context, r.value);
33 res.name = t.name; res.description = t.description; res.author = t.author;
34 res.inputs = (t.inputs || []).map(i => ({ id: i.id, required: i.required, deprecationMessage: i.deprecationMessage, default: i.default === undefined ? undefined : String(i.default) }));
35 res.outputs = (t.outputs || []).map(o => ({ id: o.id, value: o.value === undefined ? undefined : String(o.value) }));
36 res.runs = { using: t.runs?.using, main: t.runs?.main, image: t.runs?.image, preIf: t.runs?.preIf, postIf: t.runs?.postIf, steps: (t.runs?.steps || []).length };
37 }
38 res.errors = r.context.errors.getErrors().map(e => e.message);
39 out[f] = res;
40}
41console.log(JSON.stringify(out, null, 1));