@savvy-web/github-action-builder 1.1.2 → 2.0.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.
- package/bin/github-action-builder.js +13 -18
- package/cli/commands/build.js +5 -5
- package/cli/commands/init.js +4 -4
- package/cli/commands/validate.js +1 -1
- package/github-action.js +3 -3
- package/index.d.ts +248 -272
- package/package.json +7 -14
- package/schemas/action-yml.js +272 -10
- package/schemas/config.js +13 -19
- package/schemas/path.js +7 -4
- package/services/build-live.js +5 -5
- package/services/build.js +22 -2
- package/services/config.js +21 -3
- package/services/persist-local-live.js +3 -2
- package/services/persist-local.js +2 -2
- package/services/validation-live.js +18 -17
- package/services/validation.js +22 -2
- package/tsdoc-metadata.json +1 -1
|
@@ -2,10 +2,10 @@ import { ActionYmlMissing, ActionYmlSchemaError, ActionYmlSyntaxError, MainEntry
|
|
|
2
2
|
import { ConfigService } from "./config.js";
|
|
3
3
|
import { ActionYml } from "../schemas/action-yml.js";
|
|
4
4
|
import { ValidationService } from "./validation.js";
|
|
5
|
-
import { Effect, Layer,
|
|
5
|
+
import { Effect, Layer, Result, Schema } from "effect";
|
|
6
6
|
import { existsSync, readFileSync } from "node:fs";
|
|
7
7
|
import { resolve } from "node:path";
|
|
8
|
-
import {
|
|
8
|
+
import { Yaml } from "@effected/yaml";
|
|
9
9
|
|
|
10
10
|
//#region src/services/validation-live.ts
|
|
11
11
|
/**
|
|
@@ -32,7 +32,7 @@ const makeWarning = (code, message, suggestion, file) => file !== void 0 ? {
|
|
|
32
32
|
/* v8 ignore start - only called for schema validation errors */
|
|
33
33
|
const formatSchemaErrors = (error, filePath) => [{
|
|
34
34
|
path: filePath,
|
|
35
|
-
message:
|
|
35
|
+
message: error.message
|
|
36
36
|
}];
|
|
37
37
|
/* v8 ignore stop */
|
|
38
38
|
/**
|
|
@@ -43,14 +43,15 @@ const ValidationServiceLive = Layer.effect(ValidationService, Effect.gen(functio
|
|
|
43
43
|
/** Read and parse action.yml file. */
|
|
44
44
|
const readActionYml = (path) => Effect.gen(function* () {
|
|
45
45
|
if (!existsSync(path)) return yield* new ActionYmlMissing({ cwd: path });
|
|
46
|
-
const
|
|
46
|
+
const content = yield* Effect.try({
|
|
47
47
|
try: () => readFileSync(path, "utf8"),
|
|
48
48
|
/* v8 ignore next */
|
|
49
49
|
catch: () => new ActionYmlSyntaxError({
|
|
50
50
|
path,
|
|
51
51
|
message: "Failed to read file"
|
|
52
52
|
})
|
|
53
|
-
})
|
|
53
|
+
});
|
|
54
|
+
const parsed = yield* Yaml.parse(content).pipe(
|
|
54
55
|
/* v8 ignore next 5 - requires malformed YAML */
|
|
55
56
|
Effect.mapError((error) => new ActionYmlSyntaxError({
|
|
56
57
|
path,
|
|
@@ -68,12 +69,12 @@ const ValidationServiceLive = Layer.effect(ValidationService, Effect.gen(functio
|
|
|
68
69
|
/** Validate parsed content against ActionYml schema. */
|
|
69
70
|
/* v8 ignore start - schema validation error branch */
|
|
70
71
|
const validateSchema = (parsed, path) => Effect.gen(function* () {
|
|
71
|
-
const result = Schema.
|
|
72
|
-
if (result
|
|
72
|
+
const result = yield* Effect.result(Schema.decodeUnknownEffect(ActionYml)(parsed));
|
|
73
|
+
if (Result.isFailure(result)) return yield* new ActionYmlSchemaError({
|
|
73
74
|
path,
|
|
74
|
-
errors: formatSchemaErrors(result.
|
|
75
|
+
errors: formatSchemaErrors(result.failure, path)
|
|
75
76
|
});
|
|
76
|
-
return result.
|
|
77
|
+
return result.success;
|
|
77
78
|
});
|
|
78
79
|
/* v8 ignore stop */
|
|
79
80
|
/** Check for recommended fields and generate warnings. */
|
|
@@ -113,12 +114,12 @@ const ValidationServiceLive = Layer.effect(ValidationService, Effect.gen(functio
|
|
|
113
114
|
const entriesConfig = { main: config.entries.main };
|
|
114
115
|
if (config.entries.pre) entriesConfig.pre = config.entries.pre;
|
|
115
116
|
if (config.entries.post) entriesConfig.post = config.entries.post;
|
|
116
|
-
const result = yield* Effect.
|
|
117
|
+
const result = yield* Effect.result(configService.detectEntries(cwd, entriesConfig));
|
|
117
118
|
/* v8 ignore start - error branch requires missing main entry */
|
|
118
|
-
if (result
|
|
119
|
+
if (Result.isFailure(result) && result.failure instanceof MainEntryMissing) errors.push({
|
|
119
120
|
code: "MAIN_ENTRY_MISSING",
|
|
120
|
-
message: `Main entry point not found: ${result.
|
|
121
|
-
file: result.
|
|
121
|
+
message: `Main entry point not found: ${result.failure.expectedPath}`,
|
|
122
|
+
file: result.failure.expectedPath,
|
|
122
123
|
suggestion: "Create src/main.ts or specify a different path in config"
|
|
123
124
|
});
|
|
124
125
|
/* v8 ignore stop */
|
|
@@ -134,9 +135,9 @@ const ValidationServiceLive = Layer.effect(ValidationService, Effect.gen(functio
|
|
|
134
135
|
warnings
|
|
135
136
|
};
|
|
136
137
|
const actionYmlPath = resolve(cwd, "action.yml");
|
|
137
|
-
const result = yield* Effect.
|
|
138
|
-
if (result
|
|
139
|
-
const error = result.
|
|
138
|
+
const result = yield* Effect.result(validateActionYml(actionYmlPath));
|
|
139
|
+
if (Result.isFailure(result)) {
|
|
140
|
+
const error = result.failure;
|
|
140
141
|
if (error instanceof ActionYmlMissing) warnings.push({
|
|
141
142
|
code: "ACTION_YML_MISSING",
|
|
142
143
|
message: "action.yml not found",
|
|
@@ -153,7 +154,7 @@ const ValidationServiceLive = Layer.effect(ValidationService, Effect.gen(functio
|
|
|
153
154
|
message: schemaError.message,
|
|
154
155
|
file: error.path
|
|
155
156
|
});
|
|
156
|
-
} else warnings.push(...result.
|
|
157
|
+
} else warnings.push(...result.success.warnings);
|
|
157
158
|
return {
|
|
158
159
|
errors,
|
|
159
160
|
warnings
|
package/services/validation.js
CHANGED
|
@@ -67,11 +67,31 @@ const ActionYmlResultSchema = Schema.Struct({
|
|
|
67
67
|
warnings: Schema.Array(ValidationWarningSchema)
|
|
68
68
|
});
|
|
69
69
|
/**
|
|
70
|
-
* ValidationService
|
|
70
|
+
* ValidationService key for dependency injection.
|
|
71
|
+
*
|
|
72
|
+
* @example Using ValidationService with Effect
|
|
73
|
+
* ```typescript
|
|
74
|
+
* import { Effect } from "effect";
|
|
75
|
+
* import { AppLayer, ConfigService, ValidationService } from "@savvy-web/github-action-builder";
|
|
76
|
+
*
|
|
77
|
+
* const program = Effect.gen(function* () {
|
|
78
|
+
* const configService = yield* ConfigService;
|
|
79
|
+
* const validationService = yield* ValidationService;
|
|
80
|
+
*
|
|
81
|
+
* const { config } = yield* configService.load();
|
|
82
|
+
* const result = yield* validationService.validate(config);
|
|
83
|
+
*
|
|
84
|
+
* if (!result.valid) {
|
|
85
|
+
* console.error("Validation failed:", result.errors);
|
|
86
|
+
* }
|
|
87
|
+
* });
|
|
88
|
+
*
|
|
89
|
+
* Effect.runPromise(program.pipe(Effect.provide(AppLayer)));
|
|
90
|
+
* ```
|
|
71
91
|
*
|
|
72
92
|
* @public
|
|
73
93
|
*/
|
|
74
|
-
|
|
94
|
+
var ValidationService = class extends Context.Service()("ValidationService") {};
|
|
75
95
|
|
|
76
96
|
//#endregion
|
|
77
97
|
export { ActionYmlResultSchema, ValidateOptionsSchema, ValidationErrorSchema, ValidationResultSchema, ValidationService, ValidationWarningSchema };
|