@intellectual-frontiers/libraries 0.2.1 → 0.4.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.
@@ -85,18 +85,24 @@ export type Permissions = Readonly<
85
85
  /** The branches, paths and tags a push or a pull request is run for; none is every one. */
86
86
  export type Filter = { readonly branches?: readonly string[]; readonly paths?: readonly string[]; readonly tags?: readonly string[] };
87
87
 
88
+ /** A question a run by hand asks: a yes or no with its default. */
89
+ export type DispatchInput = { readonly description: string; readonly type: "boolean"; readonly default: boolean };
90
+
88
91
  export type Triggers = {
89
92
  readonly push?: Filter;
90
93
  readonly pullRequest?: Filter;
91
- /** Run by hand from the Actions page. */
92
- readonly workflowDispatch?: true;
94
+ /** Run by hand from the Actions page, with the inputs it asks for (true asks for none). */
95
+ readonly workflowDispatch?: true | { readonly inputs: Readonly<Record<string, DispatchInput>> };
93
96
  /** Called by another workflow. */
94
97
  readonly workflowCall?: true;
95
98
  };
96
99
 
100
+ /** The cells of a matrix: the values of each axis, or an expression that gives the whole matrix (`expr("fromJSON(needs.plan.outputs.linux)")`), which a job reads from the output of another. */
101
+ export type Matrix = Readonly<Record<string, readonly (string | number)[]>> | Expr;
102
+
97
103
  export type Strategy = {
98
104
  readonly failFast?: boolean;
99
- readonly matrix: Readonly<Record<string, readonly (string | number)[]>>;
105
+ readonly matrix: Matrix;
100
106
  };
101
107
 
102
108
  export type Job = {
@@ -109,6 +115,8 @@ export type Job = {
109
115
  readonly permissions?: Permissions;
110
116
  readonly environment?: { readonly name: string; readonly url?: string };
111
117
  readonly env?: Readonly<Record<string, Scalar>>;
118
+ /** What the job gives the jobs that need it, by name: an expression of its steps' outputs. */
119
+ readonly outputs?: Readonly<Record<string, Expr>>;
112
120
  readonly strategy?: Strategy;
113
121
  readonly steps: readonly [Step, ...Step[]];
114
122
  /** A comment written above the job. */
@@ -126,10 +126,12 @@ function jobLines(id: string, j: Job): string[] {
126
126
  if (j.environment.url !== undefined) out.push(...entry("url", j.environment.url, 6));
127
127
  }
128
128
  out.push(...mapping("env", j.env, 4));
129
+ out.push(...mapping("outputs", j.outputs, 4));
129
130
  if (j.strategy !== undefined) {
130
131
  out.push(" strategy:");
131
132
  if (j.strategy.failFast !== undefined) out.push(...entry("fail-fast", j.strategy.failFast, 6));
132
- out.push(" matrix:", ...Object.entries(j.strategy.matrix).flatMap(([k, v]) => flowList(k, v, 8)));
133
+ const m = j.strategy.matrix;
134
+ out.push(...(typeof m === "string" ? entry("matrix", m, 6) : [" matrix:", ...Object.entries(m).flatMap(([k, v]) => flowList(k, v, 8))]));
133
135
  }
134
136
  out.push(" steps:", ...j.steps.flatMap((s) => step(s, 6)));
135
137
  return out;
@@ -141,7 +143,13 @@ export function renderWorkflow(w: Workflow): string {
141
143
  if (w.comment !== undefined) out.push(...comment(w.comment, 0));
142
144
  out.push("on:");
143
145
  out.push(...filter("push", w.on.push, 2), ...filter("pull_request", w.on.pullRequest, 2));
144
- if (w.on.workflowDispatch === true) out.push(" workflow_dispatch:");
146
+ const dispatch = w.on.workflowDispatch;
147
+ if (dispatch === true) out.push(" workflow_dispatch:");
148
+ else if (dispatch !== undefined) {
149
+ out.push(" workflow_dispatch:", " inputs:");
150
+ for (const [k, v] of Object.entries(dispatch.inputs))
151
+ out.push(` ${key(k)}:`, ...entry("description", v.description, 8), ...entry("type", v.type, 8), ...entry("default", v.default, 8));
152
+ }
145
153
  if (w.on.workflowCall === true) out.push(" workflow_call:");
146
154
  out.push("");
147
155
  if (w.permissions !== undefined) out.push(...permissions(w.permissions, 0), "");