@effected/engine 0.12.0 → 0.14.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.
- package/build/ActionInit.js +461 -0
- package/build/ActionRun.js +74 -0
- package/build/ActionRunResult.js +22 -0
- package/build/BuildRun.js +162 -0
- package/build/BuildRunResult.js +26 -0
- package/build.d.ts +446 -0
- package/build.js +8 -0
- package/package.json +24 -4
- package/schema/AjvInstanceValidator.js +72 -0
- package/schema/AjvValidator.js +80 -0
- package/schema/ConfigLoader.js +273 -0
- package/schema/Report.js +203 -0
- package/schema/RunReport.js +352 -0
- package/schema/Runner.js +507 -0
- package/schema/SchemaRun.js +108 -0
- package/schema/SchemaValidate.js +324 -0
- package/schema/StepSummary.js +30 -0
- package/schema/VersionCheck.js +81 -0
- package/schema/internal/ajv.js +50 -0
- package/schema/internal/causeMessage.js +57 -0
- package/schema/internal/decode.js +23 -0
- package/schema.d.ts +1084 -0
- package/schema.js +12 -0
|
@@ -0,0 +1,461 @@
|
|
|
1
|
+
import { NotAPackageError } from "./BuildRun.js";
|
|
2
|
+
import { ErrorText, PathContainment } from "@effected/kit";
|
|
3
|
+
import { Effect, FileSystem, Path, Predicate, Result, Schema } from "effect";
|
|
4
|
+
import { AtomicFile } from "@effected/files";
|
|
5
|
+
|
|
6
|
+
// src/build/ActionInit.ts
|
|
7
|
+
/**
|
|
8
|
+
* One file of a scaffold: where it goes, relative to the action's directory, and its whole content.
|
|
9
|
+
*
|
|
10
|
+
* @public
|
|
11
|
+
*/
|
|
12
|
+
var ActionScaffoldFile = class extends Schema.Class("ActionScaffoldFile")({
|
|
13
|
+
/** The path, relative to the action's directory, with `/` separators. */
|
|
14
|
+
path: Schema.String,
|
|
15
|
+
/** The complete content. */
|
|
16
|
+
contents: Schema.String
|
|
17
|
+
}) {};
|
|
18
|
+
/**
|
|
19
|
+
* Everything a new action needs that `action init` writes, as data: the files, and the packages its source imports.
|
|
20
|
+
*
|
|
21
|
+
* @public
|
|
22
|
+
*/
|
|
23
|
+
var ActionScaffold = class extends Schema.Class("ActionScaffold")({
|
|
24
|
+
/** The files, in the order they are written. */
|
|
25
|
+
files: Schema.Array(ActionScaffoldFile),
|
|
26
|
+
/** The runtime packages the scaffold's source imports, closed over their required peers. */
|
|
27
|
+
dependencies: Schema.Array(Schema.String),
|
|
28
|
+
/** The packages the scaffold's tooling needs: the `effected` command and the tsconfig preset it extends. */
|
|
29
|
+
devDependencies: Schema.Array(Schema.String)
|
|
30
|
+
}) {};
|
|
31
|
+
/**
|
|
32
|
+
* What one `action init` did.
|
|
33
|
+
*
|
|
34
|
+
* @public
|
|
35
|
+
*/
|
|
36
|
+
var ActionInitResult = class extends Schema.Class("ActionInitResult")({
|
|
37
|
+
/** The action's directory. */
|
|
38
|
+
cwd: Schema.String,
|
|
39
|
+
/** Every file written, relative to `cwd`, in the order written. */
|
|
40
|
+
written: Schema.Array(Schema.String),
|
|
41
|
+
/** The files among `written` that existed and were replaced, which only `force` allows. */
|
|
42
|
+
overwritten: Schema.Array(Schema.String),
|
|
43
|
+
/** Runtime packages the scaffold imports that `package.json` does not declare yet. */
|
|
44
|
+
missingDependencies: Schema.Array(Schema.String),
|
|
45
|
+
/** Tooling packages the scaffold needs that `package.json` does not declare yet. */
|
|
46
|
+
missingDevDependencies: Schema.Array(Schema.String),
|
|
47
|
+
/** Whether `package.json` sets `"type": "module"`, which the entry's top-level `await` needs. */
|
|
48
|
+
typeModule: Schema.Boolean
|
|
49
|
+
}) {};
|
|
50
|
+
/**
|
|
51
|
+
* The files a scaffold would write already exist, and overwriting was not asked for. Nothing was written.
|
|
52
|
+
*
|
|
53
|
+
* @public
|
|
54
|
+
*/
|
|
55
|
+
var ScaffoldExistsError = class extends Schema.TaggedError()("ScaffoldExistsError", {
|
|
56
|
+
/** The action's directory. */
|
|
57
|
+
cwd: Schema.String,
|
|
58
|
+
/** The existing files, relative to `cwd`. */
|
|
59
|
+
files: Schema.Array(Schema.String)
|
|
60
|
+
}) {
|
|
61
|
+
get message() {
|
|
62
|
+
return `${this.cwd} already has ${this.files.join(", ")}: nothing was written, and overwriting needs force`;
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
/**
|
|
66
|
+
* One path a scaffold cannot be written over, whatever `force` says.
|
|
67
|
+
*
|
|
68
|
+
* @public
|
|
69
|
+
*/
|
|
70
|
+
var ScaffoldConflict = class extends Schema.Class("ScaffoldConflict")({
|
|
71
|
+
/** The path, relative to the action's directory. */
|
|
72
|
+
path: Schema.String,
|
|
73
|
+
/**
|
|
74
|
+
* What is there: `symlink` a symbolic link, which is never followed or replaced; `not-a-file` a directory or other
|
|
75
|
+
* non-file where a file goes; `not-a-directory` a file where a directory goes; `unreadable` an entry that could not
|
|
76
|
+
* be inspected; `unwritable` an existing file or directory this process may not write (`.` is the action's directory
|
|
77
|
+
* itself); `escapes` a path that resolves outside the
|
|
78
|
+
* action's directory; `case-variant` an entry whose name differs from the scaffold's only in case.
|
|
79
|
+
*/
|
|
80
|
+
kind: Schema.Literals([
|
|
81
|
+
"symlink",
|
|
82
|
+
"not-a-file",
|
|
83
|
+
"not-a-directory",
|
|
84
|
+
"unreadable",
|
|
85
|
+
"unwritable",
|
|
86
|
+
"escapes",
|
|
87
|
+
"case-variant"
|
|
88
|
+
])
|
|
89
|
+
}) {};
|
|
90
|
+
/**
|
|
91
|
+
* Paths the scaffold would write cannot be written over: a symbolic link, the wrong kind of entry, an entry that could
|
|
92
|
+
* not be inspected, or a path resolving outside the action's directory. Nothing was written, and `force` does not
|
|
93
|
+
* change it.
|
|
94
|
+
*
|
|
95
|
+
* @public
|
|
96
|
+
*/
|
|
97
|
+
var ScaffoldConflictError = class extends Schema.TaggedError()("ScaffoldConflictError", {
|
|
98
|
+
/** The action's directory. */
|
|
99
|
+
cwd: Schema.String,
|
|
100
|
+
/** Each conflicting path and what is there. */
|
|
101
|
+
conflicts: Schema.Array(ScaffoldConflict)
|
|
102
|
+
}) {
|
|
103
|
+
get message() {
|
|
104
|
+
const listed = this.conflicts.map((conflict) => `${conflict.path} (${conflict.kind})`).join(", ");
|
|
105
|
+
return `${this.cwd} cannot take the scaffold over ${listed}: nothing was written`;
|
|
106
|
+
}
|
|
107
|
+
};
|
|
108
|
+
/**
|
|
109
|
+
* A scaffold file or directory could not be written after every check passed. The files before it were written.
|
|
110
|
+
*
|
|
111
|
+
* @public
|
|
112
|
+
*/
|
|
113
|
+
var ScaffoldWriteError = class extends Schema.TaggedError()("ScaffoldWriteError", {
|
|
114
|
+
/** The action's directory. */
|
|
115
|
+
cwd: Schema.String,
|
|
116
|
+
/** The path that could not be written, relative to `cwd`. */
|
|
117
|
+
path: Schema.String,
|
|
118
|
+
/** The files written before it, relative to `cwd`, in order. */
|
|
119
|
+
written: Schema.Array(Schema.String),
|
|
120
|
+
/** The underlying filesystem failure, preserved structurally. */
|
|
121
|
+
cause: Schema.Defect()
|
|
122
|
+
}) {
|
|
123
|
+
get message() {
|
|
124
|
+
const before = this.written.length > 0 ? this.written.join(", ") : "nothing";
|
|
125
|
+
const cause = ErrorText.causeMessage(this.cause);
|
|
126
|
+
return `Could not write ${this.path} in ${this.cwd}: ${cause}; already written: ${before}`;
|
|
127
|
+
}
|
|
128
|
+
};
|
|
129
|
+
/**
|
|
130
|
+
* The action's name or description was neither given nor found in `package.json`, or was blank.
|
|
131
|
+
*
|
|
132
|
+
* @public
|
|
133
|
+
*/
|
|
134
|
+
var ActionMetadataMissingError = class extends Schema.TaggedError()("ActionMetadataMissingError", {
|
|
135
|
+
/** Which `action.yml` field had no value. */
|
|
136
|
+
field: Schema.Literals(["name", "description"]) }) {
|
|
137
|
+
get message() {
|
|
138
|
+
return `The action needs a ${this.field}: pass one, or set "${this.field}" in package.json`;
|
|
139
|
+
}
|
|
140
|
+
};
|
|
141
|
+
/**
|
|
142
|
+
* The action's name or description holds a control character or a lone surrogate, which `action.yml` cannot carry.
|
|
143
|
+
*
|
|
144
|
+
* @public
|
|
145
|
+
*/
|
|
146
|
+
var ActionMetadataInvalidError = class extends Schema.TaggedError()("ActionMetadataInvalidError", {
|
|
147
|
+
/** Which `action.yml` field it was. */
|
|
148
|
+
field: Schema.Literals(["name", "description"]),
|
|
149
|
+
/** The first offending character or lone surrogate, as `U+XXXX`. */
|
|
150
|
+
character: Schema.String
|
|
151
|
+
}) {
|
|
152
|
+
get message() {
|
|
153
|
+
return `The action's ${this.field} holds ${this.character}, a control character or lone surrogate: write it on one line, as printable text`;
|
|
154
|
+
}
|
|
155
|
+
};
|
|
156
|
+
const DEPENDENCIES = [
|
|
157
|
+
"@effected/github-actions",
|
|
158
|
+
"effect",
|
|
159
|
+
"@effect/platform-node"
|
|
160
|
+
];
|
|
161
|
+
const DEV_DEPENDENCIES = [
|
|
162
|
+
"@effected/plugin",
|
|
163
|
+
"typescript",
|
|
164
|
+
"@types/node"
|
|
165
|
+
];
|
|
166
|
+
const isControl = (code) => code < 32 && code !== 9 || code >= 127 && code <= 159;
|
|
167
|
+
const codePoint = (character) => `U+${(character.codePointAt(0) ?? 0).toString(16).toUpperCase().padStart(4, "0")}`;
|
|
168
|
+
const yamlString = (value) => JSON.stringify(value).replace(/[\u007F-\u009F\u2028\u2029]/g, (character) => `\\u${codePoint(character).slice(2)}`);
|
|
169
|
+
const effectedToml = `# \`effected action build\` reads the [action] tables. A key left out takes its default.
|
|
170
|
+
|
|
171
|
+
[action.entries]
|
|
172
|
+
main = "src/main.ts"
|
|
173
|
+
|
|
174
|
+
# Copies each build to .github/actions/local, the target act and CI smoke-test.
|
|
175
|
+
[action.persistLocal]
|
|
176
|
+
enabled = true
|
|
177
|
+
path = ".github/actions/local"
|
|
178
|
+
`;
|
|
179
|
+
const actionYml = (input) => `# The single source of the action's input and output names and their defaults: code mirrors them.
|
|
180
|
+
name: ${yamlString(input.name)}
|
|
181
|
+
description: ${yamlString(input.description)}
|
|
182
|
+
branding:
|
|
183
|
+
icon: package
|
|
184
|
+
color: blue
|
|
185
|
+
runs:
|
|
186
|
+
using: node24
|
|
187
|
+
main: dist/main.js
|
|
188
|
+
`;
|
|
189
|
+
const mainTs = `// The main entry: the program and the guard, nothing else. The guard keeps the program importable by tests, and the
|
|
190
|
+
// build's load check imports this bundle with GITHUB_ACTIONS unset, so it loads without running.
|
|
191
|
+
import { Action } from "@effected/github-actions";
|
|
192
|
+
import { program } from "./program.js";
|
|
193
|
+
|
|
194
|
+
if (process.env.GITHUB_ACTIONS) {
|
|
195
|
+
await Action.run(program);
|
|
196
|
+
}
|
|
197
|
+
`;
|
|
198
|
+
const programTs = `// The program: read the inputs, run the steps in order, fold their results into the outputs, and report. Composition
|
|
199
|
+
// only: when it has steps, their bodies live in src/steps/, and every human-readable string in src/format.ts.
|
|
200
|
+
import { Effect } from "effect";
|
|
201
|
+
|
|
202
|
+
export const program = Effect.logInfo("The action ran.");
|
|
203
|
+
`;
|
|
204
|
+
const tsconfigJson = `{
|
|
205
|
+
"$schema": "https://json.schemastore.org/tsconfig.json",
|
|
206
|
+
"extends": "@effected/plugin/tsconfig/ecma.json"
|
|
207
|
+
}
|
|
208
|
+
`;
|
|
209
|
+
const blank = (value) => value === void 0 || value.trim() === "";
|
|
210
|
+
const checked = (field, value) => {
|
|
211
|
+
const found = [...value].find((character) => isControl(character.codePointAt(0) ?? 0) || !character.isWellFormed());
|
|
212
|
+
return found === void 0 ? Effect.succeed(value.trim()) : Effect.fail(new ActionMetadataInvalidError({
|
|
213
|
+
field,
|
|
214
|
+
character: codePoint(found)
|
|
215
|
+
}));
|
|
216
|
+
};
|
|
217
|
+
const stringField = (value, key) => {
|
|
218
|
+
const field = value[key];
|
|
219
|
+
return Predicate.isString(field) ? field : void 0;
|
|
220
|
+
};
|
|
221
|
+
const declaredIn = (value, key) => {
|
|
222
|
+
const field = value[key];
|
|
223
|
+
return Predicate.isObject(field) ? Object.keys(field) : [];
|
|
224
|
+
};
|
|
225
|
+
const readManifest = Effect.fnUntraced(function* (cwd) {
|
|
226
|
+
const fs = yield* FileSystem.FileSystem;
|
|
227
|
+
const path = yield* Path.Path;
|
|
228
|
+
const text = yield* fs.readFileString(path.join(cwd, "package.json")).pipe(Effect.catchReason("PlatformError", "NotFound", () => Effect.fail(new NotAPackageError({
|
|
229
|
+
cwd,
|
|
230
|
+
reason: "it has no package.json"
|
|
231
|
+
}))));
|
|
232
|
+
const parsed = yield* Effect.try({
|
|
233
|
+
try: () => JSON.parse(text),
|
|
234
|
+
catch: () => new NotAPackageError({
|
|
235
|
+
cwd,
|
|
236
|
+
reason: "its package.json is not valid JSON"
|
|
237
|
+
})
|
|
238
|
+
});
|
|
239
|
+
if (!Predicate.isObject(parsed)) return yield* new NotAPackageError({
|
|
240
|
+
cwd,
|
|
241
|
+
reason: "its package.json is not an object"
|
|
242
|
+
});
|
|
243
|
+
const name = stringField(parsed, "name");
|
|
244
|
+
return {
|
|
245
|
+
name: name === void 0 ? void 0 : name.replace(/^@[^/]+\//, ""),
|
|
246
|
+
description: stringField(parsed, "description"),
|
|
247
|
+
declared: new Set(["dependencies", "devDependencies"].flatMap((key) => declaredIn(parsed, key))),
|
|
248
|
+
typeModule: stringField(parsed, "type") === "module"
|
|
249
|
+
};
|
|
250
|
+
});
|
|
251
|
+
/**
|
|
252
|
+
* Scaffolds a new GitHub Action to the kit's canonical shape.
|
|
253
|
+
*
|
|
254
|
+
* @remarks
|
|
255
|
+
* {@link ActionInit.plan} is pure: it answers the files as data. {@link ActionInit.write} puts a plan on disk, and
|
|
256
|
+
* {@link ActionInit.run} is the front ends' one call, reading defaults from `package.json` first.
|
|
257
|
+
*
|
|
258
|
+
* @public
|
|
259
|
+
*/
|
|
260
|
+
var ActionInit = class ActionInit {
|
|
261
|
+
constructor() {}
|
|
262
|
+
/**
|
|
263
|
+
* The scaffold for one action: the `[action]` tables of `effected.toml`, `action.yml`, the `main` entry, the program
|
|
264
|
+
* it runs, and a `tsconfig.json` extending the kit's preset.
|
|
265
|
+
*
|
|
266
|
+
* @remarks
|
|
267
|
+
* It has only a `main` phase and requires no token, so it builds and runs as it stands; `pre`, `post` and App
|
|
268
|
+
* authentication are added when the action needs them. The `action.yml` carries branding, because a missing one is a
|
|
269
|
+
* warning, and a warning fails a build under CI.
|
|
270
|
+
*/
|
|
271
|
+
static plan(input) {
|
|
272
|
+
return ActionScaffold.make({
|
|
273
|
+
files: [
|
|
274
|
+
ActionScaffoldFile.make({
|
|
275
|
+
path: "effected.toml",
|
|
276
|
+
contents: effectedToml
|
|
277
|
+
}),
|
|
278
|
+
ActionScaffoldFile.make({
|
|
279
|
+
path: "action.yml",
|
|
280
|
+
contents: actionYml(input)
|
|
281
|
+
}),
|
|
282
|
+
ActionScaffoldFile.make({
|
|
283
|
+
path: "src/main.ts",
|
|
284
|
+
contents: mainTs
|
|
285
|
+
}),
|
|
286
|
+
ActionScaffoldFile.make({
|
|
287
|
+
path: "src/program.ts",
|
|
288
|
+
contents: programTs
|
|
289
|
+
}),
|
|
290
|
+
ActionScaffoldFile.make({
|
|
291
|
+
path: "tsconfig.json",
|
|
292
|
+
contents: tsconfigJson
|
|
293
|
+
})
|
|
294
|
+
],
|
|
295
|
+
dependencies: DEPENDENCIES,
|
|
296
|
+
devDependencies: DEV_DEPENDENCIES
|
|
297
|
+
});
|
|
298
|
+
}
|
|
299
|
+
/**
|
|
300
|
+
* Writes a scaffold under `cwd`.
|
|
301
|
+
*
|
|
302
|
+
* @remarks
|
|
303
|
+
* Every path is inspected with `lstat` before anything is written, so a refusal writes nothing:
|
|
304
|
+
*
|
|
305
|
+
* - A symbolic link at a file or at a directory the scaffold writes into is a {@link ScaffoldConflictError}, with or
|
|
306
|
+
* without `force`. A link is never followed and never replaced, so no write can leave `cwd` through one.
|
|
307
|
+
* - So is a directory or other non-file where a file goes, a file where a directory goes, an entry that cannot be
|
|
308
|
+
* inspected, and an existing file that cannot be written.
|
|
309
|
+
* - An existing regular file is a {@link ScaffoldExistsError} unless `force`, which replaces it.
|
|
310
|
+
*
|
|
311
|
+
* A name that differs from the scaffold's only in case (`Action.yml`) is a conflict too, and so is an existing directory,
|
|
312
|
+
* the action's own included, that this process may not write into.
|
|
313
|
+
*
|
|
314
|
+
* Then every directory is created and the files are written, each atomically and with a link at its path replaced
|
|
315
|
+
* rather than followed. Just before each write, the directories on its path are inspected again and the target is
|
|
316
|
+
* confirmed to resolve inside `cwd`. That is a point-in-time check: no committed link survives the pass above, but a
|
|
317
|
+
* concurrent local writer could still swap a directory for a link between the check and the write. Past the first
|
|
318
|
+
* check, a failure is {@link ScaffoldWriteError}, naming the path and the files already written.
|
|
319
|
+
*
|
|
320
|
+
* @returns The files written and the ones among them that were replaced.
|
|
321
|
+
*/
|
|
322
|
+
static write = Effect.fn("ActionInit.write")(function* (scaffold, options) {
|
|
323
|
+
const fs = yield* FileSystem.FileSystem;
|
|
324
|
+
const path = yield* Path.Path;
|
|
325
|
+
const root = yield* fs.realPath(path.resolve(options.cwd));
|
|
326
|
+
const at = (relative) => path.join(root, ...relative.split("/"));
|
|
327
|
+
const conflicts = [];
|
|
328
|
+
const conflict = (relative, kind) => conflicts.push(ScaffoldConflict.make({
|
|
329
|
+
path: relative,
|
|
330
|
+
kind
|
|
331
|
+
}));
|
|
332
|
+
/** The entry's type, `undefined` when nothing is there, or `null` when it could not be inspected. */
|
|
333
|
+
const probe = (relative) => Effect.map(Effect.result(fs.lstat(at(relative))), (info) => Result.isSuccess(info) ? info.success.type : info.failure.reason._tag === "NotFound" ? void 0 : null);
|
|
334
|
+
const directories = [...new Set(scaffold.files.flatMap((file) => {
|
|
335
|
+
const segments = file.path.split("/").slice(0, -1);
|
|
336
|
+
return segments.map((_, index) => segments.slice(0, index + 1).join("/"));
|
|
337
|
+
}))].sort((a, b) => a.split("/").length - b.split("/").length);
|
|
338
|
+
const blocked = /* @__PURE__ */ new Set();
|
|
339
|
+
const create = [];
|
|
340
|
+
const under = (paths, relative) => [...paths].some((parent) => relative.startsWith(`${parent}/`));
|
|
341
|
+
const parentOf = (relative) => relative.split("/").slice(0, -1).join("/");
|
|
342
|
+
const basename = (relative) => relative.split("/").at(-1) ?? relative;
|
|
343
|
+
const listings = /* @__PURE__ */ new Map();
|
|
344
|
+
const listing = (relative) => Effect.gen(function* () {
|
|
345
|
+
const cached = listings.get(relative);
|
|
346
|
+
if (cached !== void 0) return cached;
|
|
347
|
+
const read = yield* Effect.result(fs.readDirectory(relative === "" ? root : at(relative)));
|
|
348
|
+
const names = Result.isSuccess(read) ? read.success : null;
|
|
349
|
+
listings.set(relative, names);
|
|
350
|
+
return names;
|
|
351
|
+
});
|
|
352
|
+
const caseVariant = (relative) => Effect.map(listing(parentOf(relative)), (names) => {
|
|
353
|
+
const name = basename(relative);
|
|
354
|
+
return names !== null && !names.includes(name) && names.some((entry) => entry.toLowerCase() === name.toLowerCase());
|
|
355
|
+
});
|
|
356
|
+
const writable = (relative) => Effect.map(Effect.result(fs.access(relative === "" ? root : at(relative), { writable: true })), Result.isSuccess);
|
|
357
|
+
if (!(yield* writable(""))) conflict(".", "unwritable");
|
|
358
|
+
for (const directory of directories) {
|
|
359
|
+
if (under(blocked, directory)) continue;
|
|
360
|
+
if (under(create, directory)) {
|
|
361
|
+
create.push(directory);
|
|
362
|
+
continue;
|
|
363
|
+
}
|
|
364
|
+
if (yield* caseVariant(directory)) {
|
|
365
|
+
blocked.add(directory);
|
|
366
|
+
conflict(directory, "case-variant");
|
|
367
|
+
continue;
|
|
368
|
+
}
|
|
369
|
+
const type = yield* probe(directory);
|
|
370
|
+
if (type === void 0) create.push(directory);
|
|
371
|
+
else if (type !== "Directory") {
|
|
372
|
+
blocked.add(directory);
|
|
373
|
+
conflict(directory, type === null ? "unreadable" : type === "SymbolicLink" ? "symlink" : "not-a-directory");
|
|
374
|
+
} else if (!(yield* writable(directory))) {
|
|
375
|
+
blocked.add(directory);
|
|
376
|
+
conflict(directory, "unwritable");
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
const existing = [];
|
|
380
|
+
for (const file of scaffold.files) {
|
|
381
|
+
if (under(blocked, file.path) || under(create, file.path)) continue;
|
|
382
|
+
if (yield* caseVariant(file.path)) {
|
|
383
|
+
conflict(file.path, "case-variant");
|
|
384
|
+
continue;
|
|
385
|
+
}
|
|
386
|
+
const type = yield* probe(file.path);
|
|
387
|
+
if (type === void 0) continue;
|
|
388
|
+
if (type === "File") {
|
|
389
|
+
const replaceable = yield* Effect.result(fs.access(at(file.path), { writable: true }));
|
|
390
|
+
if (Result.isSuccess(replaceable)) existing.push(file.path);
|
|
391
|
+
else conflict(file.path, "unwritable");
|
|
392
|
+
} else conflict(file.path, type === null ? "unreadable" : type === "SymbolicLink" ? "symlink" : "not-a-file");
|
|
393
|
+
}
|
|
394
|
+
if (conflicts.length > 0) return yield* new ScaffoldConflictError({
|
|
395
|
+
cwd: root,
|
|
396
|
+
conflicts
|
|
397
|
+
});
|
|
398
|
+
if (existing.length > 0 && !options.force) return yield* new ScaffoldExistsError({
|
|
399
|
+
cwd: root,
|
|
400
|
+
files: existing
|
|
401
|
+
});
|
|
402
|
+
const written = [];
|
|
403
|
+
const failed = (relative) => (cause) => new ScaffoldWriteError({
|
|
404
|
+
cwd: root,
|
|
405
|
+
path: relative,
|
|
406
|
+
written: [...written],
|
|
407
|
+
cause
|
|
408
|
+
});
|
|
409
|
+
for (const directory of create) yield* fs.makeDirectory(at(directory)).pipe(Effect.mapError(failed(directory)));
|
|
410
|
+
const confined = (relative) => Effect.gen(function* () {
|
|
411
|
+
const segments = relative.split("/").slice(0, -1);
|
|
412
|
+
for (let index = 1; index <= segments.length; index++) if ((yield* probe(segments.slice(0, index).join("/"))) !== "Directory") return false;
|
|
413
|
+
return yield* PathContainment.isWithin(root, at(relative));
|
|
414
|
+
});
|
|
415
|
+
for (const file of scaffold.files) {
|
|
416
|
+
if (!(yield* confined(file.path))) return yield* failed(file.path)(/* @__PURE__ */ new Error(`${file.path} no longer resolves inside ${root}: a directory on its path changed after the checks`));
|
|
417
|
+
yield* AtomicFile.write(at(file.path), file.contents, { links: "replace" }).pipe(Effect.mapError(failed(file.path)));
|
|
418
|
+
written.push(file.path);
|
|
419
|
+
}
|
|
420
|
+
return {
|
|
421
|
+
written,
|
|
422
|
+
overwritten: existing
|
|
423
|
+
};
|
|
424
|
+
});
|
|
425
|
+
/**
|
|
426
|
+
* Scaffolds the action in `deps.cwd`: reads `package.json` for the name and description not given, plans, and
|
|
427
|
+
* writes.
|
|
428
|
+
*
|
|
429
|
+
* @remarks
|
|
430
|
+
* The error channel holds a run that could not start or finish: a directory with no readable `package.json`, a name or
|
|
431
|
+
* description found nowhere or holding a control character, files that exist without `force`, a path that cannot be
|
|
432
|
+
* written over ({@link ScaffoldConflictError}), and a write that failed. It edits no `package.json`: the result names
|
|
433
|
+
* the packages to add.
|
|
434
|
+
*/
|
|
435
|
+
static run = Effect.fn("ActionInit.run")(function* (input, deps) {
|
|
436
|
+
const cwd = (yield* Path.Path).resolve(deps.cwd);
|
|
437
|
+
const manifest = yield* readManifest(cwd);
|
|
438
|
+
const name = blank(input.name) ? manifest.name : input.name;
|
|
439
|
+
if (blank(name)) return yield* new ActionMetadataMissingError({ field: "name" });
|
|
440
|
+
const description = blank(input.description) ? manifest.description : input.description;
|
|
441
|
+
if (blank(description)) return yield* new ActionMetadataMissingError({ field: "description" });
|
|
442
|
+
const scaffold = ActionInit.plan({
|
|
443
|
+
name: yield* checked("name", name ?? ""),
|
|
444
|
+
description: yield* checked("description", description ?? "")
|
|
445
|
+
});
|
|
446
|
+
const { written, overwritten } = yield* ActionInit.write(scaffold, {
|
|
447
|
+
cwd,
|
|
448
|
+
force: input.force
|
|
449
|
+
});
|
|
450
|
+
return ActionInitResult.make({
|
|
451
|
+
cwd,
|
|
452
|
+
written,
|
|
453
|
+
overwritten,
|
|
454
|
+
missingDependencies: scaffold.dependencies.filter((dependency) => !manifest.declared.has(dependency)),
|
|
455
|
+
missingDevDependencies: scaffold.devDependencies.filter((dependency) => !manifest.declared.has(dependency)),
|
|
456
|
+
typeModule: manifest.typeModule
|
|
457
|
+
});
|
|
458
|
+
});
|
|
459
|
+
};
|
|
460
|
+
|
|
461
|
+
export { ActionInit, ActionInitResult, ActionMetadataInvalidError, ActionMetadataMissingError, ActionScaffold, ActionScaffoldFile, ScaffoldConflict, ScaffoldConflictError, ScaffoldExistsError, ScaffoldWriteError };
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { ActionRunResult } from "./ActionRunResult.js";
|
|
2
|
+
import { readPackageName, workspaceRootOf } from "./BuildRun.js";
|
|
3
|
+
import { Effect, Layer, Path, Schema } from "effect";
|
|
4
|
+
import { ActionBuildResult, ActionBuilder, BuildResult, EffectedConfigFile } from "@effected/bundler";
|
|
5
|
+
import { WorkspaceDiscovery, WorkspaceRoot } from "@effected/workspaces";
|
|
6
|
+
|
|
7
|
+
// src/build/ActionRun.ts
|
|
8
|
+
/**
|
|
9
|
+
* The directory asked to build as an action has no `[action]` table in its config, so it is a library.
|
|
10
|
+
*
|
|
11
|
+
* @public
|
|
12
|
+
*/
|
|
13
|
+
var NotAnActionError = class extends Schema.TaggedError()("NotAnActionError", {
|
|
14
|
+
/** The directory. */
|
|
15
|
+
cwd: Schema.String }) {
|
|
16
|
+
get message() {
|
|
17
|
+
return `${this.cwd} is not an action: its effected.toml has no [action] table`;
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
/** The partial result a builder failure stops with. No bundling happened when `build` is absent. */
|
|
21
|
+
const failedResult = (error) => ActionRunResult.make({
|
|
22
|
+
verdict: "failed",
|
|
23
|
+
result: ActionBuildResult.make({
|
|
24
|
+
validation: error.validation,
|
|
25
|
+
build: error.build ?? BuildResult.make({
|
|
26
|
+
success: false,
|
|
27
|
+
entries: [],
|
|
28
|
+
duration: 0
|
|
29
|
+
}),
|
|
30
|
+
persisted: false
|
|
31
|
+
})
|
|
32
|
+
});
|
|
33
|
+
/**
|
|
34
|
+
* Runs one GitHub Action build.
|
|
35
|
+
*
|
|
36
|
+
* @remarks
|
|
37
|
+
* Validation stopping the build and an entry failing to bundle or load are a `failed` verdict rather than a failure,
|
|
38
|
+
* with what happened so far in the result, so a front end can always render it. The error channel holds a run that could
|
|
39
|
+
* not start or finish: no `package.json`, a config that will not load, no `[action]` table, an entry that is missing
|
|
40
|
+
* with validation off, and a file that cannot be cleaned, written or persisted.
|
|
41
|
+
*
|
|
42
|
+
* It appends to no journal: the build and issue journals record package builds only.
|
|
43
|
+
*
|
|
44
|
+
* @public
|
|
45
|
+
*/
|
|
46
|
+
var ActionRun = class {
|
|
47
|
+
constructor() {}
|
|
48
|
+
static run = Effect.fn("ActionRun.run")(function* (input, deps) {
|
|
49
|
+
const cwd = (yield* Path.Path).resolve(deps.cwd);
|
|
50
|
+
yield* readPackageName(cwd);
|
|
51
|
+
const discovery = WorkspaceDiscovery.layer({ cwd }).pipe(Layer.provide(WorkspaceRoot.layer));
|
|
52
|
+
const root = yield* workspaceRootOf(cwd).pipe(Effect.provide(discovery));
|
|
53
|
+
const { config } = yield* EffectedConfigFile.load({
|
|
54
|
+
cwd,
|
|
55
|
+
root
|
|
56
|
+
}).pipe(Effect.provide(discovery));
|
|
57
|
+
if (config.action === void 0) return yield* new NotAnActionError({ cwd });
|
|
58
|
+
return yield* ActionBuilder.build({
|
|
59
|
+
cwd,
|
|
60
|
+
config: config.action,
|
|
61
|
+
validate: input.validate,
|
|
62
|
+
persist: input.persist,
|
|
63
|
+
ci: deps.ci
|
|
64
|
+
}).pipe(Effect.map((result) => ActionRunResult.make({
|
|
65
|
+
verdict: "ok",
|
|
66
|
+
result
|
|
67
|
+
})), Effect.catchTags({
|
|
68
|
+
ValidationFailed: (error) => Effect.succeed(failedResult(error)),
|
|
69
|
+
BuildFailed: (error) => Effect.succeed(failedResult(error))
|
|
70
|
+
}));
|
|
71
|
+
});
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
export { ActionRun, NotAnActionError };
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { Schema } from "effect";
|
|
2
|
+
import { ActionBuildResult } from "@effected/bundler";
|
|
3
|
+
|
|
4
|
+
// src/build/ActionRunResult.ts
|
|
5
|
+
/**
|
|
6
|
+
* One action build's answer: the verdict a front end maps to an exit code or returns as data, and what the build did.
|
|
7
|
+
*
|
|
8
|
+
* @public
|
|
9
|
+
*/
|
|
10
|
+
var ActionRunResult = class extends Schema.Class("ActionRunResult")({
|
|
11
|
+
/** `failed` when validation stopped the build or an entry failed to bundle or load. */
|
|
12
|
+
verdict: Schema.Literals(["ok", "failed"]),
|
|
13
|
+
/**
|
|
14
|
+
* What validation found, how bundling went and whether the build was persisted.
|
|
15
|
+
*
|
|
16
|
+
* @remarks
|
|
17
|
+
* When validation stops the build before bundling, `build` has no entries and `success: false`.
|
|
18
|
+
*/
|
|
19
|
+
result: ActionBuildResult
|
|
20
|
+
}) {};
|
|
21
|
+
|
|
22
|
+
export { ActionRunResult };
|