@r_masseater/fu4 0.3.9 → 0.4.1

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.
@@ -0,0 +1,1592 @@
1
+ import { n as defineRule } from "./define-Dvnt_9zv.mjs";
2
+ import { Array, Function, Option, Order, Predicate, Record, Result, String as String$1, pipe } from "effect";
3
+ // src/app/presets/shared/text/number.ts
4
+ const ZERO$2 = 0;
5
+ const EXPONENT_ABOVE = 1e21;
6
+ const EXPONENT_BELOW = 1e-4;
7
+ const SIGNS = /^[+-]*/u;
8
+ const FLOAT_CHARS = /^[\d.eE+-]+$/u;
9
+ const INFINITE = /* @__PURE__ */ new Set(["inf", "infinity"]);
10
+ const DIGITS = /^[+-]?\d+$/u;
11
+ const MAX_SIGNS = 1;
12
+ const INT64_MIN = BigInt("-9223372036854775808");
13
+ const INT64_MAX = 9223372036854775807n;
14
+ const nonFinite = (value) => {
15
+ if (Number.isNaN(value)) return "NaN";
16
+ if (value < ZERO$2) return "-inf";
17
+ return "inf";
18
+ };
19
+ const goFloat = (value) => {
20
+ if (!Number.isFinite(value)) return nonFinite(value);
21
+ if (Number.isInteger(value) && Math.abs(value) < EXPONENT_ABOVE) return value.toFixed(ZERO$2);
22
+ if (Math.abs(value) >= EXPONENT_ABOVE || value !== ZERO$2 && Math.abs(value) < EXPONENT_BELOW) return value.toExponential();
23
+ return String(value);
24
+ };
25
+ const infinite = (text) => {
26
+ if (String$1.startsWith("-")(text)) return Number.NEGATIVE_INFINITY;
27
+ return Number.POSITIVE_INFINITY;
28
+ };
29
+ const special = (text) => {
30
+ const lower = pipe(text, String$1.replace(SIGNS, ""), String$1.toLowerCase);
31
+ if (INFINITE.has(lower)) return Option.some(infinite(text));
32
+ if (lower === "nan") return Option.some(NaN);
33
+ return Option.none();
34
+ };
35
+ const plainFloat = (text) => {
36
+ const body = String$1.replace(SIGNS, "")(text);
37
+ const hex = pipe(body, String$1.toLowerCase, String$1.startsWith("0x"));
38
+ if (text.length - body.length > MAX_SIGNS || String$1.includes("_")(text) || hex || !FLOAT_CHARS.test(body)) return Option.none();
39
+ return Option.liftPredicate(Number(text), (value) => !Number.isNaN(value));
40
+ };
41
+ const parseGoFloat = (text) => Option.orElse(special(text), () => plainFloat(text));
42
+ const atoi = (text) => {
43
+ if (!DIGITS.test(text)) return "invalid syntax";
44
+ const value = BigInt(text);
45
+ if (value < INT64_MIN || value > INT64_MAX) return "value out of range";
46
+ return Number(value);
47
+ };
48
+ // src/app/presets/shared/text/quote.ts
49
+ const ESCAPES = {
50
+ "\x07": String.raw`\a`,
51
+ "\b": String.raw`\b`,
52
+ "\f": String.raw`\f`,
53
+ "\n": String.raw`\n`,
54
+ "\r": String.raw`\r`,
55
+ " ": String.raw`\t`,
56
+ "\v": String.raw`\v`,
57
+ "\\": String.raw`\\`
58
+ };
59
+ const ASCII_END = 128;
60
+ const BMP_END = 65536;
61
+ const BYTE_DIGITS = 2;
62
+ const SHORT_DIGITS = 4;
63
+ const LONG_DIGITS = 8;
64
+ const HEX = 16;
65
+ const FIRST$1 = 0;
66
+ const UNPRINTABLE = /[\p{Cc}\p{Z}\uFEFF\uFFF9-\uFFFB\uE000-\uF8FF\u2028\u2029]/u;
67
+ const SPACE = " ";
68
+ const SEPARATOR = ", ";
69
+ const hex = (code, digits) => String$1.padStart(digits, "0")(code.toString(HEX));
70
+ const unicodeEscape = (code) => {
71
+ if (code < ASCII_END) return `\\x${hex(code, BYTE_DIGITS)}`;
72
+ if (code < BMP_END) return `\\u${hex(code, SHORT_DIGITS)}`;
73
+ return `\\U${hex(code, LONG_DIGITS)}`;
74
+ };
75
+ const escapeChar = (delimiter) => (character) => Option.getOrElse(Record.get(ESCAPES, character), () => {
76
+ if (character === delimiter) return `\\${character}`;
77
+ if (character !== SPACE && UNPRINTABLE.test(character)) return unicodeEscape(Option.getOrElse(String$1.codePointAt(FIRST$1)(character), () => FIRST$1));
78
+ return character;
79
+ });
80
+ const codePoints = (text) => {
81
+ const points = [];
82
+ for (const point of text) points.push(point);
83
+ return points;
84
+ };
85
+ const escaped = (text, delimiter) => pipe(codePoints(text), Array.map(escapeChar(delimiter)), Array.join(""));
86
+ const quote = (text) => `"${escaped(text, "\"")}"`;
87
+ const quoteChar = (character) => `'${escaped(character, "'")}'`;
88
+ const quotes = (items) => pipe(items, Array.map(quote), Array.join(SEPARATOR));
89
+ const sortedQuotes = (items) => quotes(Array.sort(items, Order.String));
90
+ const TEEN_START = 11;
91
+ const TEEN_END = 13;
92
+ const TEN = 10;
93
+ const HUNDRED = 100;
94
+ const SUFFIXES = {
95
+ 1: "st",
96
+ 2: "nd",
97
+ 3: "rd"
98
+ };
99
+ const ordinal = (value) => {
100
+ if (value % HUNDRED >= TEEN_START && value % HUNDRED <= TEEN_END) return `${String(value)}th`;
101
+ return `${String(value)}${Option.getOrElse(Record.get(SUFFIXES, String(value % TEN)), () => "th")}`;
102
+ };
103
+ // src/app/presets/shared/yaml/node.ts
104
+ const PAIR = 2;
105
+ const KEY = 0;
106
+ const VALUE = 1;
107
+ const isQuoted = (node) => node.style === "single-quoted" || node.style === "double-quoted";
108
+ const isNull = (node) => node.kind === "scalar" && node.tag === "!!null";
109
+ const pairsOf = (node) => {
110
+ if (node.kind !== "mapping") return [];
111
+ return pipe(Array.chunksOf(node.children, PAIR), Array.flatMap((chunk) => pipe(Option.all([Array.get(chunk, KEY), Array.get(chunk, VALUE)]), Option.map(([key, value]) => ({
112
+ key,
113
+ value
114
+ })), Option.toArray)));
115
+ };
116
+ const keysOf = (node) => pipe(pairsOf(node), Array.map((pair) => pair.key.value));
117
+ const valueAt = (key) => (node) => pipe(pairsOf(node), Array.findFirst((pair) => pair.key.value === key), Option.map((pair) => pair.value));
118
+ const textOf = (node) => ({
119
+ value: node.value,
120
+ quoted: isQuoted(node),
121
+ line: node.line,
122
+ column: node.column
123
+ });
124
+ const describePosition = (position) => `line:${String(position.line)},col:${String(position.column)}`;
125
+ const readYaml = (read) => (source) => pipe(Array.head(source.errors), Option.match({
126
+ onNone: () => read(source),
127
+ onSome: (error) => Result.fail(`yaml: line ${String(error.line)}: ${error.message}`)
128
+ }));
129
+ // src/app/presets/features/check-workflows/lib/step.ts
130
+ const runOf = (step) => pipe(Option.fromNullishOr(step.exec), Option.flatMap((exec) => {
131
+ if (exec.type === "run") return Option.some(exec);
132
+ return Option.none();
133
+ }));
134
+ const actionOf = (step) => pipe(Option.fromNullishOr(step.exec), Option.flatMap((exec) => {
135
+ if (exec.type === "action") return Option.some(exec);
136
+ return Option.none();
137
+ }));
138
+ // src/app/presets/entities/workflow/lib/expression-text.ts
139
+ const OPEN = "${{";
140
+ const CLOSE = "}}";
141
+ const SINGLE = 2;
142
+ const containsExpression = (text) => Option.match(Option.all([String$1.indexOf(OPEN)(text), String$1.indexOf(CLOSE)(text)]), {
143
+ onNone: () => false,
144
+ onSome: ([open, close]) => open < close
145
+ });
146
+ const isExpressionAssigned = (text) => {
147
+ const trimmed = String$1.trim(text);
148
+ return String$1.startsWith(OPEN)(trimmed) && String$1.endsWith(CLOSE)(trimmed) && String$1.split(OPEN)(trimmed).length === SINGLE;
149
+ };
150
+ // src/app/presets/shared/record/optional.ts
151
+ const optional = (key) => (value) => Option.match(value, {
152
+ onNone: () => ({}),
153
+ onSome: (present) => Record.singleton(key, present)
154
+ });
155
+ // src/app/presets/entities/workflow/lib/scalar.ts
156
+ const ZERO$1 = 0;
157
+ const FLOAT_TAGS = /* @__PURE__ */ new Set([
158
+ "!!float",
159
+ "!!int",
160
+ "!!str"
161
+ ]);
162
+ const nodeShape = (node) => `${node.kind} node with ${quote(node.tag)} tag`;
163
+ const emptyText = (node) => ({
164
+ value: "",
165
+ quoted: false,
166
+ line: node.line,
167
+ column: node.column
168
+ });
169
+ const checkString = (sink) => (node, allowEmpty) => {
170
+ if (node.kind !== "scalar") {
171
+ sink.error(node, `expected scalar node for string value but found ${nodeShape(node)}`);
172
+ return false;
173
+ }
174
+ if (!allowEmpty && node.value === "") {
175
+ sink.error(node, "string should not be empty");
176
+ return false;
177
+ }
178
+ return true;
179
+ };
180
+ const parseString = (sink) => (node, allowEmpty) => {
181
+ if (!checkString(sink)(node, allowEmpty)) return emptyText(node);
182
+ return textOf(node);
183
+ };
184
+ const parseExpression = (sink) => (node, expecting) => {
185
+ if (!isExpressionAssigned(node.value)) {
186
+ sink.error(node, `expecting a single \${{...}} expression or ${expecting}, but found plain text node`);
187
+ return Option.none();
188
+ }
189
+ return Option.some(textOf(node));
190
+ };
191
+ const mayParseExpression = (node) => pipe(Option.liftPredicate(node, (value) => value.tag === "!!str" && isExpressionAssigned(value.value)), Option.map(textOf));
192
+ const parseBool = (sink) => (node) => {
193
+ if (node.kind !== "scalar" || node.tag !== "!!bool" && node.tag !== "!!str") {
194
+ sink.error(node, `expected bool value but found ${nodeShape(node)}`);
195
+ return Option.none();
196
+ }
197
+ const at = {
198
+ line: node.line,
199
+ column: node.column
200
+ };
201
+ if (node.tag === "!!str") {
202
+ const expression = parseExpression(sink)(node, "boolean literal \"true\" or \"false\"");
203
+ return Option.some({
204
+ ...at,
205
+ value: false,
206
+ ...optional("expression")(expression)
207
+ });
208
+ }
209
+ return Option.some({
210
+ ...at,
211
+ value: node.value === "true"
212
+ });
213
+ };
214
+ const fromExpression = (expression) => pipe(expression, Option.map((text) => ({
215
+ value: ZERO$1,
216
+ expression: text
217
+ })));
218
+ const integerLiteral = (sink) => (node) => {
219
+ const parsed = atoi(node.value);
220
+ if (typeof parsed === "string") {
221
+ const shown = quote(node.value);
222
+ sink.error(node, `invalid integer value: ${shown}: strconv.Atoi: parsing ${shown}: ${parsed}`);
223
+ return Option.none();
224
+ }
225
+ return Option.some({ value: parsed });
226
+ };
227
+ const parseInteger = (sink) => (node) => {
228
+ if (node.kind !== "scalar" || node.tag !== "!!int" && node.tag !== "!!str") {
229
+ sink.error(node, `expected scalar node for integer value but found ${nodeShape(node)}`);
230
+ return Option.none();
231
+ }
232
+ if (node.tag === "!!str") return fromExpression(parseExpression(sink)(node, "integer literal"));
233
+ return integerLiteral(sink)(node);
234
+ };
235
+ const parseNumber = (sink) => (node) => {
236
+ if (node.kind !== "scalar" || !FLOAT_TAGS.has(node.tag)) {
237
+ sink.error(node, `expected scalar node for float value but found ${nodeShape(node)}`);
238
+ return Option.none();
239
+ }
240
+ if (node.tag === "!!str") return fromExpression(parseExpression(sink)(node, "float number literal"));
241
+ const parsed = pipe(parseGoFloat(node.value), Option.filter((value) => !Number.isNaN(value)));
242
+ if (Option.isNone(parsed)) {
243
+ const shown = quote(node.value);
244
+ sink.error(node, `invalid float value: ${shown}: strconv.ParseFloat: parsing ${shown}: invalid syntax`);
245
+ }
246
+ return pipe(parsed, Option.map((value) => ({ value })));
247
+ };
248
+ const parseTimeoutMinutes = (sink) => (node) => {
249
+ const parsed = parseNumber(sink)(node);
250
+ if (Option.isSome(parsed) && Predicate.isUndefined(parsed.value.expression) && parsed.value.value <= ZERO$1) sink.error(node, `value at "timeout-minutes" must be greater than zero: ${goFloat(parsed.value.value)}`);
251
+ return parsed;
252
+ };
253
+ // src/app/presets/entities/workflow/lib/sequence.ts
254
+ const EMPTY$1 = 0;
255
+ const ONE = 1;
256
+ const sectionName = (section) => {
257
+ if (String$1.includes(" ")(section)) return section;
258
+ return `${quote(section)} section`;
259
+ };
260
+ const unexpectedMessage = (input) => {
261
+ const section = sectionName(input.section);
262
+ const key = quote(input.key.value);
263
+ const [first] = input.expected;
264
+ if (input.expected.length === ONE && Predicate.isNotUndefined(first)) return `expected ${quote(first)} key for ${section} but got ${key}`;
265
+ if (input.expected.length === EMPTY$1) return `unexpected key ${key} for ${section}`;
266
+ return `unexpected key ${key} for ${section}. expected one of ${sortedQuotes(input.expected)}`;
267
+ };
268
+ const unexpectedKey = (sink) => (input) => {
269
+ sink.error(input.key, unexpectedMessage(input));
270
+ };
271
+ const reportEmpty = (sink) => (section, node) => {
272
+ sink.error(node, `${quote(section)} section should not be empty`);
273
+ };
274
+ const checkNotEmpty = (sink) => (section, node) => {
275
+ if (node.children.length === EMPTY$1) {
276
+ reportEmpty(sink)(section, node);
277
+ return false;
278
+ }
279
+ return true;
280
+ };
281
+ const checkSequence = (sink) => (input) => {
282
+ const { node, section } = input;
283
+ if (node.kind !== "sequence") {
284
+ sink.error(node, `${quote(section)} section must be sequence node but got ${node.kind} node with ${quote(node.tag)} tag`);
285
+ return false;
286
+ }
287
+ return input.allowEmpty || checkNotEmpty(sink)(section, node);
288
+ };
289
+ const parseStringSequence = (sink) => (input) => {
290
+ if (!checkSequence(sink)(input)) return [];
291
+ return pipe(input.node.children, Array.map((child) => parseString(sink)(child, input.allowElementEmpty)));
292
+ };
293
+ const parseStringOrSequence = (sink) => (input) => {
294
+ const { node } = input;
295
+ if (node.kind !== "scalar") return parseStringSequence(sink)(input);
296
+ if (input.allowEmpty && node.tag === "!!null") return [];
297
+ return [parseString(sink)(node, input.allowElementEmpty)];
298
+ };
299
+ // src/app/presets/entities/workflow/lib/fold.ts
300
+ const foldEntries = (input) => {
301
+ const table = Record.fromEntries(input.handlers);
302
+ return Array.reduce(input.entries, input.initial, (state, entry) => Option.getOrElse(Record.get(table, entry.id), () => input.unknown)(state, entry));
303
+ };
304
+ const rejecting = (input) => (state, entry) => {
305
+ unexpectedKey(input.sink)({
306
+ key: entry.key,
307
+ section: input.section,
308
+ expected: input.expected
309
+ });
310
+ return state;
311
+ };
312
+ const setters = () => ({
313
+ set: (key, parse) => (state, entry) => ({
314
+ ...state,
315
+ [key]: parse(entry)
316
+ }),
317
+ setSome: (key, parse) => (state, entry) => Option.match(parse(entry), {
318
+ onNone: () => state,
319
+ onSome: (value) => ({
320
+ ...state,
321
+ [key]: value
322
+ })
323
+ })
324
+ });
325
+ const keep = (state) => state;
326
+ // ../lint-host/src/shared/lib/collections.ts
327
+ const byKey = Order.mapInput(String$1.Order, ([key]) => key);
328
+ const sortedRecord = (entries) => Record.fromEntries(Array.sort(entries, byKey));
329
+ const ancestorsBy = (parentOf) => (node) => Array.unfold(parentOf(node), (current) => pipe(current, Option.map((found) => [found, parentOf(found)])));
330
+ // src/app/presets/entities/workflow/lib/mapping.ts
331
+ const MERGE_KEY = "<<";
332
+ const EMPTY = 0;
333
+ const emptyMessage = (place) => `${place} should not be empty. please remove this section if it's unnecessary`;
334
+ const caseNote = (caseSensitive) => {
335
+ if (caseSensitive) return "";
336
+ return ". note that this key is case insensitive";
337
+ };
338
+ const duplicateMessage = (input, key, previous) => {
339
+ const note = caseNote(input.caseSensitive);
340
+ return `key ${quote(key.value)} is duplicated in ${input.place}. previously defined at ${describePosition(previous)}${note}`;
341
+ };
342
+ const idOf = (input, key) => {
343
+ if (input.caseSensitive) return key.value;
344
+ return String$1.toLowerCase(key.value);
345
+ };
346
+ const collectPair = (sink, input) => (collected, pair) => {
347
+ const key = parseString(sink)(pair.key, false);
348
+ const id = idOf(input, key);
349
+ if (key.value === MERGE_KEY) {
350
+ sink.error(key, `GitHub Actions does not support YAML merge key "${MERGE_KEY}"`);
351
+ return collected;
352
+ }
353
+ return Option.match(Record.get(collected.seen, id), {
354
+ onSome: (previous) => {
355
+ sink.error(key, duplicateMessage(input, key, previous));
356
+ return collected;
357
+ },
358
+ onNone: () => ({
359
+ seen: {
360
+ ...collected.seen,
361
+ [id]: key
362
+ },
363
+ entries: [...collected.entries, {
364
+ id,
365
+ key,
366
+ value: pair.value
367
+ }]
368
+ })
369
+ });
370
+ };
371
+ const nonMapping = (sink, input) => {
372
+ const { node, place } = input;
373
+ if (node.kind === "scalar" && node.tag === "!!null") {
374
+ if (!input.allowEmpty) sink.error(node, emptyMessage(place));
375
+ return true;
376
+ }
377
+ if (node.kind !== "mapping") {
378
+ sink.error(node, `${place} is ${node.kind} node but mapping node is expected`);
379
+ return true;
380
+ }
381
+ return false;
382
+ };
383
+ const parseMapping = (sink) => (input) => {
384
+ if (nonMapping(sink, input)) return [];
385
+ const { entries } = Array.reduce(pairsOf(input.node), {
386
+ seen: {},
387
+ entries: []
388
+ }, collectPair(sink, input));
389
+ if (!input.allowEmpty && entries.length === EMPTY) sink.error(input.node, emptyMessage(input.place));
390
+ return entries;
391
+ };
392
+ const sectionWith = (flags) => (sink) => (section, node) => parseMapping(sink)({
393
+ ...flags,
394
+ node,
395
+ place: `${quote(section)} section`
396
+ });
397
+ const section = sectionWith({
398
+ allowEmpty: false,
399
+ caseSensitive: true
400
+ });
401
+ const caselessSection = sectionWith({
402
+ allowEmpty: false,
403
+ caseSensitive: false
404
+ });
405
+ const emptyableSection = sectionWith({
406
+ allowEmpty: true,
407
+ caseSensitive: true
408
+ });
409
+ const emptyableCaselessSection = sectionWith({
410
+ allowEmpty: true,
411
+ caseSensitive: false
412
+ });
413
+ const entryText = (sink) => (allowEmpty) => (entry) => parseString(sink)(entry.value, allowEmpty);
414
+ const entryRecord = (parse) => (entries) => sortedRecord(pipe(entries, Array.map((entry) => [entry.id, parse(entry)])));
415
+ // src/app/presets/entities/workflow/lib/sink.ts
416
+ const reportMissing = (sink) => (value, at, message) => {
417
+ if (Predicate.isUndefined(value)) sink.error(at, message);
418
+ };
419
+ // src/app/presets/entities/workflow/lib/runner.ts
420
+ const labels = (sink) => (name, node) => parseStringOrSequence(sink)({
421
+ section: name,
422
+ node,
423
+ allowEmpty: false,
424
+ allowElementEmpty: false
425
+ });
426
+ const labelsHandler = (sink) => (state, entry) => Option.match(mayParseExpression(entry.value), {
427
+ onSome: (expression) => ({
428
+ ...state,
429
+ labelsExpression: expression
430
+ }),
431
+ onNone: () => ({
432
+ ...state,
433
+ labels: labels(sink)("labels", entry.value)
434
+ })
435
+ });
436
+ const parseRunsOn = (sink) => (node) => {
437
+ const expression = mayParseExpression(node);
438
+ if (Option.isSome(expression)) return {
439
+ labels: [],
440
+ labelsExpression: expression.value
441
+ };
442
+ if (node.kind === "scalar" || node.kind === "sequence") return { labels: labels(sink)("runs-on", node) };
443
+ return foldEntries({
444
+ entries: section(sink)("runs-on", node),
445
+ initial: { labels: [] },
446
+ handlers: [["labels", labelsHandler(sink)], ["group", setters().set("group", entryText(sink)(false))]],
447
+ unknown: rejecting({
448
+ sink,
449
+ section: "runs-on",
450
+ expected: ["labels", "group"]
451
+ })
452
+ });
453
+ };
454
+ const snapshotMapping = (sink) => (at, node) => {
455
+ const { set } = setters();
456
+ const snapshot = foldEntries({
457
+ entries: section(sink)("on", node),
458
+ initial: {},
459
+ handlers: [
460
+ ["image-name", set("imageName", entryText(sink)(false))],
461
+ ["version", set("version", entryText(sink)(false))],
462
+ ["if", set("condition", entryText(sink)(false))]
463
+ ],
464
+ unknown: rejecting({
465
+ sink,
466
+ section: "snapshot",
467
+ expected: [
468
+ "image-name",
469
+ "version",
470
+ "if"
471
+ ]
472
+ })
473
+ });
474
+ reportMissing(sink)(snapshot.imageName, at, "\"snapshot\" section must have \"image-name\" configuration");
475
+ return snapshot;
476
+ };
477
+ const parseSnapshot = (sink) => (at, node) => {
478
+ if (node.kind === "scalar") return Option.some({ imageName: parseString(sink)(node, false) });
479
+ if (node.kind === "mapping") return Option.some(snapshotMapping(sink)(at, node));
480
+ sink.error(node, `"snapshot" section value must be string or mapping but found ${node.kind} node`);
481
+ return Option.none();
482
+ };
483
+ const parseCallValues = (sink) => (name, node) => entryRecord((entry) => ({
484
+ name: entry.key,
485
+ value: parseString(sink)(entry.value, true)
486
+ }))(caselessSection(sink)(name, node));
487
+ // src/app/presets/entities/workflow/lib/job-fields.ts
488
+ const forJob = (handler) => (state, entry) => ({
489
+ ...state,
490
+ job: handler(state.job, entry)
491
+ });
492
+ const stepsOnly = (handler) => (state, entry) => ({
493
+ ...forJob(handler)(state, entry),
494
+ stepsOnly: entry.key
495
+ });
496
+ const callOnly = (handler) => (state, entry) => ({
497
+ ...state,
498
+ call: handler(state.call, entry),
499
+ callOnly: entry.key
500
+ });
501
+ const needs = (sink) => (entry) => {
502
+ if (entry.value.kind === "scalar") return [parseString(sink)(entry.value, false)];
503
+ return parseStringSequence(sink)({
504
+ section: "needs",
505
+ node: entry.value,
506
+ allowEmpty: false,
507
+ allowElementEmpty: false
508
+ });
509
+ };
510
+ const callSecrets = (sink) => (call, entry) => {
511
+ const node = entry.value;
512
+ if (node.kind !== "scalar") return {
513
+ ...call,
514
+ secrets: parseCallValues(sink)("secrets", node)
515
+ };
516
+ if (node.value === "inherit") return {
517
+ ...call,
518
+ inheritSecrets: true
519
+ };
520
+ sink.error(node, `expected mapping node for secrets or "inherit" string node but found ${quote(node.value)} node`);
521
+ return call;
522
+ };
523
+ const emptyJob = (id) => ({
524
+ id,
525
+ needs: [],
526
+ outputs: {},
527
+ line: id.line,
528
+ column: id.column
529
+ });
530
+ // src/app/presets/entities/workflow/lib/sections.ts
531
+ const parsePermissions = (sink) => (node) => {
532
+ if (node.kind === "scalar") return {
533
+ all: parseString(sink)(node, false),
534
+ scopes: {}
535
+ };
536
+ const entries = emptyableCaselessSection(sink)("permissions", node);
537
+ return { scopes: entryRecord((entry) => ({
538
+ name: entry.key,
539
+ value: entryText(sink)(false)(entry)
540
+ }))(entries) };
541
+ };
542
+ const parseEnv = (sink) => (node) => {
543
+ if (node.kind === "scalar") return {
544
+ vars: {},
545
+ ...optional("expression")(parseExpression(sink)(node, "mapping value for \"env\" section"))
546
+ };
547
+ return { vars: entryRecord((entry) => ({
548
+ name: entry.key,
549
+ value: parseString(sink)(entry.value, true)
550
+ }))(caselessSection(sink)("env", node)) };
551
+ };
552
+ const defaultsRun = (sink) => (node) => {
553
+ const { set } = setters();
554
+ return foldEntries({
555
+ entries: section(sink)("run", node),
556
+ initial: {},
557
+ handlers: [["shell", set("shell", entryText(sink)(false))], ["working-directory", set("workingDirectory", entryText(sink)(false))]],
558
+ unknown: rejecting({
559
+ sink,
560
+ section: "run",
561
+ expected: ["shell", "working-directory"]
562
+ })
563
+ });
564
+ };
565
+ const parseDefaults = (sink) => (node) => {
566
+ const defaults = foldEntries({
567
+ entries: section(sink)("defaults", node),
568
+ initial: {},
569
+ handlers: [["run", setters().set("run", (entry) => defaultsRun(sink)(entry.value))]],
570
+ unknown: rejecting({
571
+ sink,
572
+ section: "defaults",
573
+ expected: ["run"]
574
+ })
575
+ });
576
+ reportMissing(sink)(defaults.run, node, "\"defaults\" section should have \"run\" section");
577
+ return defaults;
578
+ };
579
+ const parseConcurrency = (sink) => (at, node) => {
580
+ if (node.kind === "scalar") return { group: parseString(sink)(node, false) };
581
+ const { set, setSome } = setters();
582
+ const concurrency = foldEntries({
583
+ entries: section(sink)("concurrency", node),
584
+ initial: {},
585
+ handlers: [["group", set("group", entryText(sink)(false))], ["cancel-in-progress", setSome("cancelInProgress", (entry) => parseBool(sink)(entry.value))]],
586
+ unknown: rejecting({
587
+ sink,
588
+ section: "concurrency",
589
+ expected: ["group", "cancel-in-progress"]
590
+ })
591
+ });
592
+ reportMissing(sink)(concurrency.group, at, "group name is missing in \"concurrency\" section");
593
+ return concurrency;
594
+ };
595
+ const parseEnvironment = (sink) => (at, node) => {
596
+ if (node.kind === "scalar") return { name: parseString(sink)(node, false) };
597
+ const { set, setSome } = setters();
598
+ const environment = foldEntries({
599
+ entries: section(sink)("environment", node),
600
+ initial: {},
601
+ handlers: [
602
+ ["name", set("name", entryText(sink)(false))],
603
+ ["url", set("url", entryText(sink)(false))],
604
+ ["deployment", setSome("deployment", (entry) => parseBool(sink)(entry.value))]
605
+ ],
606
+ unknown: rejecting({
607
+ sink,
608
+ section: "environment",
609
+ expected: [
610
+ "deployment",
611
+ "name",
612
+ "url"
613
+ ]
614
+ })
615
+ });
616
+ reportMissing(sink)(environment.name, at, "name is missing in \"environment\" section");
617
+ return environment;
618
+ };
619
+ const parseOutputs = (sink) => (node) => {
620
+ const outputs = entryRecord((entry) => parseString(sink)(entry.value, true))(caselessSection(sink)("outputs", node));
621
+ if (Record.isEmptyRecord(outputs)) reportEmpty(sink)("outputs", node);
622
+ return outputs;
623
+ };
624
+ // src/app/presets/entities/workflow/lib/container.ts
625
+ const parseCredentials = (sink) => (entry) => {
626
+ const expression = mayParseExpression(entry.value);
627
+ if (Option.isSome(expression)) return Option.some({ expression: expression.value });
628
+ const { set } = setters();
629
+ const credentials = foldEntries({
630
+ entries: section(sink)("credentials", entry.value),
631
+ initial: {},
632
+ handlers: [["username", set("username", entryText(sink)(false))], ["password", set("password", entryText(sink)(false))]],
633
+ unknown: rejecting({
634
+ sink,
635
+ section: "credentials",
636
+ expected: ["username", "password"]
637
+ })
638
+ });
639
+ if (Predicate.isUndefined(credentials.username) || Predicate.isUndefined(credentials.password)) {
640
+ sink.error(entry.key, "both \"username\" and \"password\" must be specified in \"credentials\" section");
641
+ return Option.none();
642
+ }
643
+ return Option.some(credentials);
644
+ };
645
+ const strings$2 = (sink, name) => (entry) => parseStringSequence(sink)({
646
+ section: name,
647
+ node: entry.value,
648
+ allowEmpty: true,
649
+ allowElementEmpty: false
650
+ });
651
+ const CONTAINER_KEYS = [
652
+ "image",
653
+ "credentials",
654
+ "env",
655
+ "ports",
656
+ "volumes",
657
+ "options"
658
+ ];
659
+ const parseContainer = (sink) => (name, at, node) => {
660
+ if (node.kind === "scalar") return {
661
+ ports: [],
662
+ volumes: [],
663
+ image: parseString(sink)(node, false)
664
+ };
665
+ const { set, setSome } = setters();
666
+ const container = foldEntries({
667
+ entries: section(sink)(name, node),
668
+ initial: {
669
+ ports: [],
670
+ volumes: []
671
+ },
672
+ handlers: [
673
+ ["image", set("image", entryText(sink)(false))],
674
+ ["credentials", setSome("credentials", parseCredentials(sink))],
675
+ ["env", set("env", (entry) => parseEnv(sink)(entry.value))],
676
+ ["ports", set("ports", strings$2(sink, "ports"))],
677
+ ["volumes", set("volumes", strings$2(sink, "volumes"))],
678
+ ["options", set("options", entryText(sink)(true))]
679
+ ],
680
+ unknown: rejecting({
681
+ sink,
682
+ section: name,
683
+ expected: CONTAINER_KEYS
684
+ })
685
+ });
686
+ reportMissing(sink)(container.image, at, `"image" is missing in ${quote(name)} section`);
687
+ return container;
688
+ };
689
+ const parseServices = (sink) => (node) => {
690
+ const expression = mayParseExpression(node);
691
+ if (Option.isSome(expression)) return {
692
+ value: {},
693
+ expression: expression.value
694
+ };
695
+ const entries = caselessSection(sink)("services", node);
696
+ return { value: entryRecord((entry) => ({
697
+ name: entry.key,
698
+ container: parseContainer(sink)("services", entry.key, entry.value)
699
+ }))(entries) };
700
+ };
701
+ // src/app/presets/entities/workflow/lib/raw-value.ts
702
+ const rawEntries = (parse) => (entries) => sortedRecord(pipe(entries, Array.flatMap((entry) => pipe(parse(entry), Option.map((value) => [entry.id, value]), Option.toArray))));
703
+ const rawArray = (node, parse) => ({
704
+ line: node.line,
705
+ column: node.column,
706
+ type: "array",
707
+ elems: pipe(node.children, Array.flatMap((child) => Option.toArray(parse(child))))
708
+ });
709
+ const rawObject = (sink, node, parse) => {
710
+ const entries = parseMapping(sink)({
711
+ place: "matrix row value",
712
+ node,
713
+ allowEmpty: true,
714
+ caseSensitive: false
715
+ });
716
+ return {
717
+ line: node.line,
718
+ column: node.column,
719
+ type: "object",
720
+ props: rawEntries((entry) => parse(entry.value))(entries)
721
+ };
722
+ };
723
+ const parseRawValue = (sink) => (node) => {
724
+ if (node.kind === "scalar") return Option.some({
725
+ line: node.line,
726
+ column: node.column,
727
+ type: "string",
728
+ value: node.value
729
+ });
730
+ if (node.kind === "sequence") return Option.some(rawArray(node, parseRawValue(sink)));
731
+ if (node.kind === "mapping") return Option.some(rawObject(sink, node, parseRawValue(sink)));
732
+ sink.error(node, `unexpected ${node.kind} node on parsing value in matrix row`);
733
+ return Option.none();
734
+ };
735
+ // src/app/presets/entities/workflow/lib/matrix-values.ts
736
+ const combination = (sink, section) => (child) => {
737
+ if (child.kind === "scalar") return Option.map(parseExpression(sink)(child, "mapping of matrix combination"), (expression) => ({
738
+ assigns: {},
739
+ expression
740
+ }));
741
+ const entries = parseMapping(sink)({
742
+ place: `element in ${quote(section)} section`,
743
+ node: child,
744
+ allowEmpty: false,
745
+ caseSensitive: false
746
+ });
747
+ const assigns = rawEntries((entry) => Option.map(parseRawValue(sink)(entry.value), (value) => ({
748
+ key: entry.key,
749
+ value
750
+ })))(entries);
751
+ return Option.some({ assigns });
752
+ };
753
+ const combinations = (sink) => (section, entry) => {
754
+ const node = entry.value;
755
+ if (node.kind === "scalar") return Option.some({
756
+ combinations: [],
757
+ ...optional("expression")(parseExpression(sink)(node, "array of matrix combination"))
758
+ });
759
+ if (!checkSequence(sink)({
760
+ section,
761
+ node,
762
+ allowEmpty: false
763
+ })) return Option.none();
764
+ return Option.some({ combinations: pipe(node.children, Array.flatMap((child) => Option.toArray(combination(sink, section)(child)))) });
765
+ };
766
+ const row = (sink) => (entry) => {
767
+ if (entry.value.kind === "scalar") {
768
+ const expression = parseExpression(sink)(entry.value, "array value for matrix variations");
769
+ return Option.some({
770
+ values: [],
771
+ ...optional("expression")(expression)
772
+ });
773
+ }
774
+ if (!checkSequence(sink)({
775
+ section: "matrix values",
776
+ node: entry.value,
777
+ allowEmpty: false
778
+ })) return Option.none();
779
+ return Option.some({
780
+ name: entry.key,
781
+ values: pipe(entry.value.children, Array.flatMap((child) => Option.toArray(parseRawValue(sink)(child))))
782
+ });
783
+ };
784
+ // src/app/presets/entities/workflow/lib/matrix.ts
785
+ const addRow = (sink) => (state, entry) => Option.match(row(sink)(entry), {
786
+ onNone: () => state,
787
+ onSome: (value) => ({
788
+ ...state,
789
+ rows: {
790
+ ...state.rows,
791
+ [entry.id]: value
792
+ }
793
+ })
794
+ });
795
+ const emptyMatrix = (at) => ({
796
+ rows: {},
797
+ line: at.line,
798
+ column: at.column
799
+ });
800
+ const parseMatrix = (sink) => (at, node) => {
801
+ if (node.kind === "scalar") return {
802
+ ...emptyMatrix(node),
803
+ ...optional("expression")(parseExpression(sink)(node, "matrix"))
804
+ };
805
+ const { setSome } = setters();
806
+ const matrix = foldEntries({
807
+ entries: caselessSection(sink)("matrix", node),
808
+ initial: emptyMatrix(at),
809
+ handlers: [["include", setSome("include", (entry) => combinations(sink)("include", entry))], ["exclude", setSome("exclude", (entry) => combinations(sink)("exclude", entry))]],
810
+ unknown: addRow(sink)
811
+ });
812
+ return {
813
+ ...matrix,
814
+ rows: sortedRecord(Record.toEntries(matrix.rows))
815
+ };
816
+ };
817
+ // src/app/presets/entities/workflow/lib/strategy.ts
818
+ const ZERO = 0;
819
+ const maxParallel = (sink) => (entry) => {
820
+ const parsed = parseInteger(sink)(entry.value);
821
+ if (Option.isSome(parsed) && Predicate.isUndefined(parsed.value.expression) && parsed.value.value <= ZERO) sink.error(entry.value, `value at "max-parallel" must be greater than zero: ${String(parsed.value.value)}`);
822
+ return parsed;
823
+ };
824
+ const parseStrategy = (sink) => (node) => {
825
+ const { setSome } = setters();
826
+ return foldEntries({
827
+ entries: section(sink)("strategy", node),
828
+ initial: {},
829
+ handlers: [
830
+ ["matrix", setSome("matrix", (entry) => Option.some(parseMatrix(sink)(entry.key, entry.value)))],
831
+ ["fail-fast", setSome("failFast", (entry) => parseBool(sink)(entry.value))],
832
+ ["max-parallel", setSome("maxParallel", maxParallel(sink))]
833
+ ],
834
+ unknown: rejecting({
835
+ sink,
836
+ section: "strategy",
837
+ expected: [
838
+ "matrix",
839
+ "fail-fast",
840
+ "max-parallel"
841
+ ]
842
+ })
843
+ });
844
+ };
845
+ // src/app/presets/entities/workflow/lib/job-general.ts
846
+ const generalHandlers = (sink) => {
847
+ const { set, setSome } = setters();
848
+ const call = setters();
849
+ return [
850
+ ["name", forJob(set("name", (entry) => parseString(sink)(entry.value, true)))],
851
+ ["needs", forJob(set("needs", needs(sink)))],
852
+ ["permissions", forJob(set("permissions", (entry) => parsePermissions(sink)(entry.value)))],
853
+ ["concurrency", forJob(set("concurrency", (entry) => parseConcurrency(sink)(entry.key, entry.value)))],
854
+ ["if", forJob(set("condition", (entry) => parseString(sink)(entry.value, false)))],
855
+ ["strategy", forJob(set("strategy", (entry) => parseStrategy(sink)(entry.value)))],
856
+ ["services", forJob(set("services", (entry) => parseServices(sink)(entry.value)))],
857
+ ["snapshot", forJob(setSome("snapshot", (entry) => parseSnapshot(sink)(entry.key, entry.value)))],
858
+ ["uses", callOnly(call.set("uses", (entry) => parseString(sink)(entry.value, false)))],
859
+ ["with", callOnly(call.set("inputs", (entry) => parseCallValues(sink)("with", entry.value)))],
860
+ ["secrets", callOnly(callSecrets(sink))]
861
+ ];
862
+ };
863
+ // src/app/presets/entities/workflow/lib/exec.ts
864
+ const COMMON = [
865
+ "id",
866
+ "if",
867
+ "name",
868
+ "env",
869
+ "continue-on-error",
870
+ "timeout-minutes"
871
+ ];
872
+ const common = () => pipe(COMMON, Array.map((key) => [key, keep]));
873
+ const withInput = (sink, docker) => (state, item) => {
874
+ if (docker && item.id === "entrypoint") return {
875
+ ...state,
876
+ action: {
877
+ ...state.action,
878
+ entrypoint: entryText(sink)(false)(item)
879
+ }
880
+ };
881
+ if (docker && item.id === "args") return {
882
+ ...state,
883
+ action: {
884
+ ...state.action,
885
+ args: entryText(sink)(true)(item)
886
+ }
887
+ };
888
+ const input = {
889
+ name: item.key,
890
+ value: entryText(sink)(true)(item)
891
+ };
892
+ return {
893
+ ...state,
894
+ inputs: [...state.inputs, [item.id, input]]
895
+ };
896
+ };
897
+ const parseWith = (sink, docker) => (action, entry) => {
898
+ const state = foldEntries({
899
+ entries: caselessSection(sink)("with", entry.value),
900
+ initial: {
901
+ action,
902
+ inputs: []
903
+ },
904
+ handlers: [],
905
+ unknown: withInput(sink, docker)
906
+ });
907
+ return {
908
+ ...state.action,
909
+ inputs: sortedRecord(state.inputs)
910
+ };
911
+ };
912
+ const execAction = (sink) => (entries, docker) => foldEntries({
913
+ entries,
914
+ initial: { type: "action" },
915
+ handlers: [
916
+ ...common(),
917
+ ["uses", setters().set("uses", entryText(sink)(false))],
918
+ ["with", parseWith(sink, docker)]
919
+ ],
920
+ unknown: rejecting({
921
+ sink,
922
+ section: "step to execute action",
923
+ expected: [
924
+ ...COMMON,
925
+ "uses",
926
+ "with"
927
+ ]
928
+ })
929
+ });
930
+ const runHandler = (sink) => (state, entry) => ({
931
+ ...state,
932
+ run: entryText(sink)(false)(entry),
933
+ runPosition: entry.key
934
+ });
935
+ const execRun = (sink) => (entries) => {
936
+ const { set } = setters();
937
+ return foldEntries({
938
+ entries,
939
+ initial: { type: "run" },
940
+ handlers: [
941
+ ...common(),
942
+ ["run", runHandler(sink)],
943
+ ["shell", set("shell", entryText(sink)(false))],
944
+ ["working-directory", set("workingDirectory", entryText(sink)(false))]
945
+ ],
946
+ unknown: rejecting({
947
+ sink,
948
+ section: "step to run shell command",
949
+ expected: [
950
+ ...COMMON,
951
+ "run",
952
+ "shell",
953
+ "working-directory"
954
+ ]
955
+ })
956
+ });
957
+ };
958
+ // src/app/presets/entities/workflow/lib/steps.ts
959
+ const lift$1 = (handler) => (state, entry) => ({
960
+ ...state,
961
+ step: handler(state.step, entry)
962
+ });
963
+ const usesShape = (state, entry) => {
964
+ if (String$1.startsWith("docker://")(entry.value.value)) return {
965
+ ...state,
966
+ shape: "docker"
967
+ };
968
+ return {
969
+ ...state,
970
+ shape: "action"
971
+ };
972
+ };
973
+ const runShape = (state) => ({
974
+ ...state,
975
+ shape: "run"
976
+ });
977
+ const stepHandlers$1 = (sink) => {
978
+ const { set, setSome } = setters();
979
+ const text = (allowEmpty) => (entry) => parseString(sink)(entry.value, allowEmpty);
980
+ return [
981
+ ["id", lift$1(set("id", text(false)))],
982
+ ["if", lift$1(set("condition", text(false)))],
983
+ ["name", lift$1(set("name", text(true)))],
984
+ ["env", lift$1(set("env", (entry) => parseEnv(sink)(entry.value)))],
985
+ ["continue-on-error", lift$1(setSome("continueOnError", (entry) => parseBool(sink)(entry.value)))],
986
+ ["timeout-minutes", lift$1(setSome("timeoutMinutes", (entry) => parseTimeoutMinutes(sink)(entry.value)))],
987
+ ["uses", usesShape],
988
+ ["run", runShape]
989
+ ];
990
+ };
991
+ const execOf = (sink) => (shape, entries) => {
992
+ if (shape === "run") return Option.some(execRun(sink)(entries));
993
+ if (shape === "unknown") return Option.none();
994
+ return Option.some(execAction(sink)(entries, shape === "docker"));
995
+ };
996
+ const parseStep = (sink) => (node) => {
997
+ const entries = parseMapping(sink)({
998
+ place: "element of \"steps\" section",
999
+ node,
1000
+ allowEmpty: false,
1001
+ caseSensitive: true
1002
+ });
1003
+ const state = foldEntries({
1004
+ entries,
1005
+ initial: {
1006
+ step: {},
1007
+ shape: "unknown"
1008
+ },
1009
+ handlers: stepHandlers$1(sink),
1010
+ unknown: keep
1011
+ });
1012
+ if (state.shape === "unknown") sink.error(node, "step must run script with \"run\" section or run action with \"uses\" section");
1013
+ return Option.match(execOf(sink)(state.shape, entries), {
1014
+ onNone: () => state.step,
1015
+ onSome: (exec) => ({
1016
+ ...state.step,
1017
+ exec
1018
+ })
1019
+ });
1020
+ };
1021
+ const parseSteps = (sink) => (node) => {
1022
+ if (!checkSequence(sink)({
1023
+ section: "steps",
1024
+ node,
1025
+ allowEmpty: false
1026
+ })) return Option.none();
1027
+ return Option.some(pipe(node.children, Array.map((child) => parseStep(sink)(child))));
1028
+ };
1029
+ // src/app/presets/entities/workflow/lib/job-steps.ts
1030
+ const stepHandlers = (sink) => {
1031
+ const { set, setSome } = setters();
1032
+ return [
1033
+ ["runs-on", stepsOnly(set("runsOn", (entry) => parseRunsOn(sink)(entry.value)))],
1034
+ ["environment", stepsOnly(set("environment", (entry) => parseEnvironment(sink)(entry.key, entry.value)))],
1035
+ ["outputs", stepsOnly(set("outputs", (entry) => parseOutputs(sink)(entry.value)))],
1036
+ ["env", stepsOnly(set("env", (entry) => parseEnv(sink)(entry.value)))],
1037
+ ["defaults", stepsOnly(set("defaults", (entry) => parseDefaults(sink)(entry.value)))],
1038
+ ["steps", stepsOnly(setSome("steps", (entry) => parseSteps(sink)(entry.value)))],
1039
+ ["timeout-minutes", stepsOnly(setSome("timeoutMinutes", (entry) => parseTimeoutMinutes(sink)(entry.value)))],
1040
+ ["continue-on-error", stepsOnly(setSome("continueOnError", (entry) => parseBool(sink)(entry.value)))],
1041
+ ["container", stepsOnly(set("container", (entry) => parseContainer(sink)("container", entry.key, entry.value)))]
1042
+ ];
1043
+ };
1044
+ // src/app/presets/entities/workflow/lib/job.ts
1045
+ const JOB_KEYS = [
1046
+ "name",
1047
+ "needs",
1048
+ "runs-on",
1049
+ "permissions",
1050
+ "environment",
1051
+ "concurrency",
1052
+ "outputs",
1053
+ "env",
1054
+ "defaults",
1055
+ "if",
1056
+ "steps",
1057
+ "timeout-minutes",
1058
+ "strategy",
1059
+ "continue-on-error",
1060
+ "container",
1061
+ "services",
1062
+ "uses",
1063
+ "with",
1064
+ "secrets",
1065
+ "snapshot"
1066
+ ];
1067
+ const finishCall = (sink) => (state) => {
1068
+ const key = state.stepsOnly;
1069
+ if (Predicate.isUndefined(key)) return {
1070
+ ...state.job,
1071
+ workflowCall: state.call
1072
+ };
1073
+ sink.error(key, `when a reusable workflow is called with "uses", ${quote(key.value)} is not available. only following keys are allowed: "name", "uses", "with", "secrets", "needs", "if", and "permissions" in job ${quote(state.job.id.value)}`);
1074
+ return state.job;
1075
+ };
1076
+ const finishSteps = (sink) => (state) => {
1077
+ const { job, callOnly: key } = state;
1078
+ const id = quote(job.id.value);
1079
+ reportMissing(sink)(job.steps, job.id, `"steps" section is missing in job ${id}`);
1080
+ reportMissing(sink)(job.runsOn, job.id, `"runs-on" section is missing in job ${id}`);
1081
+ if (Predicate.isNotUndefined(key)) sink.error(key, `${quote(key.value)} is only available for a reusable workflow call with "uses" but "uses" is not found in job ${id}`);
1082
+ return job;
1083
+ };
1084
+ const parseJob = (sink) => (id, node) => {
1085
+ const state = foldEntries({
1086
+ entries: parseMapping(sink)({
1087
+ place: `${quote(id.value)} job`,
1088
+ node,
1089
+ allowEmpty: false,
1090
+ caseSensitive: true
1091
+ }),
1092
+ initial: {
1093
+ job: emptyJob(id),
1094
+ call: {
1095
+ inputs: {},
1096
+ secrets: {},
1097
+ inheritSecrets: false
1098
+ }
1099
+ },
1100
+ handlers: [...generalHandlers(sink), ...stepHandlers(sink)],
1101
+ unknown: rejecting({
1102
+ sink,
1103
+ section: "job",
1104
+ expected: JOB_KEYS
1105
+ })
1106
+ });
1107
+ if (Predicate.isUndefined(state.call.uses)) return finishSteps(sink)(state);
1108
+ return finishCall(sink)(state);
1109
+ };
1110
+ // src/app/presets/entities/workflow/lib/dispatch.ts
1111
+ const DISPATCH_TYPES = {
1112
+ string: "string",
1113
+ number: "number",
1114
+ boolean: "boolean",
1115
+ choice: "choice",
1116
+ environment: "environment"
1117
+ };
1118
+ const dispatchType = (sink) => (state, entry) => {
1119
+ const node = entry.value;
1120
+ if (!checkString(sink)(node, false)) return state;
1121
+ return Option.match(Record.get(DISPATCH_TYPES, node.value), {
1122
+ onSome: (kind) => ({
1123
+ ...state,
1124
+ kind
1125
+ }),
1126
+ onNone: () => {
1127
+ sink.error(node, `input type of workflow_dispatch event must be one of "string", "number", "boolean", "choice", "environment" but got ${quote(node.value)}`);
1128
+ return state;
1129
+ }
1130
+ });
1131
+ };
1132
+ const strings$1 = (sink, section) => (entry) => parseStringSequence(sink)({
1133
+ section,
1134
+ node: entry.value,
1135
+ allowEmpty: false,
1136
+ allowElementEmpty: false
1137
+ });
1138
+ const dispatchInput = (sink) => (input) => {
1139
+ const { set, setSome } = setters();
1140
+ return foldEntries({
1141
+ entries: parseMapping(sink)({
1142
+ place: "input settings of workflow_dispatch event",
1143
+ node: input.value,
1144
+ allowEmpty: true,
1145
+ caseSensitive: true
1146
+ }),
1147
+ initial: {
1148
+ name: input.key,
1149
+ kind: "none",
1150
+ options: []
1151
+ },
1152
+ handlers: [
1153
+ ["description", set("description", entryText(sink)(true))],
1154
+ ["required", setSome("required", (entry) => parseBool(sink)(entry.value))],
1155
+ ["default", set("default", entryText(sink)(true))],
1156
+ ["type", dispatchType(sink)],
1157
+ ["options", set("options", strings$1(sink, "options"))]
1158
+ ],
1159
+ unknown: rejecting({
1160
+ sink,
1161
+ section: "inputs",
1162
+ expected: [
1163
+ "description",
1164
+ "required",
1165
+ "default"
1166
+ ]
1167
+ })
1168
+ });
1169
+ };
1170
+ const emptyDispatch = (at) => ({
1171
+ type: "workflow_dispatch",
1172
+ inputs: {},
1173
+ line: at.line,
1174
+ column: at.column
1175
+ });
1176
+ const parseWorkflowDispatch = (sink) => (at, node) => foldEntries({
1177
+ entries: emptyableSection(sink)("workflow_dispatch", node),
1178
+ initial: emptyDispatch(at),
1179
+ handlers: [["inputs", setters().set("inputs", (entry) => entryRecord(dispatchInput(sink))(emptyableCaselessSection(sink)("inputs", entry.value)))]],
1180
+ unknown: rejecting({
1181
+ sink,
1182
+ section: "workflow_dispatch",
1183
+ expected: ["inputs"]
1184
+ })
1185
+ });
1186
+ const EMPTY_IMAGE_VERSION = {
1187
+ type: "image_version",
1188
+ names: [],
1189
+ versions: []
1190
+ };
1191
+ const parseImageVersion = (sink) => (node) => {
1192
+ const { set } = setters();
1193
+ return foldEntries({
1194
+ entries: emptyableSection(sink)("image_version", node),
1195
+ initial: EMPTY_IMAGE_VERSION,
1196
+ handlers: [["names", set("names", strings$1(sink, "names"))], ["versions", set("versions", strings$1(sink, "versions"))]],
1197
+ unknown: rejecting({
1198
+ sink,
1199
+ section: "image_version",
1200
+ expected: ["names", "versions"]
1201
+ })
1202
+ });
1203
+ };
1204
+ // src/app/presets/entities/workflow/lib/events.ts
1205
+ const SCHEDULE_ELEMENT = "element of \"schedule\" section";
1206
+ const nonEmpty = (sink) => (entry) => Option.liftPredicate(parseString(sink)(entry.value, false), (text) => text.value !== "");
1207
+ const scheduleEntry = (sink) => (node) => {
1208
+ const { setSome } = setters();
1209
+ const state = foldEntries({
1210
+ entries: parseMapping(sink)({
1211
+ place: SCHEDULE_ELEMENT,
1212
+ node,
1213
+ allowEmpty: false,
1214
+ caseSensitive: true
1215
+ }),
1216
+ initial: {},
1217
+ handlers: [["cron", setSome("cron", nonEmpty(sink))], ["timezone", setSome("timezone", nonEmpty(sink))]],
1218
+ unknown: rejecting({
1219
+ sink,
1220
+ section: SCHEDULE_ELEMENT,
1221
+ expected: ["cron", "timezone"]
1222
+ })
1223
+ });
1224
+ return pipe(Option.fromNullishOr(state.cron), Option.map((cron) => ({
1225
+ cron,
1226
+ ...optional("timezone")(Option.fromNullishOr(state.timezone))
1227
+ })));
1228
+ };
1229
+ const parseSchedule = (sink) => (node) => {
1230
+ if (!checkSequence(sink)({
1231
+ section: "schedule",
1232
+ node,
1233
+ allowEmpty: false
1234
+ })) return Option.none();
1235
+ return Option.some({
1236
+ type: "schedule",
1237
+ schedules: pipe(node.children, Array.flatMap((child) => Option.toArray(scheduleEntry(sink)(child))))
1238
+ });
1239
+ };
1240
+ const strings = (sink) => (entry) => parseStringOrSequence(sink)({
1241
+ section: entry.key.value,
1242
+ node: entry.value,
1243
+ allowEmpty: false,
1244
+ allowElementEmpty: false
1245
+ });
1246
+ const parseRepositoryDispatch = (sink) => (node) => foldEntries({
1247
+ entries: emptyableSection(sink)("repository_dispatch", node),
1248
+ initial: {
1249
+ type: "repository_dispatch",
1250
+ types: []
1251
+ },
1252
+ handlers: [["types", setters().set("types", strings(sink))]],
1253
+ unknown: rejecting({
1254
+ sink,
1255
+ section: "repository_dispatch",
1256
+ expected: ["types"]
1257
+ })
1258
+ });
1259
+ const WEBHOOK_FILTERS = [
1260
+ ["branches", "branches"],
1261
+ ["branches-ignore", "branchesIgnore"],
1262
+ ["tags", "tags"],
1263
+ ["tags-ignore", "tagsIgnore"],
1264
+ ["paths", "paths"],
1265
+ ["paths-ignore", "pathsIgnore"]
1266
+ ];
1267
+ const WEBHOOK_KEYS = [
1268
+ "types",
1269
+ "branches",
1270
+ "branches-ignore",
1271
+ "tags",
1272
+ "tags-ignore",
1273
+ "paths",
1274
+ "paths-ignore",
1275
+ "workflows"
1276
+ ];
1277
+ const emptyWebhook = (name) => ({
1278
+ type: "webhook",
1279
+ hook: name,
1280
+ types: [],
1281
+ workflows: [],
1282
+ line: name.line,
1283
+ column: name.column
1284
+ });
1285
+ const webhookHandlers = (sink) => {
1286
+ const { set } = setters();
1287
+ const filter = (entry) => ({
1288
+ name: entry.key,
1289
+ values: strings(sink)(entry)
1290
+ });
1291
+ return [
1292
+ ["types", set("types", strings(sink))],
1293
+ ["workflows", set("workflows", strings(sink))],
1294
+ ...pipe(WEBHOOK_FILTERS, Array.map(([key, field]) => [key, set(field, filter)]))
1295
+ ];
1296
+ };
1297
+ const parseWebhook = (sink) => (name, node) => foldEntries({
1298
+ entries: emptyableSection(sink)(name.value, node),
1299
+ initial: emptyWebhook(name),
1300
+ handlers: webhookHandlers(sink),
1301
+ unknown: rejecting({
1302
+ sink,
1303
+ section: name.value,
1304
+ expected: WEBHOOK_KEYS
1305
+ })
1306
+ });
1307
+ // src/app/presets/entities/workflow/lib/workflow-call.ts
1308
+ const CALL_TYPES = {
1309
+ boolean: "boolean",
1310
+ number: "number",
1311
+ string: "string"
1312
+ };
1313
+ const inputType = (sink) => (state, entry) => {
1314
+ const node = entry.value;
1315
+ if (!checkString(sink)(node, false)) return {
1316
+ ...state,
1317
+ typed: true
1318
+ };
1319
+ return Option.match(Record.get(CALL_TYPES, node.value), {
1320
+ onSome: (kind) => ({
1321
+ input: {
1322
+ ...state.input,
1323
+ kind
1324
+ },
1325
+ typed: true
1326
+ }),
1327
+ onNone: () => {
1328
+ sink.error(node, `invalid value ${quote(node.value)} for input type of workflow_call event. it must be one of "boolean", "number", or "string"`);
1329
+ return {
1330
+ ...state,
1331
+ typed: true
1332
+ };
1333
+ }
1334
+ });
1335
+ };
1336
+ const lift = (handler) => (state, entry) => ({
1337
+ ...state,
1338
+ input: handler(state.input, entry)
1339
+ });
1340
+ const required = (sink) => (entry) => parseBool(sink)(entry.value);
1341
+ const mappingOf = (sink, place) => (entry) => parseMapping(sink)({
1342
+ place,
1343
+ node: entry.value,
1344
+ allowEmpty: true,
1345
+ caseSensitive: true
1346
+ });
1347
+ const callInput = (sink) => (entry) => {
1348
+ const { set, setSome } = setters();
1349
+ const description = lift(set("description", entryText(sink)(true)));
1350
+ const isRequired = lift(setSome("required", required(sink)));
1351
+ const fallback = lift(set("default", entryText(sink)(true)));
1352
+ const state = foldEntries({
1353
+ entries: mappingOf(sink, "input of workflow_call event")(entry),
1354
+ initial: {
1355
+ input: {
1356
+ id: entry.id,
1357
+ name: entry.key,
1358
+ kind: "invalid"
1359
+ },
1360
+ typed: false
1361
+ },
1362
+ handlers: [
1363
+ ["description", description],
1364
+ ["required", isRequired],
1365
+ ["default", fallback],
1366
+ ["type", inputType(sink)]
1367
+ ],
1368
+ unknown: rejecting({
1369
+ sink,
1370
+ section: "inputs at workflow_call event",
1371
+ expected: [
1372
+ "description",
1373
+ "required",
1374
+ "default",
1375
+ "type"
1376
+ ]
1377
+ })
1378
+ });
1379
+ if (!state.typed) sink.error(entry.key, `"type" is missing at ${quote(entry.key.value)} input of workflow_call event`);
1380
+ return state.input;
1381
+ };
1382
+ const callSecret = (sink) => (entry) => {
1383
+ const { set, setSome } = setters();
1384
+ return foldEntries({
1385
+ entries: mappingOf(sink, "secret of workflow_call event")(entry),
1386
+ initial: { name: entry.key },
1387
+ handlers: [["description", set("description", entryText(sink)(true))], ["required", setSome("required", required(sink))]],
1388
+ unknown: rejecting({
1389
+ sink,
1390
+ section: "secrets",
1391
+ expected: ["description", "required"]
1392
+ })
1393
+ });
1394
+ };
1395
+ const callOutput = (sink) => (entry) => {
1396
+ const { set } = setters();
1397
+ const output = foldEntries({
1398
+ entries: mappingOf(sink, "output of workflow_call event")(entry),
1399
+ initial: { name: entry.key },
1400
+ handlers: [["description", set("description", entryText(sink)(true))], ["value", set("value", (item) => parseString(sink)(item.value, false))]],
1401
+ unknown: rejecting({
1402
+ sink,
1403
+ section: "outputs at workflow_call event",
1404
+ expected: ["description", "value"]
1405
+ })
1406
+ });
1407
+ reportMissing(sink)(output.value, entry.key, `"value" is missing at ${quote(entry.key.value)} output of workflow_call event`);
1408
+ return output;
1409
+ };
1410
+ const emptyCall = (at) => ({
1411
+ type: "workflow_call",
1412
+ inputs: [],
1413
+ outputs: {},
1414
+ line: at.line,
1415
+ column: at.column
1416
+ });
1417
+ const parseWorkflowCall = (sink) => (at, node) => {
1418
+ const { set } = setters();
1419
+ return foldEntries({
1420
+ entries: emptyableSection(sink)("workflow_call", node),
1421
+ initial: emptyCall(at),
1422
+ handlers: [
1423
+ ["inputs", set("inputs", (entry) => Array.map(emptyableCaselessSection(sink)("inputs", entry.value), callInput(sink)))],
1424
+ ["secrets", set("secrets", (entry) => entryRecord(callSecret(sink))(emptyableCaselessSection(sink)("secrets", entry.value)))],
1425
+ ["outputs", set("outputs", (entry) => entryRecord(callOutput(sink))(emptyableCaselessSection(sink)("outputs", entry.value)))]
1426
+ ],
1427
+ unknown: rejecting({
1428
+ sink,
1429
+ section: "workflow_call",
1430
+ expected: [
1431
+ "inputs",
1432
+ "secrets",
1433
+ "outputs"
1434
+ ]
1435
+ })
1436
+ });
1437
+ };
1438
+ // src/app/presets/entities/workflow/lib/on.ts
1439
+ const withoutConfig = (sink) => (node) => {
1440
+ const name = parseString(sink)(node, false);
1441
+ switch (name.value) {
1442
+ case "": return Option.none();
1443
+ case "schedule":
1444
+ sink.error(node, "schedule event must be configured with mapping");
1445
+ return Option.none();
1446
+ case "repository_dispatch": return Option.some({
1447
+ type: "repository_dispatch",
1448
+ types: []
1449
+ });
1450
+ case "workflow_dispatch": return Option.some(emptyDispatch(node));
1451
+ case "workflow_call": return Option.some(emptyCall(node));
1452
+ case "image_version": return Option.some(EMPTY_IMAGE_VERSION);
1453
+ default: return Option.some({
1454
+ ...emptyWebhook(name),
1455
+ line: node.line,
1456
+ column: node.column
1457
+ });
1458
+ }
1459
+ };
1460
+ const configured = (sink) => (entry) => {
1461
+ switch (entry.id) {
1462
+ case "schedule": return parseSchedule(sink)(entry.value);
1463
+ case "workflow_dispatch": return Option.some(parseWorkflowDispatch(sink)(entry.key, entry.value));
1464
+ case "repository_dispatch": return Option.some(parseRepositoryDispatch(sink)(entry.value));
1465
+ case "workflow_call": return Option.some(parseWorkflowCall(sink)(entry.key, entry.value));
1466
+ case "image_version": return Option.some(parseImageVersion(sink)(entry.value));
1467
+ default: return Option.some(parseWebhook(sink)(entry.key, entry.value));
1468
+ }
1469
+ };
1470
+ const each = (parse) => (items) => pipe(items, Array.flatMap((item) => Option.toArray(parse(item))));
1471
+ const parseEvents = (sink) => (node) => {
1472
+ if (node.kind === "scalar") return withoutConfig(sink)(node).pipe(Option.toArray, Option.some);
1473
+ if (node.kind === "mapping") {
1474
+ const entries = section(sink)("on", node);
1475
+ return Option.some(each(configured(sink))(entries));
1476
+ }
1477
+ if (node.kind === "sequence") {
1478
+ checkNotEmpty(sink)("on", node);
1479
+ return Option.some(each(withoutConfig(sink))(node.children));
1480
+ }
1481
+ sink.error(node, `"on" section value is expected to be mapping or sequence but found ${node.kind} node`);
1482
+ return Option.none();
1483
+ };
1484
+ // src/app/presets/entities/workflow/lib/parse.ts
1485
+ const WORKFLOW_KEYS = [
1486
+ "name",
1487
+ "run-name",
1488
+ "on",
1489
+ "permissions",
1490
+ "env",
1491
+ "defaults",
1492
+ "concurrency",
1493
+ "jobs"
1494
+ ];
1495
+ const FIRST = 1;
1496
+ const EMPTY_WORKFLOW = {};
1497
+ const parseRoot = (sink) => (root) => {
1498
+ const { set, setSome } = setters();
1499
+ const workflow = foldEntries({
1500
+ entries: section(sink)("workflow", root),
1501
+ initial: EMPTY_WORKFLOW,
1502
+ handlers: [
1503
+ ["name", set("name", (entry) => parseString(sink)(entry.value, true))],
1504
+ ["on", setSome("on", (entry) => parseEvents(sink)(entry.value))],
1505
+ ["permissions", set("permissions", (entry) => parsePermissions(sink)(entry.value))],
1506
+ ["env", set("env", (entry) => parseEnv(sink)(entry.value))],
1507
+ ["defaults", set("defaults", (entry) => parseDefaults(sink)(entry.value))],
1508
+ ["concurrency", set("concurrency", (entry) => parseConcurrency(sink)(entry.key, entry.value))],
1509
+ ["jobs", set("jobs", (entry) => entryRecord((job) => parseJob(sink)(job.key, job.value))(caselessSection(sink)("jobs", entry.value)))],
1510
+ ["run-name", set("runName", (entry) => parseString(sink)(entry.value, false))]
1511
+ ],
1512
+ unknown: rejecting({
1513
+ sink,
1514
+ section: "workflow",
1515
+ expected: WORKFLOW_KEYS
1516
+ })
1517
+ });
1518
+ reportMissing(sink)(workflow.on, root, "\"on\" section is missing in workflow");
1519
+ reportMissing(sink)(workflow.jobs, root, "\"jobs\" section is missing in workflow");
1520
+ return workflow;
1521
+ };
1522
+ const parseWorkflow = (sink) => (source) => {
1523
+ for (const problem of source.errors) sink.error(problem, problem.message);
1524
+ const root = Option.fromNullishOr(source.yaml);
1525
+ if (Option.isSome(root)) return Option.some(parseRoot(sink)(root.value));
1526
+ if (pipe(source.errors, Array.some((problem) => String$1.startsWith("could not parse")(problem.message)))) return Option.none();
1527
+ sink.error({
1528
+ line: FIRST,
1529
+ column: FIRST
1530
+ }, "workflow is empty");
1531
+ return Option.some(EMPTY_WORKFLOW);
1532
+ };
1533
+ // src/app/presets/entities/workflow/model/parsed.ts
1534
+ const parsed = /* @__PURE__ */ new WeakMap();
1535
+ const parse = (source) => {
1536
+ const errors = [];
1537
+ const workflow = parseWorkflow({ error: (at, message) => {
1538
+ errors.push({
1539
+ line: at.line,
1540
+ column: at.column,
1541
+ message
1542
+ });
1543
+ } })(source);
1544
+ return {
1545
+ errors,
1546
+ ...optional("workflow")(workflow)
1547
+ };
1548
+ };
1549
+ const workflowOf = (source) => parsed.getOrInsertComputed(source, () => parse(source));
1550
+ // src/app/presets/features/check-workflows/lib/workflow-rule.ts
1551
+ const NOOP = {
1552
+ workflowPre: Function.constVoid,
1553
+ jobPre: Function.constVoid,
1554
+ step: Function.constVoid,
1555
+ jobPost: Function.constVoid,
1556
+ workflowPost: Function.constVoid
1557
+ };
1558
+ const eachEvent = (check) => (workflow) => {
1559
+ for (const event of Option.getOrElse(Option.fromNullishOr(workflow.on), () => [])) check(event);
1560
+ };
1561
+ const visitJob = (visitor, job) => {
1562
+ visitor.jobPre(job);
1563
+ for (const step of Option.getOrElse(Option.fromNullishOr(job.steps), () => [])) visitor.step(step);
1564
+ visitor.jobPost(job);
1565
+ };
1566
+ const visit = (visitor, workflow) => {
1567
+ visitor.workflowPre(workflow);
1568
+ for (const job of Record.values(Option.getOrElse(Option.fromNullishOr(workflow.jobs), () => ({})))) visitJob(visitor, job);
1569
+ visitor.workflowPost(workflow);
1570
+ };
1571
+ const workflowRule = (rule) => defineRule({
1572
+ meta: {
1573
+ description: rule.description,
1574
+ docs: rule.docs,
1575
+ kinds: ["workflow"]
1576
+ },
1577
+ check: (context) => {
1578
+ for (const workflow of Option.toArray(Option.fromNullishOr(workflowOf(context.source).workflow))) {
1579
+ const fail = (at, message) => {
1580
+ context.report({
1581
+ line: at.line,
1582
+ column: at.column,
1583
+ message
1584
+ });
1585
+ };
1586
+ visit(rule.visitor(fail, context), workflow);
1587
+ }
1588
+ }
1589
+ });
1590
+ export { sortedQuotes as C, quotes as S, parseGoFloat as T, valueAt as _, ancestorsBy as a, quote as b, actionOf as c, isNull as d, isQuoted as f, textOf as g, readYaml as h, workflowOf as i, runOf as l, pairsOf as m, eachEvent as n, containsExpression as o, keysOf as p, workflowRule as r, isExpressionAssigned as s, NOOP as t, describePosition as u, codePoints as v, atoi as w, quoteChar as x, ordinal as y };
1591
+
1592
+ //# sourceMappingURL=workflow-rule-C1TJLS9H.mjs.map