@expo/steps 1.0.37 → 1.0.50
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/LICENSE +1 -1
- package/dist_commonjs/BuildConfig.cjs +6 -4
- package/dist_commonjs/BuildConfig.d.ts +1 -0
- package/dist_commonjs/BuildConfig.js.map +1 -1
- package/dist_commonjs/BuildConfigParser.cjs +8 -3
- package/dist_commonjs/BuildConfigParser.js.map +1 -1
- package/dist_commonjs/BuildFunction.cjs +2 -1
- package/dist_commonjs/BuildFunction.d.ts +2 -1
- package/dist_commonjs/BuildFunction.js.map +1 -1
- package/dist_commonjs/BuildStep.cjs +23 -2
- package/dist_commonjs/BuildStep.d.ts +6 -2
- package/dist_commonjs/BuildStep.js.map +1 -1
- package/dist_commonjs/BuildStepContext.cjs +5 -1
- package/dist_commonjs/BuildStepContext.d.ts +2 -0
- package/dist_commonjs/BuildStepContext.js.map +1 -1
- package/dist_commonjs/BuildWorkflow.cjs +17 -1
- package/dist_commonjs/BuildWorkflow.js.map +1 -1
- package/dist_commonjs/utils/template.cjs +16 -1
- package/dist_commonjs/utils/template.d.ts +6 -0
- package/dist_commonjs/utils/template.js.map +1 -1
- package/dist_esm/BuildConfig.d.ts +1 -0
- package/dist_esm/BuildConfig.js +7 -5
- package/dist_esm/BuildConfig.js.map +1 -1
- package/dist_esm/BuildConfigParser.js +9 -4
- package/dist_esm/BuildConfigParser.js.map +1 -1
- package/dist_esm/BuildFunction.d.ts +2 -1
- package/dist_esm/BuildFunction.js +2 -1
- package/dist_esm/BuildFunction.js.map +1 -1
- package/dist_esm/BuildStep.d.ts +6 -2
- package/dist_esm/BuildStep.js +24 -3
- package/dist_esm/BuildStep.js.map +1 -1
- package/dist_esm/BuildStepContext.d.ts +2 -0
- package/dist_esm/BuildStepContext.js +5 -1
- package/dist_esm/BuildStepContext.js.map +1 -1
- package/dist_esm/BuildWorkflow.js +17 -1
- package/dist_esm/BuildWorkflow.js.map +1 -1
- package/dist_esm/utils/template.d.ts +6 -0
- package/dist_esm/utils/template.js +14 -0
- package/dist_esm/utils/template.js.map +1 -1
- package/package.json +2 -2
|
@@ -14,6 +14,7 @@ class BuildStepGlobalContext {
|
|
|
14
14
|
constructor(provider, skipCleanup) {
|
|
15
15
|
this.provider = provider;
|
|
16
16
|
this.skipCleanup = skipCleanup;
|
|
17
|
+
this.didCheckOut = false;
|
|
17
18
|
this.stepById = {};
|
|
18
19
|
this.stepsInternalBuildDirectory = path_1.default.join(os_1.default.tmpdir(), 'eas-build', (0, uuid_1.v4)());
|
|
19
20
|
this.runtimePlatform = provider.runtimePlatform;
|
|
@@ -26,7 +27,7 @@ class BuildStepGlobalContext {
|
|
|
26
27
|
return this.provider.projectTargetDirectory;
|
|
27
28
|
}
|
|
28
29
|
get defaultWorkingDirectory() {
|
|
29
|
-
return this.provider.defaultWorkingDirectory;
|
|
30
|
+
return this.didCheckOut ? this.provider.defaultWorkingDirectory : this.projectTargetDirectory;
|
|
30
31
|
}
|
|
31
32
|
get buildLogsDirectory() {
|
|
32
33
|
return this.provider.buildLogsDirectory;
|
|
@@ -64,6 +65,9 @@ class BuildStepGlobalContext {
|
|
|
64
65
|
stepCtx(options) {
|
|
65
66
|
return new BuildStepContext(this, options);
|
|
66
67
|
}
|
|
68
|
+
markAsCheckedOut() {
|
|
69
|
+
this.didCheckOut = true;
|
|
70
|
+
}
|
|
67
71
|
serialize() {
|
|
68
72
|
return {
|
|
69
73
|
stepsInternalBuildDirectory: this.stepsInternalBuildDirectory,
|
|
@@ -34,6 +34,7 @@ export declare class BuildStepGlobalContext {
|
|
|
34
34
|
stepsInternalBuildDirectory: string;
|
|
35
35
|
readonly runtimePlatform: BuildRuntimePlatform;
|
|
36
36
|
readonly baseLogger: bunyan;
|
|
37
|
+
private didCheckOut;
|
|
37
38
|
private stepById;
|
|
38
39
|
constructor(provider: ExternalBuildContextProvider, skipCleanup: boolean);
|
|
39
40
|
get projectSourceDirectory(): string;
|
|
@@ -50,6 +51,7 @@ export declare class BuildStepGlobalContext {
|
|
|
50
51
|
logger: bunyan;
|
|
51
52
|
workingDirectory: string;
|
|
52
53
|
}): BuildStepContext;
|
|
54
|
+
markAsCheckedOut(): void;
|
|
53
55
|
serialize(): SerializedBuildStepGlobalContext;
|
|
54
56
|
static deserialize(serialized: SerializedBuildStepGlobalContext, logger: bunyan): BuildStepGlobalContext;
|
|
55
57
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BuildStepContext.js","sourceRoot":"","sources":["../src/BuildStepContext.ts"],"names":[],"mappings":";;;;;;AAAA,4CAAoB;AACpB,gDAAwB;AAGxB,+BAAoC;AAEpC,iDAIwB;AACxB,qDAI6B;AAC7B,2CAAoD;AAmCpD,MAAa,sBAAsB;IAOjC,YACmB,QAAsC,EACvC,WAAoB;QADnB,aAAQ,GAAR,QAAQ,CAA8B;QACvC,gBAAW,GAAX,WAAW,CAAS;QAJ9B,aAAQ,GAA4C,EAAE,CAAC;QAM7D,IAAI,CAAC,2BAA2B,GAAG,cAAI,CAAC,IAAI,CAAC,YAAE,CAAC,MAAM,EAAE,EAAE,WAAW,EAAE,IAAA,SAAM,GAAE,CAAC,CAAC;QACjF,IAAI,CAAC,eAAe,GAAG,QAAQ,CAAC,eAAe,CAAC;QAChD,IAAI,CAAC,UAAU,GAAG,QAAQ,CAAC,MAAM,CAAC;IACpC,CAAC;IAED,IAAW,sBAAsB;QAC/B,OAAO,IAAI,CAAC,QAAQ,CAAC,sBAAsB,CAAC;IAC9C,CAAC;IAED,IAAW,sBAAsB;QAC/B,OAAO,IAAI,CAAC,QAAQ,CAAC,sBAAsB,CAAC;IAC9C,CAAC;IAED,IAAW,uBAAuB;QAChC,OAAO,IAAI,CAAC,QAAQ,CAAC,uBAAuB,CAAC;IAC/C,CAAC;IAED,IAAW,kBAAkB;QAC3B,OAAO,IAAI,CAAC,QAAQ,CAAC,kBAAkB,CAAC;IAC1C,CAAC;IAED,IAAW,GAAG;QACZ,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path from 'path';\n\nimport { bunyan } from '@expo/logger';\nimport { v4 as uuidv4 } from 'uuid';\n\nimport {\n BuildStep,\n BuildStepOutputAccessor,\n SerializedBuildStepOutputAccessor,\n} from './BuildStep.js';\nimport {\n getObjectValueForInterpolation,\n interpolateWithGlobalContext,\n parseOutputPath,\n} from './utils/template.js';\nimport { BuildStepRuntimeError } from './errors.js';\nimport { BuildRuntimePlatform } from './BuildRuntimePlatform.js';\nimport { BuildStepEnv } from './BuildStepEnv.js';\n\ninterface SerializedExternalBuildContextProvider {\n projectSourceDirectory: string;\n projectTargetDirectory: string;\n defaultWorkingDirectory: string;\n buildLogsDirectory: string;\n runtimePlatform: BuildRuntimePlatform;\n staticContext: Record<string, any>;\n env: BuildStepEnv;\n}\n\nexport interface ExternalBuildContextProvider {\n readonly projectSourceDirectory: string;\n readonly projectTargetDirectory: string;\n readonly defaultWorkingDirectory: string;\n readonly buildLogsDirectory: string;\n readonly runtimePlatform: BuildRuntimePlatform;\n readonly logger: bunyan;\n\n readonly staticContext: () => Record<string, any>;\n\n readonly env: BuildStepEnv;\n updateEnv(env: BuildStepEnv): void;\n}\n\nexport interface SerializedBuildStepGlobalContext {\n stepsInternalBuildDirectory: string;\n stepById: Record<string, SerializedBuildStepOutputAccessor>;\n provider: SerializedExternalBuildContextProvider;\n skipCleanup: boolean;\n}\n\nexport class BuildStepGlobalContext {\n public stepsInternalBuildDirectory: string;\n public readonly runtimePlatform: BuildRuntimePlatform;\n public readonly baseLogger: bunyan;\n\n private stepById: Record<string, BuildStepOutputAccessor> = {};\n\n constructor(\n private readonly provider: ExternalBuildContextProvider,\n public readonly skipCleanup: boolean\n ) {\n this.stepsInternalBuildDirectory = path.join(os.tmpdir(), 'eas-build', uuidv4());\n this.runtimePlatform = provider.runtimePlatform;\n this.baseLogger = provider.logger;\n }\n\n public get projectSourceDirectory(): string {\n return this.provider.projectSourceDirectory;\n }\n\n public get projectTargetDirectory(): string {\n return this.provider.projectTargetDirectory;\n }\n\n public get defaultWorkingDirectory(): string {\n return this.provider.defaultWorkingDirectory;\n }\n\n public get buildLogsDirectory(): string {\n return this.provider.buildLogsDirectory;\n }\n\n public get env(): BuildStepEnv {\n return this.provider.env;\n }\n\n public get staticContext(): Record<string, any> {\n return this.provider.staticContext();\n }\n\n public updateEnv(updatedEnv: BuildStepEnv): void {\n this.provider.updateEnv(updatedEnv);\n }\n\n public registerStep(step: BuildStep): void {\n this.stepById[step.id] = step;\n }\n\n public getStepOutputValue(path: string): string | undefined {\n const { stepId, outputId } = parseOutputPath(path);\n if (!(stepId in this.stepById)) {\n throw new BuildStepRuntimeError(`Step \"${stepId}\" does not exist.`);\n }\n return this.stepById[stepId].getOutputValueByName(outputId);\n }\n\n public interpolate(value: string): string {\n return interpolateWithGlobalContext(value, (path) => {\n return (\n getObjectValueForInterpolation(path, {\n eas: {\n runtimePlatform: this.runtimePlatform,\n ...this.staticContext,\n },\n })?.toString() ?? ''\n );\n });\n }\n\n public stepCtx(options: { logger: bunyan; workingDirectory: string }): BuildStepContext {\n return new BuildStepContext(this, options);\n }\n\n public serialize(): SerializedBuildStepGlobalContext {\n return {\n stepsInternalBuildDirectory: this.stepsInternalBuildDirectory,\n stepById: Object.fromEntries(\n Object.entries(this.stepById).map(([id, step]) => [id, step.serialize()])\n ),\n provider: {\n projectSourceDirectory: this.provider.projectSourceDirectory,\n projectTargetDirectory: this.provider.projectTargetDirectory,\n defaultWorkingDirectory: this.provider.defaultWorkingDirectory,\n buildLogsDirectory: this.provider.buildLogsDirectory,\n runtimePlatform: this.provider.runtimePlatform,\n staticContext: this.provider.staticContext(),\n env: this.provider.env,\n },\n skipCleanup: this.skipCleanup,\n };\n }\n\n public static deserialize(\n serialized: SerializedBuildStepGlobalContext,\n logger: bunyan\n ): BuildStepGlobalContext {\n const deserializedProvider: ExternalBuildContextProvider = {\n projectSourceDirectory: serialized.provider.projectSourceDirectory,\n projectTargetDirectory: serialized.provider.projectTargetDirectory,\n defaultWorkingDirectory: serialized.provider.defaultWorkingDirectory,\n buildLogsDirectory: serialized.provider.buildLogsDirectory,\n runtimePlatform: serialized.provider.runtimePlatform,\n logger,\n staticContext: () => serialized.provider.staticContext,\n env: serialized.provider.env,\n updateEnv: () => {},\n };\n const ctx = new BuildStepGlobalContext(deserializedProvider, serialized.skipCleanup);\n for (const [id, stepOutputAccessor] of Object.entries(serialized.stepById)) {\n ctx.stepById[id] = BuildStepOutputAccessor.deserialize(stepOutputAccessor);\n }\n ctx.stepsInternalBuildDirectory = serialized.stepsInternalBuildDirectory;\n\n return ctx;\n }\n}\n\nexport interface SerializedBuildStepContext {\n workingDirectory: string;\n global: SerializedBuildStepGlobalContext;\n}\n\nexport class BuildStepContext {\n public readonly logger: bunyan;\n public readonly workingDirectory: string;\n\n constructor(\n private readonly ctx: BuildStepGlobalContext,\n {\n logger,\n workingDirectory,\n }: {\n logger: bunyan;\n workingDirectory: string;\n }\n ) {\n this.logger = logger ?? ctx.baseLogger;\n this.workingDirectory = workingDirectory ?? ctx.defaultWorkingDirectory;\n }\n\n public get global(): BuildStepGlobalContext {\n return this.ctx;\n }\n\n public serialize(): SerializedBuildStepContext {\n return {\n workingDirectory: this.workingDirectory,\n global: this.ctx.serialize(),\n };\n }\n\n public static deserialize(\n serialized: SerializedBuildStepContext,\n logger: bunyan\n ): BuildStepContext {\n const deserializedGlobal = BuildStepGlobalContext.deserialize(serialized.global, logger);\n return new BuildStepContext(deserializedGlobal, {\n logger,\n workingDirectory: serialized.workingDirectory,\n });\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"BuildStepContext.js","sourceRoot":"","sources":["../src/BuildStepContext.ts"],"names":[],"mappings":";;;;;;AAAA,4CAAoB;AACpB,gDAAwB;AAGxB,+BAAoC;AAEpC,iDAIwB;AACxB,qDAI6B;AAC7B,2CAAoD;AAmCpD,MAAa,sBAAsB;IAQjC,YACmB,QAAsC,EACvC,WAAoB;QADnB,aAAQ,GAAR,QAAQ,CAA8B;QACvC,gBAAW,GAAX,WAAW,CAA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gB;IAI3B,YACmB,GAA2B,EAC5C,EACE,MAAM,EACN,gBAAgB,GAIjB;QAPgB,QAAG,GAAH,GAAG,CAAwB;QAS5C,IAAI,CAAC,MAAM,GAAG,MAAM,aAAN,MAAM,cAAN,MAAM,GAAI,GAAG,CAAC,UAAU,CAAC;QACvC,IAAI,CAAC,gBAAgB,GAAG,gBAAgB,aAAhB,gBAAgB,cAAhB,gBAAgB,GAAI,GAAG,CAAC,uBAAuB,CAAC;IAC1E,CAAC;IAED,IAAW,MAAM;QACf,OAAO,IAAI,CAAC,GAAG,CAAC;IAClB,CAAC;IAEM,SAAS;QACd,OAAO;YACL,gBAAgB,EAAE,IAAI,CAAC,gBAAgB;YACvC,MAAM,EAAE,IAAI,CAAC,GAAG,CAAC,SAAS,EAAE;SAC7B,CAAC;IACJ,CAAC;IAEM,MAAM,CAAC,WAAW,CACvB,UAAsC,EACtC,MAAc;QAEd,MAAM,kBAAkB,GAAG,sBAAsB,CAAC,WAAW,CAAC,UAAU,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;QACzF,OAAO,IAAI,gBAAgB,CAAC,kBAAkB,EAAE;YAC9C,MAAM;YACN,gBAAgB,EAAE,UAAU,CAAC,gBAAgB;SAC9C,CAAC,CAAC;IACL,CAAC;CACF;AAvCD,4CAuCC","sourcesContent":["import os from 'os';\nimport path from 'path';\n\nimport { bunyan } from '@expo/logger';\nimport { v4 as uuidv4 } from 'uuid';\n\nimport {\n BuildStep,\n BuildStepOutputAccessor,\n SerializedBuildStepOutputAccessor,\n} from './BuildStep.js';\nimport {\n getObjectValueForInterpolation,\n interpolateWithGlobalContext,\n parseOutputPath,\n} from './utils/template.js';\nimport { BuildStepRuntimeError } from './errors.js';\nimport { BuildRuntimePlatform } from './BuildRuntimePlatform.js';\nimport { BuildStepEnv } from './BuildStepEnv.js';\n\ninterface SerializedExternalBuildContextProvider {\n projectSourceDirectory: string;\n projectTargetDirectory: string;\n defaultWorkingDirectory: string;\n buildLogsDirectory: string;\n runtimePlatform: BuildRuntimePlatform;\n staticContext: Record<string, any>;\n env: BuildStepEnv;\n}\n\nexport interface ExternalBuildContextProvider {\n readonly projectSourceDirectory: string;\n readonly projectTargetDirectory: string;\n readonly defaultWorkingDirectory: string;\n readonly buildLogsDirectory: string;\n readonly runtimePlatform: BuildRuntimePlatform;\n readonly logger: bunyan;\n\n readonly staticContext: () => Record<string, any>;\n\n readonly env: BuildStepEnv;\n updateEnv(env: BuildStepEnv): void;\n}\n\nexport interface SerializedBuildStepGlobalContext {\n stepsInternalBuildDirectory: string;\n stepById: Record<string, SerializedBuildStepOutputAccessor>;\n provider: SerializedExternalBuildContextProvider;\n skipCleanup: boolean;\n}\n\nexport class BuildStepGlobalContext {\n public stepsInternalBuildDirectory: string;\n public readonly runtimePlatform: BuildRuntimePlatform;\n public readonly baseLogger: bunyan;\n private didCheckOut = false;\n\n private stepById: Record<string, BuildStepOutputAccessor> = {};\n\n constructor(\n private readonly provider: ExternalBuildContextProvider,\n public readonly skipCleanup: boolean\n ) {\n this.stepsInternalBuildDirectory = path.join(os.tmpdir(), 'eas-build', uuidv4());\n this.runtimePlatform = provider.runtimePlatform;\n this.baseLogger = provider.logger;\n }\n\n public get projectSourceDirectory(): string {\n return this.provider.projectSourceDirectory;\n }\n\n public get projectTargetDirectory(): string {\n return this.provider.projectTargetDirectory;\n }\n\n public get defaultWorkingDirectory(): string {\n return this.didCheckOut ? this.provider.defaultWorkingDirectory : this.projectTargetDirectory;\n }\n\n public get buildLogsDirectory(): string {\n return this.provider.buildLogsDirectory;\n }\n\n public get env(): BuildStepEnv {\n return this.provider.env;\n }\n\n public get staticContext(): Record<string, any> {\n return this.provider.staticContext();\n }\n\n public updateEnv(updatedEnv: BuildStepEnv): void {\n this.provider.updateEnv(updatedEnv);\n }\n\n public registerStep(step: BuildStep): void {\n this.stepById[step.id] = step;\n }\n\n public getStepOutputValue(path: string): string | undefined {\n const { stepId, outputId } = parseOutputPath(path);\n if (!(stepId in this.stepById)) {\n throw new BuildStepRuntimeError(`Step \"${stepId}\" does not exist.`);\n }\n return this.stepById[stepId].getOutputValueByName(outputId);\n }\n\n public interpolate(value: string): string {\n return interpolateWithGlobalContext(value, (path) => {\n return (\n getObjectValueForInterpolation(path, {\n eas: {\n runtimePlatform: this.runtimePlatform,\n ...this.staticContext,\n },\n })?.toString() ?? ''\n );\n });\n }\n\n public stepCtx(options: { logger: bunyan; workingDirectory: string }): BuildStepContext {\n return new BuildStepContext(this, options);\n }\n\n public markAsCheckedOut(): void {\n this.didCheckOut = true;\n }\n\n public serialize(): SerializedBuildStepGlobalContext {\n return {\n stepsInternalBuildDirectory: this.stepsInternalBuildDirectory,\n stepById: Object.fromEntries(\n Object.entries(this.stepById).map(([id, step]) => [id, step.serialize()])\n ),\n provider: {\n projectSourceDirectory: this.provider.projectSourceDirectory,\n projectTargetDirectory: this.provider.projectTargetDirectory,\n defaultWorkingDirectory: this.provider.defaultWorkingDirectory,\n buildLogsDirectory: this.provider.buildLogsDirectory,\n runtimePlatform: this.provider.runtimePlatform,\n staticContext: this.provider.staticContext(),\n env: this.provider.env,\n },\n skipCleanup: this.skipCleanup,\n };\n }\n\n public static deserialize(\n serialized: SerializedBuildStepGlobalContext,\n logger: bunyan\n ): BuildStepGlobalContext {\n const deserializedProvider: ExternalBuildContextProvider = {\n projectSourceDirectory: serialized.provider.projectSourceDirectory,\n projectTargetDirectory: serialized.provider.projectTargetDirectory,\n defaultWorkingDirectory: serialized.provider.defaultWorkingDirectory,\n buildLogsDirectory: serialized.provider.buildLogsDirectory,\n runtimePlatform: serialized.provider.runtimePlatform,\n logger,\n staticContext: () => serialized.provider.staticContext,\n env: serialized.provider.env,\n updateEnv: () => {},\n };\n const ctx = new BuildStepGlobalContext(deserializedProvider, serialized.skipCleanup);\n for (const [id, stepOutputAccessor] of Object.entries(serialized.stepById)) {\n ctx.stepById[id] = BuildStepOutputAccessor.deserialize(stepOutputAccessor);\n }\n ctx.stepsInternalBuildDirectory = serialized.stepsInternalBuildDirectory;\n\n return ctx;\n }\n}\n\nexport interface SerializedBuildStepContext {\n workingDirectory: string;\n global: SerializedBuildStepGlobalContext;\n}\n\nexport class BuildStepContext {\n public readonly logger: bunyan;\n public readonly workingDirectory: string;\n\n constructor(\n private readonly ctx: BuildStepGlobalContext,\n {\n logger,\n workingDirectory,\n }: {\n logger: bunyan;\n workingDirectory: string;\n }\n ) {\n this.logger = logger ?? ctx.baseLogger;\n this.workingDirectory = workingDirectory ?? ctx.defaultWorkingDirectory;\n }\n\n public get global(): BuildStepGlobalContext {\n return this.ctx;\n }\n\n public serialize(): SerializedBuildStepContext {\n return {\n workingDirectory: this.workingDirectory,\n global: this.ctx.serialize(),\n };\n }\n\n public static deserialize(\n serialized: SerializedBuildStepContext,\n logger: bunyan\n ): BuildStepContext {\n const deserializedGlobal = BuildStepGlobalContext.deserialize(serialized.global, logger);\n return new BuildStepContext(deserializedGlobal, {\n logger,\n workingDirectory: serialized.workingDirectory,\n });\n }\n}\n"]}
|
|
@@ -10,8 +10,24 @@ class BuildWorkflow {
|
|
|
10
10
|
this.buildFunctions = buildFunctions;
|
|
11
11
|
}
|
|
12
12
|
async executeAsync() {
|
|
13
|
+
let maybeError = null;
|
|
14
|
+
let hasAnyPreviousStepFailed = false;
|
|
13
15
|
for (const step of this.buildSteps) {
|
|
14
|
-
|
|
16
|
+
if (step.shouldExecuteStep(hasAnyPreviousStepFailed)) {
|
|
17
|
+
try {
|
|
18
|
+
await step.executeAsync();
|
|
19
|
+
}
|
|
20
|
+
catch (err) {
|
|
21
|
+
maybeError = maybeError !== null && maybeError !== void 0 ? maybeError : err;
|
|
22
|
+
hasAnyPreviousStepFailed = true;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
else {
|
|
26
|
+
step.skip();
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
if (maybeError) {
|
|
30
|
+
throw maybeError;
|
|
15
31
|
}
|
|
16
32
|
}
|
|
17
33
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BuildWorkflow.js","sourceRoot":"","sources":["../src/BuildWorkflow.ts"],"names":[],"mappings":";;;AAIA,MAAa,aAAa;IAIxB;IACE,wFAAwF;IACvE,GAA2B,EAC5C,EAAE,UAAU,EAAE,cAAc,EAAkE;QAD7E,QAAG,GAAH,GAAG,CAAwB;QAG5C,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;QAC7B,IAAI,CAAC,cAAc,GAAG,cAAc,CAAC;IACvC,CAAC;IAEM,KAAK,CAAC,YAAY;QACvB,KAAK,MAAM,IAAI,IAAI,IAAI,CAAC,UAAU,EAAE;YAClC,MAAM,IAAI,CAAC,YAAY,EAAE,CAAC;
|
|
1
|
+
{"version":3,"file":"BuildWorkflow.js","sourceRoot":"","sources":["../src/BuildWorkflow.ts"],"names":[],"mappings":";;;AAIA,MAAa,aAAa;IAIxB;IACE,wFAAwF;IACvE,GAA2B,EAC5C,EAAE,UAAU,EAAE,cAAc,EAAkE;QAD7E,QAAG,GAAH,GAAG,CAAwB;QAG5C,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;QAC7B,IAAI,CAAC,cAAc,GAAG,cAAc,CAAC;IACvC,CAAC;IAEM,KAAK,CAAC,YAAY;QACvB,IAAI,UAAU,GAAiB,IAAI,CAAC;QACpC,IAAI,wBAAwB,GAAG,KAAK,CAAC;QACrC,KAAK,MAAM,IAAI,IAAI,IAAI,CAAC,UAAU,EAAE;YAClC,IAAI,IAAI,CAAC,iBAAiB,CAAC,wBAAwB,CAAC,EAAE;gBACpD,IAAI;oBACF,MAAM,IAAI,CAAC,YAAY,EAAE,CAAC;iBAC3B;gBAAC,OAAO,GAAQ,EAAE;oBACjB,UAAU,GAAG,UAAU,aAAV,UAAU,cAAV,UAAU,GAAI,GAAG,CAAC;oBAC/B,wBAAwB,GAAG,IAAI,CAAC;iBACjC;aACF;iBAAM;gBACL,IAAI,CAAC,IAAI,EAAE,CAAC;aACb;SACF;QAED,IAAI,UAAU,EAAE;YACd,MAAM,UAAU,CAAC;SAClB;IACH,CAAC;CACF;AAjCD,sCAiCC","sourcesContent":["import { BuildFunctionById } from './BuildFunction.js';\nimport { BuildStep } from './BuildStep.js';\nimport { BuildStepGlobalContext } from './BuildStepContext.js';\n\nexport class BuildWorkflow {\n public readonly buildSteps: BuildStep[];\n public readonly buildFunctions: BuildFunctionById;\n\n constructor(\n // @ts-expect-error ctx is not used in this class but let's keep it here for consistency\n private readonly ctx: BuildStepGlobalContext,\n { buildSteps, buildFunctions }: { buildSteps: BuildStep[]; buildFunctions: BuildFunctionById }\n ) {\n this.buildSteps = buildSteps;\n this.buildFunctions = buildFunctions;\n }\n\n public async executeAsync(): Promise<void> {\n let maybeError: Error | null = null;\n let hasAnyPreviousStepFailed = false;\n for (const step of this.buildSteps) {\n if (step.shouldExecuteStep(hasAnyPreviousStepFailed)) {\n try {\n await step.executeAsync();\n } catch (err: any) {\n maybeError = maybeError ?? err;\n hasAnyPreviousStepFailed = true;\n }\n } else {\n step.skip();\n }\n }\n\n if (maybeError) {\n throw maybeError;\n }\n }\n}\n"]}
|
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.parseOutputPath = exports.findOutputPaths = exports.interpolateWithGlobalContext = exports.getObjectValueForInterpolation = exports.interpolateWithOutputs = exports.interpolateWithInputs = exports.BUILD_STEP_OR_BUILD_GLOBAL_CONTEXT_REFERENCE_REGEX = exports.BUILD_GLOBAL_CONTEXT_EXPRESSION_REGEXP = exports.BUILD_STEP_OUTPUT_EXPRESSION_REGEXP = exports.BUILD_STEP_INPUT_EXPRESSION_REGEXP = void 0;
|
|
6
|
+
exports.parseOutputPath = exports.findOutputPaths = exports.interpolateWithGlobalContext = exports.getObjectValueForInterpolation = exports.getSelectedStatusCheckFromIfStatementTemplate = exports.interpolateWithOutputs = exports.interpolateWithInputs = exports.BUILD_STEP_IF_CONDITION_EXPRESSION_REGEXP = exports.BUILD_STEP_OR_BUILD_GLOBAL_CONTEXT_REFERENCE_REGEX = exports.BUILD_GLOBAL_CONTEXT_EXPRESSION_REGEXP = exports.BUILD_STEP_OUTPUT_EXPRESSION_REGEXP = exports.BUILD_STEP_INPUT_EXPRESSION_REGEXP = void 0;
|
|
7
7
|
const lodash_get_1 = __importDefault(require("lodash.get"));
|
|
8
8
|
const BuildStepInput_js_1 = require("../BuildStepInput.cjs");
|
|
9
9
|
const errors_js_1 = require("../errors.cjs");
|
|
@@ -12,6 +12,7 @@ exports.BUILD_STEP_INPUT_EXPRESSION_REGEXP = /\${\s*(inputs\.[\S]+)\s*}/;
|
|
|
12
12
|
exports.BUILD_STEP_OUTPUT_EXPRESSION_REGEXP = /\${\s*(steps\.[\S]+)\s*}/;
|
|
13
13
|
exports.BUILD_GLOBAL_CONTEXT_EXPRESSION_REGEXP = /\${\s*(eas\.[\S]+)\s*}/;
|
|
14
14
|
exports.BUILD_STEP_OR_BUILD_GLOBAL_CONTEXT_REFERENCE_REGEX = /\${\s*((steps|eas)\.[\S]+)\s*}/;
|
|
15
|
+
exports.BUILD_STEP_IF_CONDITION_EXPRESSION_REGEXP = /\${\s*(always|success|failure)\(\)\s*}/;
|
|
15
16
|
function interpolateWithInputs(templateString, inputs) {
|
|
16
17
|
return interpolate(templateString, exports.BUILD_STEP_INPUT_EXPRESSION_REGEXP, inputs);
|
|
17
18
|
}
|
|
@@ -20,6 +21,20 @@ function interpolateWithOutputs(templateString, fn) {
|
|
|
20
21
|
return interpolate(templateString, exports.BUILD_STEP_OUTPUT_EXPRESSION_REGEXP, fn);
|
|
21
22
|
}
|
|
22
23
|
exports.interpolateWithOutputs = interpolateWithOutputs;
|
|
24
|
+
/**
|
|
25
|
+
* Returns the selected status check from the if statement template.
|
|
26
|
+
* Example: `${ success() }` -> `success`
|
|
27
|
+
*/
|
|
28
|
+
function getSelectedStatusCheckFromIfStatementTemplate(ifCondition) {
|
|
29
|
+
const matched = ifCondition.match(new RegExp(exports.BUILD_STEP_IF_CONDITION_EXPRESSION_REGEXP, 'g'));
|
|
30
|
+
if (!matched) {
|
|
31
|
+
// this should never happen because of regex pattern validation
|
|
32
|
+
throw new errors_js_1.BuildConfigError(`Invalid if condition template.`);
|
|
33
|
+
}
|
|
34
|
+
const [, selectedStatusCheck] = (0, nullthrows_js_1.nullthrows)(matched[0].match(exports.BUILD_STEP_IF_CONDITION_EXPRESSION_REGEXP));
|
|
35
|
+
return selectedStatusCheck;
|
|
36
|
+
}
|
|
37
|
+
exports.getSelectedStatusCheckFromIfStatementTemplate = getSelectedStatusCheckFromIfStatementTemplate;
|
|
23
38
|
function getObjectValueForInterpolation(path, obj) {
|
|
24
39
|
const value = (0, lodash_get_1.default)(obj, path);
|
|
25
40
|
if (value === undefined) {
|
|
@@ -2,8 +2,14 @@ export declare const BUILD_STEP_INPUT_EXPRESSION_REGEXP: RegExp;
|
|
|
2
2
|
export declare const BUILD_STEP_OUTPUT_EXPRESSION_REGEXP: RegExp;
|
|
3
3
|
export declare const BUILD_GLOBAL_CONTEXT_EXPRESSION_REGEXP: RegExp;
|
|
4
4
|
export declare const BUILD_STEP_OR_BUILD_GLOBAL_CONTEXT_REFERENCE_REGEX: RegExp;
|
|
5
|
+
export declare const BUILD_STEP_IF_CONDITION_EXPRESSION_REGEXP: RegExp;
|
|
5
6
|
export declare function interpolateWithInputs(templateString: string, inputs: Record<string, string>): string;
|
|
6
7
|
export declare function interpolateWithOutputs(templateString: string, fn: (path: string) => string): string;
|
|
8
|
+
/**
|
|
9
|
+
* Returns the selected status check from the if statement template.
|
|
10
|
+
* Example: `${ success() }` -> `success`
|
|
11
|
+
*/
|
|
12
|
+
export declare function getSelectedStatusCheckFromIfStatementTemplate(ifCondition: string): 'success' | 'failure' | 'always';
|
|
7
13
|
export declare function getObjectValueForInterpolation(path: string, obj: Record<string, any>): string | number | boolean | null;
|
|
8
14
|
export declare function interpolateWithGlobalContext(templateString: string, fn: (path: string) => string): string;
|
|
9
15
|
interface BuildOutputPath {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"template.js","sourceRoot":"","sources":["../../src/utils/template.ts"],"names":[],"mappings":";;;;;;AAAA,4DAA6B;AAE7B,4DAAmE;AACnE,4CAAuE;AAEvE,mDAA6C;AAEhC,QAAA,kCAAkC,GAAG,2BAA2B,CAAC;AACjE,QAAA,mCAAmC,GAAG,0BAA0B,CAAC;AACjE,QAAA,sCAAsC,GAAG,wBAAwB,CAAC;AAClE,QAAA,kDAAkD,GAAG,gCAAgC,CAAC;
|
|
1
|
+
{"version":3,"file":"template.js","sourceRoot":"","sources":["../../src/utils/template.ts"],"names":[],"mappings":";;;;;;AAAA,4DAA6B;AAE7B,4DAAmE;AACnE,4CAAuE;AAEvE,mDAA6C;AAEhC,QAAA,kCAAkC,GAAG,2BAA2B,CAAC;AACjE,QAAA,mCAAmC,GAAG,0BAA0B,CAAC;AACjE,QAAA,sCAAsC,GAAG,wBAAwB,CAAC;AAClE,QAAA,kDAAkD,GAAG,gCAAgC,CAAC;AACtF,QAAA,yCAAyC,GAAG,wCAAwC,CAAC;AAElG,SAAgB,qBAAqB,CACnC,cAAsB,EACtB,MAA8B;IAE9B,OAAO,WAAW,CAAC,cAAc,EAAE,0CAAkC,EAAE,MAAM,CAAC,CAAC;AACjF,CAAC;AALD,sDAKC;AAED,SAAgB,sBAAsB,CACpC,cAAsB,EACtB,EAA4B;IAE5B,OAAO,WAAW,CAAC,cAAc,EAAE,2CAAmC,EAAE,EAAE,CAAC,CAAC;AAC9E,CAAC;AALD,wDAKC;AAED;;;GAGG;AACH,SAAgB,6CAA6C,CAC3D,WAAmB;IAEnB,MAAM,OAAO,GAAG,WAAW,CAAC,KAAK,CAAC,IAAI,MAAM,CAAC,iDAAyC,EAAE,GAAG,CAAC,CAAC,CAAC;IAC9F,IAAI,CAAC,OAAO,EAAE;QACZ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AAC,MAAM,KAAK,CAAC,EAAE;QACvB,MAAM,IAAI,4BAAgB,CACxB,gKAAgK,wBAAwB,GAAG,CAC5L,CAAC;KACH;IACD,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC,GAAG,MAAM,CAAC;IAClC,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC;AAC9B,CAAC;AATD,0CASC","sourcesContent":["import get from 'lodash.get';\n\nimport { BuildStepInputValueTypeName } from '../BuildStepInput.js';\nimport { BuildConfigError, BuildStepRuntimeError } from '../errors.js';\n\nimport { nullthrows } from './nullthrows.js';\n\nexport const BUILD_STEP_INPUT_EXPRESSION_REGEXP = /\\${\\s*(inputs\\.[\\S]+)\\s*}/;\nexport const BUILD_STEP_OUTPUT_EXPRESSION_REGEXP = /\\${\\s*(steps\\.[\\S]+)\\s*}/;\nexport const BUILD_GLOBAL_CONTEXT_EXPRESSION_REGEXP = /\\${\\s*(eas\\.[\\S]+)\\s*}/;\nexport const BUILD_STEP_OR_BUILD_GLOBAL_CONTEXT_REFERENCE_REGEX = /\\${\\s*((steps|eas)\\.[\\S]+)\\s*}/;\nexport const BUILD_STEP_IF_CONDITION_EXPRESSION_REGEXP = /\\${\\s*(always|success|failure)\\(\\)\\s*}/;\n\nexport function interpolateWithInputs(\n templateString: string,\n inputs: Record<string, string>\n): string {\n return interpolate(templateString, BUILD_STEP_INPUT_EXPRESSION_REGEXP, inputs);\n}\n\nexport function interpolateWithOutputs(\n templateString: string,\n fn: (path: string) => string\n): string {\n return interpolate(templateString, BUILD_STEP_OUTPUT_EXPRESSION_REGEXP, fn);\n}\n\n/**\n * Returns the selected status check from the if statement template.\n * Example: `${ success() }` -> `success`\n */\nexport function getSelectedStatusCheckFromIfStatementTemplate(\n ifCondition: string\n): 'success' | 'failure' | 'always' {\n const matched = ifCondition.match(new RegExp(BUILD_STEP_IF_CONDITION_EXPRESSION_REGEXP, 'g'));\n if (!matched) {\n // this should never happen because of regex pattern validation\n throw new BuildConfigError(`Invalid if condition template.`);\n }\n const [, selectedStatusCheck] = nullthrows(\n matched[0].match(BUILD_STEP_IF_CONDITION_EXPRESSION_REGEXP)\n );\n return selectedStatusCheck as 'success' | 'failure' | 'always';\n}\n\nexport function getObjectValueForInterpolation(\n path: string,\n obj: Record<string, any>\n): string | number | boolean | null {\n const value = get(obj, path);\n\n if (value === undefined) {\n throw new BuildStepRuntimeError(\n `Object field \"${path}\" does not exist. Ensure you are using the correct field name.`\n );\n }\n\n if (!isAllowedValueTypeForObjectInterpolation(value)) {\n throw new BuildStepRuntimeError(\n `EAS context field \"${path}\" is not of type ${Object.values(BuildStepInputValueTypeName).join(\n ', '\n )}, or undefined. It is of type \"${typeof value}\". We currently only support accessing string or undefined values from the EAS context.`\n );\n }\n\n if (value !== null && typeof value === 'object') {\n return JSON.stringify(value);\n }\n\n return value;\n}\n\nexport function interpolateWithGlobalContext(\n templateString: string,\n fn: (path: string) => string\n): string {\n return interpolate(templateString, BUILD_GLOBAL_CONTEXT_EXPRESSION_REGEXP, fn);\n}\n\nfunction interpolate(\n templateString: string,\n regex: RegExp,\n varsOrFn: Record<string, string> | ((key: string) => string)\n): string {\n const matched = templateString.match(new RegExp(regex, 'g'));\n if (!matched) {\n return templateString;\n }\n let result = templateString;\n for (const match of matched) {\n const [, path] = nullthrows(match.match(regex));\n const value = typeof varsOrFn === 'function' ? varsOrFn(path) : varsOrFn[path.split('.')[1]];\n result = result.replace(match, value);\n }\n return result;\n}\n\nfunction isAllowedValueTypeForObjectInterpolation(\n value: any\n): value is string | number | boolean | object | null {\n return (\n typeof value === 'string' ||\n typeof value === 'number' ||\n typeof value === 'boolean' ||\n typeof value === 'object' ||\n value === null\n );\n}\n\ninterface BuildOutputPath {\n stepId: string;\n outputId: string;\n}\n\nexport function findOutputPaths(templateString: string): BuildOutputPath[] {\n const result: BuildOutputPath[] = [];\n const matches = templateString.matchAll(new RegExp(BUILD_STEP_OUTPUT_EXPRESSION_REGEXP, 'g'));\n for (const match of matches) {\n result.push(parseOutputPath(match[1]));\n }\n return result;\n}\n\nexport function parseOutputPath(outputPathWithObjectName: string): BuildOutputPath {\n const splits = outputPathWithObjectName.split('.').slice(1);\n if (splits.length !== 2) {\n throw new BuildConfigError(\n `Step output path must consist of two components joined with a dot, where first is the step ID, and second is the output name, e.g. \"step3.output1\". Passed: \"${outputPathWithObjectName}\"`\n );\n }\n const [stepId, outputId] = splits;\n return { stepId, outputId };\n}\n"]}
|
|
@@ -34,6 +34,7 @@ export type BuildFunctionCallConfig = {
|
|
|
34
34
|
workingDirectory?: string;
|
|
35
35
|
shell?: string;
|
|
36
36
|
env?: BuildStepEnv;
|
|
37
|
+
if?: string;
|
|
37
38
|
};
|
|
38
39
|
export type BuildStepInputs = Record<string, BuildStepInputValueTypeWithRequired>;
|
|
39
40
|
export type BuildStepOutputs = (string | {
|
package/dist_esm/BuildConfig.js
CHANGED
|
@@ -7,7 +7,7 @@ import { BuildConfigError, BuildWorkflowError } from './errors.js';
|
|
|
7
7
|
import { BuildRuntimePlatform } from './BuildRuntimePlatform.js';
|
|
8
8
|
import { BuildFunction } from './BuildFunction.js';
|
|
9
9
|
import { BuildStepInputValueTypeName, } from './BuildStepInput.js';
|
|
10
|
-
import { BUILD_STEP_OR_BUILD_GLOBAL_CONTEXT_REFERENCE_REGEX } from './utils/template.js';
|
|
10
|
+
import { BUILD_STEP_IF_CONDITION_EXPRESSION_REGEXP, BUILD_STEP_OR_BUILD_GLOBAL_CONTEXT_REFERENCE_REGEX, } from './utils/template.js';
|
|
11
11
|
const BuildFunctionInputsSchema = Joi.array().items(Joi.alternatives().conditional(Joi.ref('.'), {
|
|
12
12
|
is: Joi.string(),
|
|
13
13
|
then: Joi.string().required(),
|
|
@@ -78,8 +78,10 @@ const BuildFunctionCallSchema = Joi.object({
|
|
|
78
78
|
workingDirectory: Joi.string(),
|
|
79
79
|
shell: Joi.string(),
|
|
80
80
|
env: Joi.object().pattern(Joi.string(), Joi.string().allow('')),
|
|
81
|
+
if: Joi.string().pattern(BUILD_STEP_IF_CONDITION_EXPRESSION_REGEXP, 'allowed "if" condition values regex'),
|
|
81
82
|
}).rename('working_directory', 'workingDirectory');
|
|
82
83
|
const BuildStepConfigSchema = Joi.any()
|
|
84
|
+
.invalid(null)
|
|
83
85
|
.when(Joi.object().pattern(Joi.string().disallow('run').required(), Joi.object().unknown().required()), {
|
|
84
86
|
then: Joi.object().pattern(Joi.string().disallow('run').min(1).required(), BuildFunctionCallSchema.required(), { matches: Joi.array().length(1) }),
|
|
85
87
|
})
|
|
@@ -223,13 +225,13 @@ export function mergeConfigWithImportedFunctions(config, importedFunctions) {
|
|
|
223
225
|
}
|
|
224
226
|
}
|
|
225
227
|
export function isBuildStepCommandRun(step) {
|
|
226
|
-
return typeof step === 'object' && typeof step.run === 'object';
|
|
228
|
+
return Boolean(step) && typeof step === 'object' && typeof step.run === 'object';
|
|
227
229
|
}
|
|
228
230
|
export function isBuildStepBareCommandRun(step) {
|
|
229
|
-
return typeof step === 'object' && typeof step.run === 'string';
|
|
231
|
+
return Boolean(step) && typeof step === 'object' && typeof step.run === 'string';
|
|
230
232
|
}
|
|
231
233
|
export function isBuildStepFunctionCall(step) {
|
|
232
|
-
return typeof step === 'object' && !('run' in step);
|
|
234
|
+
return Boolean(step) && typeof step === 'object' && !('run' in step);
|
|
233
235
|
}
|
|
234
236
|
export function isBuildStepBareFunctionCall(step) {
|
|
235
237
|
return typeof step === 'string';
|
|
@@ -240,7 +242,7 @@ export function validateAllFunctionsExist(config, { externalFunctionIds = [], sk
|
|
|
240
242
|
if (typeof step === 'string') {
|
|
241
243
|
calledFunctionsSet.add(step);
|
|
242
244
|
}
|
|
243
|
-
else if (!('run' in step)) {
|
|
245
|
+
else if (step !== null && !('run' in step)) {
|
|
244
246
|
const keys = Object.keys(step);
|
|
245
247
|
assert(keys.length === 1, 'There must be at most one function call in the step (enforced by joi).');
|
|
246
248
|
calledFunctionsSet.add(keys[0]);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"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IAAI,GAAG,CAAC,mBAAmB,CAAC,CAAC;IAC5D,MAAM,oBAAoB,GAAG,eAAe,CAAC,MAAM,CAAC,CAAC,cAAc,EAAE,EAAE;;QACrE,IAAI,aAAa,CAAC,mBAAmB,CAAC,cAAc,CAAC,IAAI,4BAA4B,EAAE;YACrF,OAAO,KAAK,CAAC;SACd;QACD,OAAO,CACL,CAAC,CAAC,cAAc,IAAI,CAAC,MAAA,MAAM,CAAC,SAAS,mCAAI,EAAE,CAAC,CAAC,IAAI,CAAC,sBAAsB,CAAC,GAAG,CAAC,cAAc,CAAC,CAC7F,CAAC;IACJ,CAAC,CAAC,CAAC;IACH,IAAI,oBAAoB,CAAC,MAAM,GAAG,CAAC,EAAE;QACnC,MAAM,IAAI,gBAAgB,CACxB,mCAAmC,oBAAoB,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAC3F,CAAC;KACH;AACH,CAAC;AAED,SAAS,sCAAsC,CAAC,GAAW,EAAE,kBAA0B;IACrF,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,kBAAkB,CAAC,EAAE;QACxC,OAAO,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,kBAAkB,CAAC,CAAC;KAC9C;IACD,OAAO,kBAAkB,CAAC;AAC5B,CAAC","sourcesContent":["import assert from 'assert';\nimport fs from 'fs/promises';\nimport path from 'path';\n\nimport Joi from 'joi';\nimport YAML from 'yaml';\n\nimport { BuildConfigError, BuildWorkflowError } from './errors.js';\nimport { BuildRuntimePlatform } from './BuildRuntimePlatform.js';\nimport { BuildFunction } from './BuildFunction.js';\nimport {\n BuildStepInputValueTypeWithRequired,\n BuildStepInputValueTypeName,\n BuildStepInputValueType,\n} from './BuildStepInput.js';\nimport { BuildStepEnv } from './BuildStepEnv.js';\nimport { BUILD_STEP_OR_BUILD_GLOBAL_CONTEXT_REFERENCE_REGEX } from './utils/template.js';\n\nexport type BuildFunctions = Record<string, BuildFunctionConfig>;\n\ninterface BuildFunctionsConfigFile {\n configFilesToImport?: string[];\n functions?: BuildFunctions;\n}\n\nexport interface BuildConfig extends BuildFunctionsConfigFile {\n build: {\n name?: string;\n steps: BuildStepConfig[];\n };\n}\n\nexport type BuildStepConfig =\n | BuildStepCommandRun\n | BuildStepBareCommandRun\n | BuildStepFunctionCall\n | BuildStepBareFunctionCall;\n\nexport type BuildStepCommandRun = {\n run: BuildFunctionCallConfig & {\n outputs?: BuildStepOutputs;\n command: string;\n };\n};\nexport type BuildStepBareCommandRun = { run: string };\nexport type BuildStepFunctionCall = {\n [functionId: string]: BuildFunctionCallConfig;\n};\nexport type BuildStepBareFunctionCall = string;\n\nexport type BuildFunctionCallConfig = {\n id?: string;\n inputs?: BuildStepInputs;\n name?: string;\n workingDirectory?: string;\n shell?: string;\n env?: BuildStepEnv;\n};\n\nexport type BuildStepInputs = Record<string, BuildStepInputValueTypeWithRequired>;\nexport type BuildStepOutputs = (\n | string\n | {\n name: string;\n required?: boolean;\n }\n)[];\n\nexport interface BuildFunctionConfig {\n inputs?: BuildFunctionInputs;\n outputs?: BuildFunctionOutputs;\n name?: string;\n supportedRuntimePlatforms?: BuildRuntimePlatform[];\n shell?: string;\n command?: string;\n path?: string;\n}\n\nexport type BuildFunctionInputs = (\n | string\n | {\n name: string;\n defaultValue?: BuildStepInputValueType;\n allowedValues?: BuildStepInputValueType[];\n required?: boolean;\n allowedValueType: BuildStepInputValueTypeName;\n }\n)[];\nexport type BuildFunctionOutputs = BuildStepOutputs;\n\nconst BuildFunctionInputsSchema = Joi.array().items(\n Joi.alternatives().conditional(Joi.ref('.'), {\n is: Joi.string(),\n then: Joi.string().required(),\n otherwise: Joi.object({\n name: Joi.string().required(),\n defaultValue: Joi.when('allowedValues', {\n is: Joi.exist(),\n then: Joi.valid(Joi.in('allowedValues')).messages({\n 'any.only': '{{#label}} must be one of allowed values',\n }),\n })\n .when('allowedValueType', {\n is: BuildStepInputValueTypeName.STRING,\n then: Joi.string().allow(''),\n })\n .when('allowedValueType', {\n is: BuildStepInputValueTypeName.BOOLEAN,\n then: Joi.alternatives(\n Joi.boolean(),\n Joi.string().pattern(\n BUILD_STEP_OR_BUILD_GLOBAL_CONTEXT_REFERENCE_REGEX,\n 'context or output reference regex pattern'\n )\n ).messages({\n 'alternatives.types':\n '{{#label}} must be a boolean or reference to output or context value',\n }),\n })\n .when('allowedValueType', {\n is: BuildStepInputValueTypeName.NUMBER,\n then: Joi.alternatives(\n Joi.number(),\n Joi.string().pattern(\n BUILD_STEP_OR_BUILD_GLOBAL_CONTEXT_REFERENCE_REGEX,\n 'context or output reference regex pattern'\n )\n ).messages({\n 'alternatives.types':\n '{{#label}} must be a number or reference to output or context value',\n }),\n })\n .when('allowedValueType', {\n is: BuildStepInputValueTypeName.JSON,\n then: Joi.alternatives(\n Joi.object(),\n Joi.string().pattern(\n BUILD_STEP_OR_BUILD_GLOBAL_CONTEXT_REFERENCE_REGEX,\n 'context or output reference regex pattern'\n )\n ).messages({\n 'alternatives.types':\n '{{#label}} must be a object or reference to output or context value',\n }),\n }),\n allowedValues: Joi.when('allowedValueType', {\n is: BuildStepInputValueTypeName.STRING,\n then: Joi.array().items(Joi.string().allow('')),\n })\n .when('allowedValueType', {\n is: BuildStepInputValueTypeName.BOOLEAN,\n then: Joi.array().items(Joi.boolean()),\n })\n .when('allowedValueType', {\n is: BuildStepInputValueTypeName.NUMBER,\n then: Joi.array().items(Joi.number()),\n })\n .when('allowedValueType', {\n is: BuildStepInputValueTypeName.JSON,\n then: Joi.array().items(Joi.object()),\n }),\n allowedValueType: Joi.string()\n .valid(...Object.values(BuildStepInputValueTypeName))\n .default(BuildStepInputValueTypeName.STRING),\n required: Joi.boolean(),\n })\n .rename('allowed_values', 'allowedValues')\n .rename('default_value', 'defaultValue')\n .rename('type', 'allowedValueType')\n .required(),\n })\n);\n\nconst BuildStepOutputsSchema = Joi.array().items(\n Joi.alternatives().try(\n Joi.string().required(),\n Joi.object({\n name: Joi.string().required(),\n required: Joi.boolean(),\n }).required()\n )\n);\n\nconst BuildFunctionCallSchema = Joi.object({\n id: Joi.string(),\n inputs: Joi.object().pattern(\n Joi.string(),\n Joi.alternatives().try(Joi.string().allow(''), Joi.boolean(), Joi.number(), Joi.object())\n ),\n name: Joi.string(),\n workingDirectory: Joi.string(),\n shell: Joi.string(),\n env: Joi.object().pattern(Joi.string(), Joi.string().allow('')),\n}).rename('working_directory', 'workingDirectory');\n\nconst BuildStepConfigSchema = Joi.any<BuildStepConfig>()\n .when(\n Joi.object().pattern(\n Joi.string().disallow('run').required(),\n Joi.object().unknown().required()\n ),\n {\n then: Joi.object().pattern(\n Joi.string().disallow('run').min(1).required(),\n BuildFunctionCallSchema.required(),\n { matches: Joi.array().length(1) }\n ),\n }\n )\n .when(Joi.object({ run: Joi.object().unknown().required() }), {\n then: Joi.object({\n run: BuildFunctionCallSchema.keys({\n outputs: BuildStepOutputsSchema,\n command: Joi.string().required(),\n }),\n }),\n })\n .when(Joi.object({ run: Joi.string().required() }), {\n then: Joi.object({\n run: Joi.string().min(1).required(),\n }),\n })\n .when(Joi.string(), {\n then: Joi.string().min(1),\n });\n\nconst BuildFunctionConfigSchema = Joi.object({\n name: Joi.string(),\n supportedRuntimePlatforms: Joi.array().items(...Object.values(BuildRuntimePlatform)),\n inputs: BuildFunctionInputsSchema,\n outputs: BuildStepOutputsSchema,\n command: Joi.string(),\n path: Joi.string(),\n shell: Joi.string(),\n})\n .rename('supported_platforms', 'supportedRuntimePlatforms')\n .xor('command', 'path')\n .nand('command', 'path');\n\nexport const BuildFunctionsConfigFileSchema = Joi.object<BuildFunctionsConfigFile>({\n configFilesToImport: Joi.array().items(Joi.string().pattern(/\\.y(a)?ml$/)),\n functions: Joi.object().pattern(\n Joi.string()\n .pattern(/^[\\w-]+$/, 'function names')\n .min(1)\n .required()\n .disallow('run'),\n BuildFunctionConfigSchema.required()\n ),\n})\n .rename('import', 'configFilesToImport')\n .required();\n\nexport const BuildConfigSchema = BuildFunctionsConfigFileSchema.append<BuildConfig>({\n build: Joi.object({\n name: Joi.string(),\n steps: Joi.array().items(BuildStepConfigSchema.required()).required(),\n }).required(),\n}).required();\n\ninterface BuildConfigValidationParams {\n externalFunctionIds?: string[];\n skipNamespacedFunctionsCheck?: boolean;\n}\n\nexport async function readAndValidateBuildConfigAsync(\n configPath: string,\n params: BuildConfigValidationParams = {}\n): Promise<BuildConfig> {\n const rawConfig = await readRawBuildConfigAsync(configPath);\n\n const config = validateConfig(BuildConfigSchema, rawConfig);\n for (const functionName in config.functions) {\n const customFunctionPath = config.functions[functionName].path;\n if (customFunctionPath) {\n config.functions[functionName].path = maybeResolveCustomFunctionRelativePath(\n path.dirname(configPath),\n customFunctionPath\n );\n }\n }\n\n const importedFunctions = await importFunctionsAsync(configPath, config.configFilesToImport);\n mergeConfigWithImportedFunctions(config, importedFunctions);\n validateAllFunctionsExist(config, params);\n return config;\n}\n\nasync function importFunctionsAsync(\n baseConfigPath: string,\n configPathsToImport?: string[]\n): Promise<BuildFunctions> {\n if (!configPathsToImport) {\n return {};\n }\n\n const baseConfigDir = path.dirname(baseConfigPath);\n\n const errors: BuildConfigError[] = [];\n const importedFunctions: BuildFunctions = {};\n // this is a set of visited files identified by ABSOLUTE paths\n const visitedFiles = new Set<string>([baseConfigPath]);\n const configFilesToVisit = (configPathsToImport ?? []).map((childConfigRelativePath) =>\n path.resolve(baseConfigDir, childConfigRelativePath)\n );\n while (configFilesToVisit.length > 0) {\n const childConfigPath = configFilesToVisit.shift();\n assert(childConfigPath, 'Guaranteed by loop condition');\n if (visitedFiles.has(childConfigPath)) {\n continue;\n }\n visitedFiles.add(childConfigPath);\n try {\n const childConfig = await readAndValidateBuildFunctionsConfigFileAsync(childConfigPath);\n const childDir = path.dirname(childConfigPath);\n for (const functionName in childConfig.functions) {\n if (!(functionName in importedFunctions)) {\n const f = childConfig.functions[functionName];\n if (f.path) {\n f.path = maybeResolveCustomFunctionRelativePath(childDir, f.path);\n }\n importedFunctions[functionName] = f;\n }\n }\n if (childConfig.configFilesToImport) {\n configFilesToVisit.push(\n ...childConfig.configFilesToImport.map((relativePath) =>\n path.resolve(childDir, relativePath)\n )\n );\n }\n } catch (err) {\n if (err instanceof BuildConfigError) {\n errors.push(err);\n } else {\n throw err;\n }\n }\n }\n if (errors.length > 0) {\n throw new BuildWorkflowError(`Detected build config errors in imported files.`, errors);\n }\n return importedFunctions;\n}\n\nexport async function readAndValidateBuildFunctionsConfigFileAsync(\n configPath: string\n): Promise<BuildFunctionsConfigFile> {\n const rawConfig = await readRawBuildConfigAsync(configPath);\n return validateConfig(BuildFunctionsConfigFileSchema, rawConfig);\n}\n\nexport async function readRawBuildConfigAsync(configPath: string): Promise<any> {\n const contents = await fs.readFile(configPath, 'utf-8');\n return YAML.parse(contents);\n}\n\nexport function validateConfig<T>(\n schema: Joi.ObjectSchema<T>,\n config: object,\n configFilePath?: string\n): T {\n const { error, value } = schema.validate(config, {\n allowUnknown: false,\n abortEarly: false,\n });\n if (error) {\n const errorMessage = error.details.map(({ message }) => message).join(', ');\n throw new BuildConfigError(errorMessage, {\n cause: error,\n ...(configFilePath && { metadata: { configFilePath } }),\n });\n }\n return value;\n}\n\nexport function mergeConfigWithImportedFunctions(\n config: BuildConfig,\n importedFunctions: BuildFunctions\n): void {\n if (Object.keys(importedFunctions).length === 0) {\n return;\n }\n config.functions = config.functions ?? {};\n for (const functionName in importedFunctions) {\n if (!(functionName in config.functions)) {\n config.functions[functionName] = importedFunctions[functionName];\n }\n }\n}\n\nexport function isBuildStepCommandRun(step: BuildStepConfig): step is BuildStepCommandRun {\n return typeof step === 'object' && typeof step.run === 'object';\n}\n\nexport function isBuildStepBareCommandRun(step: BuildStepConfig): step is BuildStepBareCommandRun {\n return typeof step === 'object' && typeof step.run === 'string';\n}\n\nexport function isBuildStepFunctionCall(step: BuildStepConfig): step is BuildStepFunctionCall {\n return typeof step === 'object' && !('run' in step);\n}\n\nexport function isBuildStepBareFunctionCall(\n step: BuildStepConfig\n): step is BuildStepBareFunctionCall {\n return typeof step === 'string';\n}\n\nexport function validateAllFunctionsExist(\n config: BuildConfig,\n { externalFunctionIds = [], skipNamespacedFunctionsCheck }: BuildConfigValidationParams\n): void {\n const calledFunctionsSet = new Set<string>();\n for (const step of config.build.steps) {\n if (typeof step === 'string') {\n calledFunctionsSet.add(step);\n } else if (!('run' in step)) {\n const keys = Object.keys(step);\n assert(\n keys.length === 1,\n 'There must be at most one function call in the step (enforced by joi).'\n );\n calledFunctionsSet.add(keys[0]);\n }\n }\n const calledFunctions = Array.from(calledFunctionsSet);\n const externalFunctionIdsSet = new Set(externalFunctionIds);\n const nonExistentFunctions = calledFunctions.filter((calledFunction) => {\n if (BuildFunction.isFulldIdNamespaced(calledFunction) && skipNamespacedFunctionsCheck) {\n return false;\n }\n return (\n !(calledFunction in (config.functions ?? {})) && !externalFunctionIdsSet.has(calledFunction)\n );\n });\n if (nonExistentFunctions.length > 0) {\n throw new BuildConfigError(\n `Calling non-existent functions: ${nonExistentFunctions.map((f) => `\"${f}\"`).join(', ')}.`\n );\n }\n}\n\nfunction maybeResolveCustomFunctionRelativePath(dir: string, customFunctionPath: string): string {\n if (!path.isAbsolute(customFunctionPath)) {\n return path.resolve(dir, customFunctionPath);\n }\n return customFunctionPath;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"BuildConfig.js","sourceRoot":"","sources":["../src/BuildConfig.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,QAAQ,CAAC;AAC5B,OAAO,EAAE,MAAM,aAAa,CAAC;AAC7B,OAAO,IAAI,MAAM,MAAM,CAAC;AAExB,OAAO,GAAG,MAAM,KAAK,CAAC;AACtB,OAAO,IAAI,MAAM,MAAM,CAAC;AAExB,OAAO,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AACnE,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AACjE,OAAO,EAAE,aAAa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B,CAAC,cAAc,CAAC,IAAI,4BAA4B,EAAE;YACrF,OAAO,KAAK,CAAC;SACd;QACD,OAAO,CACL,CAAC,CAAC,cAAc,IAAI,CAAC,MAAA,MAAM,CAAC,SAAS,mCAAI,EAAE,CAAC,CAAC,IAAI,CAAC,sBAAsB,CAAC,GAAG,CAAC,cAAc,CAAC,CAC7F,CAAC;IACJ,CAAC,CAAC,CAAC;IACH,IAAI,oBAAoB,CAAC,MAAM,GAAG,CAAC,EAAE;QACnC,MAAM,IAAI,gBAAgB,CACxB,mCAAmC,oBAAoB,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAC3F,CAAC;KACH;AACH,CAAC;AAED,SAAS,sCAAsC,CAAC,GAAW,EAAE,kBAA0B;IACrF,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,kBAAkB,CAAC,EAAE;QACxC,OAAO,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,kBAAkB,CAAC,CAAC;KAC9C;IACD,OAAO,kBAAkB,CAAC;AAC5B,CAAC","sourcesContent":["import assert from 'assert';\nimport fs from 'fs/promises';\nimport path from 'path';\n\nimport Joi from 'joi';\nimport YAML from 'yaml';\n\nimport { BuildConfigError, BuildWorkflowError } from './errors.js';\nimport { BuildRuntimePlatform } from './BuildRuntimePlatform.js';\nimport { BuildFunction } from './BuildFunction.js';\nimport {\n BuildStepInputValueTypeWithRequired,\n BuildStepInputValueTypeName,\n BuildStepInputValueType,\n} from './BuildStepInput.js';\nimport { BuildStepEnv } from './BuildStepEnv.js';\nimport {\n BUILD_STEP_IF_CONDITION_EXPRESSION_REGEXP,\n BUILD_STEP_OR_BUILD_GLOBAL_CONTEXT_REFERENCE_REGEX,\n} from './utils/template.js';\n\nexport type BuildFunctions = Record<string, BuildFunctionConfig>;\n\ninterface BuildFunctionsConfigFile {\n configFilesToImport?: string[];\n functions?: BuildFunctions;\n}\n\nexport interface BuildConfig extends BuildFunctionsConfigFile {\n build: {\n name?: string;\n steps: BuildStepConfig[];\n };\n}\n\nexport type BuildStepConfig =\n | BuildStepCommandRun\n | BuildStepBareCommandRun\n | BuildStepFunctionCall\n | BuildStepBareFunctionCall;\n\nexport type BuildStepCommandRun = {\n run: BuildFunctionCallConfig & {\n outputs?: BuildStepOutputs;\n command: string;\n };\n};\nexport type BuildStepBareCommandRun = { run: string };\nexport type BuildStepFunctionCall = {\n [functionId: string]: BuildFunctionCallConfig;\n};\nexport type BuildStepBareFunctionCall = string;\n\nexport type BuildFunctionCallConfig = {\n id?: string;\n inputs?: BuildStepInputs;\n name?: string;\n workingDirectory?: string;\n shell?: string;\n env?: BuildStepEnv;\n if?: string;\n};\n\nexport type BuildStepInputs = Record<string, BuildStepInputValueTypeWithRequired>;\nexport type BuildStepOutputs = (\n | string\n | {\n name: string;\n required?: boolean;\n }\n)[];\n\nexport interface BuildFunctionConfig {\n inputs?: BuildFunctionInputs;\n outputs?: BuildFunctionOutputs;\n name?: string;\n supportedRuntimePlatforms?: BuildRuntimePlatform[];\n shell?: string;\n command?: string;\n path?: string;\n}\n\nexport type BuildFunctionInputs = (\n | string\n | {\n name: string;\n defaultValue?: BuildStepInputValueType;\n allowedValues?: BuildStepInputValueType[];\n required?: boolean;\n allowedValueType: BuildStepInputValueTypeName;\n }\n)[];\nexport type BuildFunctionOutputs = BuildStepOutputs;\n\nconst BuildFunctionInputsSchema = Joi.array().items(\n Joi.alternatives().conditional(Joi.ref('.'), {\n is: Joi.string(),\n then: Joi.string().required(),\n otherwise: Joi.object({\n name: Joi.string().required(),\n defaultValue: Joi.when('allowedValues', {\n is: Joi.exist(),\n then: Joi.valid(Joi.in('allowedValues')).messages({\n 'any.only': '{{#label}} must be one of allowed values',\n }),\n })\n .when('allowedValueType', {\n is: BuildStepInputValueTypeName.STRING,\n then: Joi.string().allow(''),\n })\n .when('allowedValueType', {\n is: BuildStepInputValueTypeName.BOOLEAN,\n then: Joi.alternatives(\n Joi.boolean(),\n Joi.string().pattern(\n BUILD_STEP_OR_BUILD_GLOBAL_CONTEXT_REFERENCE_REGEX,\n 'context or output reference regex pattern'\n )\n ).messages({\n 'alternatives.types':\n '{{#label}} must be a boolean or reference to output or context value',\n }),\n })\n .when('allowedValueType', {\n is: BuildStepInputValueTypeName.NUMBER,\n then: Joi.alternatives(\n Joi.number(),\n Joi.string().pattern(\n BUILD_STEP_OR_BUILD_GLOBAL_CONTEXT_REFERENCE_REGEX,\n 'context or output reference regex pattern'\n )\n ).messages({\n 'alternatives.types':\n '{{#label}} must be a number or reference to output or context value',\n }),\n })\n .when('allowedValueType', {\n is: BuildStepInputValueTypeName.JSON,\n then: Joi.alternatives(\n Joi.object(),\n Joi.string().pattern(\n BUILD_STEP_OR_BUILD_GLOBAL_CONTEXT_REFERENCE_REGEX,\n 'context or output reference regex pattern'\n )\n ).messages({\n 'alternatives.types':\n '{{#label}} must be a object or reference to output or context value',\n }),\n }),\n allowedValues: Joi.when('allowedValueType', {\n is: BuildStepInputValueTypeName.STRING,\n then: Joi.array().items(Joi.string().allow('')),\n })\n .when('allowedValueType', {\n is: BuildStepInputValueTypeName.BOOLEAN,\n then: Joi.array().items(Joi.boolean()),\n })\n .when('allowedValueType', {\n is: BuildStepInputValueTypeName.NUMBER,\n then: Joi.array().items(Joi.number()),\n })\n .when('allowedValueType', {\n is: BuildStepInputValueTypeName.JSON,\n then: Joi.array().items(Joi.object()),\n }),\n allowedValueType: Joi.string()\n .valid(...Object.values(BuildStepInputValueTypeName))\n .default(BuildStepInputValueTypeName.STRING),\n required: Joi.boolean(),\n })\n .rename('allowed_values', 'allowedValues')\n .rename('default_value', 'defaultValue')\n .rename('type', 'allowedValueType')\n .required(),\n })\n);\n\nconst BuildStepOutputsSchema = Joi.array().items(\n Joi.alternatives().try(\n Joi.string().required(),\n Joi.object({\n name: Joi.string().required(),\n required: Joi.boolean(),\n }).required()\n )\n);\n\nconst BuildFunctionCallSchema = Joi.object({\n id: Joi.string(),\n inputs: Joi.object().pattern(\n Joi.string(),\n Joi.alternatives().try(Joi.string().allow(''), Joi.boolean(), Joi.number(), Joi.object())\n ),\n name: Joi.string(),\n workingDirectory: Joi.string(),\n shell: Joi.string(),\n env: Joi.object().pattern(Joi.string(), Joi.string().allow('')),\n if: Joi.string().pattern(\n BUILD_STEP_IF_CONDITION_EXPRESSION_REGEXP,\n 'allowed \"if\" condition values regex'\n ),\n}).rename('working_directory', 'workingDirectory');\n\nconst BuildStepConfigSchema = Joi.any<BuildStepConfig>()\n .invalid(null)\n .when(\n Joi.object().pattern(\n Joi.string().disallow('run').required(),\n Joi.object().unknown().required()\n ),\n {\n then: Joi.object().pattern(\n Joi.string().disallow('run').min(1).required(),\n BuildFunctionCallSchema.required(),\n { matches: Joi.array().length(1) }\n ),\n }\n )\n .when(Joi.object({ run: Joi.object().unknown().required() }), {\n then: Joi.object({\n run: BuildFunctionCallSchema.keys({\n outputs: BuildStepOutputsSchema,\n command: Joi.string().required(),\n }),\n }),\n })\n .when(Joi.object({ run: Joi.string().required() }), {\n then: Joi.object({\n run: Joi.string().min(1).required(),\n }),\n })\n .when(Joi.string(), {\n then: Joi.string().min(1),\n });\n\nconst BuildFunctionConfigSchema = Joi.object({\n name: Joi.string(),\n supportedRuntimePlatforms: Joi.array().items(...Object.values(BuildRuntimePlatform)),\n inputs: BuildFunctionInputsSchema,\n outputs: BuildStepOutputsSchema,\n command: Joi.string(),\n path: Joi.string(),\n shell: Joi.string(),\n})\n .rename('supported_platforms', 'supportedRuntimePlatforms')\n .xor('command', 'path')\n .nand('command', 'path');\n\nexport const BuildFunctionsConfigFileSchema = Joi.object<BuildFunctionsConfigFile>({\n configFilesToImport: Joi.array().items(Joi.string().pattern(/\\.y(a)?ml$/)),\n functions: Joi.object().pattern(\n Joi.string()\n .pattern(/^[\\w-]+$/, 'function names')\n .min(1)\n .required()\n .disallow('run'),\n BuildFunctionConfigSchema.required()\n ),\n})\n .rename('import', 'configFilesToImport')\n .required();\n\nexport const BuildConfigSchema = BuildFunctionsConfigFileSchema.append<BuildConfig>({\n build: Joi.object({\n name: Joi.string(),\n steps: Joi.array().items(BuildStepConfigSchema.required()).required(),\n }).required(),\n}).required();\n\ninterface BuildConfigValidationParams {\n externalFunctionIds?: string[];\n skipNamespacedFunctionsCheck?: boolean;\n}\n\nexport async function readAndValidateBuildConfigAsync(\n configPath: string,\n params: BuildConfigValidationParams = {}\n): Promise<BuildConfig> {\n const rawConfig = await readRawBuildConfigAsync(configPath);\n\n const config = validateConfig(BuildConfigSchema, rawConfig);\n for (const functionName in config.functions) {\n const customFunctionPath = config.functions[functionName].path;\n if (customFunctionPath) {\n config.functions[functionName].path = maybeResolveCustomFunctionRelativePath(\n path.dirname(configPath),\n customFunctionPath\n );\n }\n }\n\n const importedFunctions = await importFunctionsAsync(configPath, config.configFilesToImport);\n mergeConfigWithImportedFunctions(config, importedFunctions);\n validateAllFunctionsExist(config, params);\n return config;\n}\n\nasync function importFunctionsAsync(\n baseConfigPath: string,\n configPathsToImport?: string[]\n): Promise<BuildFunctions> {\n if (!configPathsToImport) {\n return {};\n }\n\n const baseConfigDir = path.dirname(baseConfigPath);\n\n const errors: BuildConfigError[] = [];\n const importedFunctions: BuildFunctions = {};\n // this is a set of visited files identified by ABSOLUTE paths\n const visitedFiles = new Set<string>([baseConfigPath]);\n const configFilesToVisit = (configPathsToImport ?? []).map((childConfigRelativePath) =>\n path.resolve(baseConfigDir, childConfigRelativePath)\n );\n while (configFilesToVisit.length > 0) {\n const childConfigPath = configFilesToVisit.shift();\n assert(childConfigPath, 'Guaranteed by loop condition');\n if (visitedFiles.has(childConfigPath)) {\n continue;\n }\n visitedFiles.add(childConfigPath);\n try {\n const childConfig = await readAndValidateBuildFunctionsConfigFileAsync(childConfigPath);\n const childDir = path.dirname(childConfigPath);\n for (const functionName in childConfig.functions) {\n if (!(functionName in importedFunctions)) {\n const f = childConfig.functions[functionName];\n if (f.path) {\n f.path = maybeResolveCustomFunctionRelativePath(childDir, f.path);\n }\n importedFunctions[functionName] = f;\n }\n }\n if (childConfig.configFilesToImport) {\n configFilesToVisit.push(\n ...childConfig.configFilesToImport.map((relativePath) =>\n path.resolve(childDir, relativePath)\n )\n );\n }\n } catch (err) {\n if (err instanceof BuildConfigError) {\n errors.push(err);\n } else {\n throw err;\n }\n }\n }\n if (errors.length > 0) {\n throw new BuildWorkflowError(`Detected build config errors in imported files.`, errors);\n }\n return importedFunctions;\n}\n\nexport async function readAndValidateBuildFunctionsConfigFileAsync(\n configPath: string\n): Promise<BuildFunctionsConfigFile> {\n const rawConfig = await readRawBuildConfigAsync(configPath);\n return validateConfig(BuildFunctionsConfigFileSchema, rawConfig);\n}\n\nexport async function readRawBuildConfigAsync(configPath: string): Promise<any> {\n const contents = await fs.readFile(configPath, 'utf-8');\n return YAML.parse(contents);\n}\n\nexport function validateConfig<T>(\n schema: Joi.ObjectSchema<T>,\n config: object,\n configFilePath?: string\n): T {\n const { error, value } = schema.validate(config, {\n allowUnknown: false,\n abortEarly: false,\n });\n if (error) {\n const errorMessage = error.details.map(({ message }) => message).join(', ');\n throw new BuildConfigError(errorMessage, {\n cause: error,\n ...(configFilePath && { metadata: { configFilePath } }),\n });\n }\n return value;\n}\n\nexport function mergeConfigWithImportedFunctions(\n config: BuildConfig,\n importedFunctions: BuildFunctions\n): void {\n if (Object.keys(importedFunctions).length === 0) {\n return;\n }\n config.functions = config.functions ?? {};\n for (const functionName in importedFunctions) {\n if (!(functionName in config.functions)) {\n config.functions[functionName] = importedFunctions[functionName];\n }\n }\n}\n\nexport function isBuildStepCommandRun(step: BuildStepConfig): step is BuildStepCommandRun {\n return Boolean(step) && typeof step === 'object' && typeof step.run === 'object';\n}\n\nexport function isBuildStepBareCommandRun(step: BuildStepConfig): step is BuildStepBareCommandRun {\n return Boolean(step) && typeof step === 'object' && typeof step.run === 'string';\n}\n\nexport function isBuildStepFunctionCall(step: BuildStepConfig): step is BuildStepFunctionCall {\n return Boolean(step) && typeof step === 'object' && !('run' in step);\n}\n\nexport function isBuildStepBareFunctionCall(\n step: BuildStepConfig\n): step is BuildStepBareFunctionCall {\n return typeof step === 'string';\n}\n\nexport function validateAllFunctionsExist(\n config: BuildConfig,\n { externalFunctionIds = [], skipNamespacedFunctionsCheck }: BuildConfigValidationParams\n): void {\n const calledFunctionsSet = new Set<string>();\n for (const step of config.build.steps) {\n if (typeof step === 'string') {\n calledFunctionsSet.add(step);\n } else if (step !== null && !('run' in step)) {\n const keys = Object.keys(step);\n assert(\n keys.length === 1,\n 'There must be at most one function call in the step (enforced by joi).'\n );\n calledFunctionsSet.add(keys[0]);\n }\n }\n const calledFunctions = Array.from(calledFunctionsSet);\n const externalFunctionIdsSet = new Set(externalFunctionIds);\n const nonExistentFunctions = calledFunctions.filter((calledFunction) => {\n if (BuildFunction.isFulldIdNamespaced(calledFunction) && skipNamespacedFunctionsCheck) {\n return false;\n }\n return (\n !(calledFunction in (config.functions ?? {})) && !externalFunctionIdsSet.has(calledFunction)\n );\n });\n if (nonExistentFunctions.length > 0) {\n throw new BuildConfigError(\n `Calling non-existent functions: ${nonExistentFunctions.map((f) => `\"${f}\"`).join(', ')}.`\n );\n }\n}\n\nfunction maybeResolveCustomFunctionRelativePath(dir: string, customFunctionPath: string): string {\n if (!path.isAbsolute(customFunctionPath)) {\n return path.resolve(dir, customFunctionPath);\n }\n return customFunctionPath;\n}\n"]}
|
|
@@ -6,7 +6,7 @@ import { BuildStepInput, BuildStepInputValueTypeName, } from './BuildStepInput.j
|
|
|
6
6
|
import { BuildStepOutput } from './BuildStepOutput.js';
|
|
7
7
|
import { BuildWorkflow } from './BuildWorkflow.js';
|
|
8
8
|
import { BuildWorkflowValidator } from './BuildWorkflowValidator.js';
|
|
9
|
-
import {
|
|
9
|
+
import { BuildConfigError } from './errors.js';
|
|
10
10
|
import { duplicates } from './utils/expodash/duplicates.js';
|
|
11
11
|
import { uniq } from './utils/expodash/uniq.js';
|
|
12
12
|
export class BuildConfigParser {
|
|
@@ -37,12 +37,15 @@ export class BuildConfigParser {
|
|
|
37
37
|
else if (isBuildStepBareFunctionCall(buildStepConfig)) {
|
|
38
38
|
return this.createBuildStepFromBuildStepBareFunctionCall(buildFunctions, buildStepConfig);
|
|
39
39
|
}
|
|
40
|
-
else {
|
|
40
|
+
else if (buildStepConfig !== null) {
|
|
41
41
|
return this.createBuildStepFromBuildStepFunctionCall(buildFunctions, buildStepConfig);
|
|
42
42
|
}
|
|
43
|
+
else {
|
|
44
|
+
throw new BuildConfigError('Invalid build step configuration detected. Build step cannot be empty.');
|
|
45
|
+
}
|
|
43
46
|
}
|
|
44
47
|
createBuildStepFromBuildStepCommandRun({ run }) {
|
|
45
|
-
const { id: maybeId, inputs: inputsConfig, outputs: outputsConfig, name, workingDirectory, shell, command, env, } = run;
|
|
48
|
+
const { id: maybeId, inputs: inputsConfig, outputs: outputsConfig, name, workingDirectory, shell, command, env, if: ifCondition, } = run;
|
|
46
49
|
const id = BuildStep.getNewId(maybeId);
|
|
47
50
|
const displayName = BuildStep.getDisplayName({ id, name, command });
|
|
48
51
|
const inputs = inputsConfig && this.createBuildStepInputsFromDefinition(inputsConfig, displayName);
|
|
@@ -57,6 +60,7 @@ export class BuildConfigParser {
|
|
|
57
60
|
shell,
|
|
58
61
|
command,
|
|
59
62
|
env,
|
|
63
|
+
ifCondition,
|
|
60
64
|
});
|
|
61
65
|
}
|
|
62
66
|
createBuildStepFromBuildStepBareCommandRun({ run: command, }) {
|
|
@@ -85,6 +89,7 @@ export class BuildConfigParser {
|
|
|
85
89
|
workingDirectory: buildFunctionCallConfig.workingDirectory,
|
|
86
90
|
shell: buildFunctionCallConfig.shell,
|
|
87
91
|
env: buildFunctionCallConfig.env,
|
|
92
|
+
ifCondition: buildFunctionCallConfig.if,
|
|
88
93
|
});
|
|
89
94
|
}
|
|
90
95
|
createBuildFunctionsFromConfig(buildFunctionsConfig) {
|
|
@@ -187,7 +192,7 @@ export class BuildConfigParser {
|
|
|
187
192
|
if (duplicatedExternalFunctionIds.length === 0) {
|
|
188
193
|
return;
|
|
189
194
|
}
|
|
190
|
-
throw new
|
|
195
|
+
throw new BuildConfigError(`Provided external functions with duplicated IDs: ${duplicatedExternalFunctionIds
|
|
191
196
|
.map((id) => `"${id}"`)
|
|
192
197
|
.join(', ')}`);
|
|
193
198
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BuildConfigParser.js","sourceRoot":"","sources":["../src/BuildConfigParser.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,QAAQ,CAAC;AAE5B,OAAO,EAYL,yBAAyB,EACzB,2BAA2B,EAC3B,qBAAqB,EACrB,+BAA+B,GAChC,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,aAAa,EAAqB,MAAM,oBAAoB,CAAC;AACtE,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC3C,OAAO,EACL,cAAc,EAEd,2BAA2B,GAC5B,MAAM,qBAAqB,CAAC;AAE7B,OAAO,EAAE,eAAe,EAA2B,MAAM,sBAAsB,CAAC;AAChF,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAC;AACrE,OAAO,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AACpD,OAAO,EAAE,UAAU,EAAE,MAAM,gCAAgC,CAAC;AAC5D,OAAO,EAAE,IAAI,EAAE,MAAM,0BAA0B,CAAC;AAEhD,MAAM,OAAO,iBAAiB;IAI5B,YACmB,GAA2B,EAC5C,EAAE,UAAU,EAAE,iBAAiB,EAA+D;QAD7E,QAAG,GAAH,GAAG,CAAwB;QAG5C,IAAI,CAAC,yBAAyB,CAAC,iBAAiB,CAAC,CAAC;QAElD,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;QAC7B,IAAI,CAAC,iBAAiB,GAAG,iBAAiB,CAAC;IAC7C,CAAC;IAEM,KAAK,CAAC,UAAU;QACrB,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iB,EAAE;YAC7C,uDAAuD;YACvD,MAAM,MAAM,GAAG,aAAa,CAAC,SAAS,EAAE,CAAC;YACzC,IAAI,CAAC,CAAC,MAAM,IAAI,MAAM,CAAC,EAAE;gBACvB,MAAM,CAAC,MAAM,CAAC,GAAG,aAAa,CAAC;aAChC;SACF;QACD,OAAO,MAAM,CAAC;IAChB,CAAC;IAEO,yBAAyB,CAAC,iBAAmC;QACnE,IAAI,iBAAiB,KAAK,SAAS,EAAE;YACnC,OAAO;SACR;QACD,MAAM,mBAAmB,GAAG,iBAAiB,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,SAAS,EAAE,CAAC,CAAC;QACxE,MAAM,6BAA6B,GAAG,UAAU,CAAC,mBAAmB,CAAC,CAAC;QACtE,IAAI,6BAA6B,CAAC,MAAM,KAAK,CAAC,EAAE;YAC9C,OAAO;SACR;QACD,MAAM,IAAI,qBAAqB,CAC7B,oDAAoD,6BAA6B;aAC9E,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,IAAI,EAAE,GAAG,CAAC;aACtB,IAAI,CAAC,IAAI,CAAC,EAAE,CAChB,CAAC;IACJ,CAAC;IAEO,0BAA0B;QAChC,IAAI,IAAI,CAAC,iBAAiB,KAAK,SAAS,EAAE;YACxC,OAAO,EAAE,CAAC;SACX;QACD,MAAM,GAAG,GAAG,IAAI,CAAC,iBAAiB,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,SAAS,EAAE,CAAC,CAAC;QAC7D,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC;IACnB,CAAC;CACF","sourcesContent":["import assert from 'assert';\n\nimport {\n BuildConfig,\n BuildFunctionConfig,\n BuildFunctionInputs,\n BuildFunctionOutputs,\n BuildStepBareCommandRun,\n BuildStepBareFunctionCall,\n BuildStepCommandRun,\n BuildStepConfig,\n BuildStepFunctionCall,\n BuildStepInputs,\n BuildStepOutputs,\n isBuildStepBareCommandRun,\n isBuildStepBareFunctionCall,\n isBuildStepCommandRun,\n readAndValidateBuildConfigAsync,\n} from './BuildConfig.js';\nimport { BuildFunction, BuildFunctionById } from './BuildFunction.js';\nimport { BuildStep } from './BuildStep.js';\nimport {\n BuildStepInput,\n BuildStepInputProvider,\n BuildStepInputValueTypeName,\n} from './BuildStepInput.js';\nimport { BuildStepGlobalContext } from './BuildStepContext.js';\nimport { BuildStepOutput, BuildStepOutputProvider } from './BuildStepOutput.js';\nimport { BuildWorkflow } from './BuildWorkflow.js';\nimport { BuildWorkflowValidator } from './BuildWorkflowValidator.js';\nimport { BuildStepRuntimeError } from './errors.js';\nimport { duplicates } from './utils/expodash/duplicates.js';\nimport { uniq } from './utils/expodash/uniq.js';\n\nexport class BuildConfigParser {\n private readonly configPath: string;\n private readonly externalFunctions?: BuildFunction[];\n\n constructor(\n private readonly ctx: BuildStepGlobalContext,\n { configPath, externalFunctions }: { configPath: string; externalFunctions?: BuildFunction[] }\n ) {\n this.validateExternalFunctions(externalFunctions);\n\n this.configPath = configPath;\n this.externalFunctions = externalFunctions;\n }\n\n public async parseAsync(): Promise<BuildWorkflow> {\n const config = await readAndValidateBuildConfigAsync(this.configPath, {\n externalFunctionIds: this.getExternalFunctionFullIds(),\n });\n const configBuildFunctions = this.createBuildFunctionsFromConfig(config.functions);\n const buildFunctions = this.mergeBuildFunctionsWithExternal(\n configBuildFunctions,\n this.externalFunctions\n );\n const buildSteps = config.build.steps.map((stepConfig) =>\n this.createBuildStepFromConfig(stepConfig, buildFunctions)\n );\n const workflow = new BuildWorkflow(this.ctx, { buildSteps, buildFunctions });\n await new BuildWorkflowValidator(workflow).validateAsync();\n return workflow;\n }\n\n private createBuildStepFromConfig(\n buildStepConfig: BuildStepConfig,\n buildFunctions: BuildFunctionById\n ): BuildStep {\n if (isBuildStepCommandRun(buildStepConfig)) {\n return this.createBuildStepFromBuildStepCommandRun(buildStepConfig);\n } else if (isBuildStepBareCommandRun(buildStepConfig)) {\n return this.createBuildStepFromBuildStepBareCommandRun(buildStepConfig);\n } else if (isBuildStepBareFunctionCall(buildStepConfig)) {\n return this.createBuildStepFromBuildStepBareFunctionCall(buildFunctions, buildStepConfig);\n } else {\n return this.createBuildStepFromBuildStepFunctionCall(buildFunctions, buildStepConfig);\n }\n }\n\n private createBuildStepFromBuildStepCommandRun({ run }: BuildStepCommandRun): BuildStep {\n const {\n id: maybeId,\n inputs: inputsConfig,\n outputs: outputsConfig,\n name,\n workingDirectory,\n shell,\n command,\n env,\n } = run;\n const id = BuildStep.getNewId(maybeId);\n const displayName = BuildStep.getDisplayName({ id, name, command });\n const inputs =\n inputsConfig && this.createBuildStepInputsFromDefinition(inputsConfig, displayName);\n const outputs =\n outputsConfig && this.createBuildStepOutputsFromDefinition(outputsConfig, displayName);\n return new BuildStep(this.ctx, {\n id,\n inputs,\n outputs,\n name,\n displayName,\n workingDirectory,\n shell,\n command,\n env,\n });\n }\n\n private createBuildStepFromBuildStepBareCommandRun({\n run: command,\n }: BuildStepBareCommandRun): BuildStep {\n const id = BuildStep.getNewId();\n const displayName = BuildStep.getDisplayName({ id, command });\n return new BuildStep(this.ctx, {\n id,\n displayName,\n command,\n });\n }\n\n private createBuildStepFromBuildStepBareFunctionCall(\n buildFunctions: BuildFunctionById,\n functionId: BuildStepBareFunctionCall\n ): BuildStep {\n const buildFunction = buildFunctions[functionId];\n return buildFunction.createBuildStepFromFunctionCall(this.ctx);\n }\n\n private createBuildStepFromBuildStepFunctionCall(\n buildFunctions: BuildFunctionById,\n buildStepFunctionCall: BuildStepFunctionCall\n ): BuildStep {\n const keys = Object.keys(buildStepFunctionCall);\n assert(\n keys.length === 1,\n 'There must be at most one function call in the step (enforced by joi).'\n );\n const functionId = keys[0];\n const buildFunctionCallConfig = buildStepFunctionCall[functionId];\n const buildFunction = buildFunctions[functionId];\n return buildFunction.createBuildStepFromFunctionCall(this.ctx, {\n id: buildFunctionCallConfig.id,\n name: buildFunctionCallConfig.name,\n callInputs: buildFunctionCallConfig.inputs,\n workingDirectory: buildFunctionCallConfig.workingDirectory,\n shell: buildFunctionCallConfig.shell,\n env: buildFunctionCallConfig.env,\n });\n }\n\n private createBuildFunctionsFromConfig(\n buildFunctionsConfig: BuildConfig['functions']\n ): BuildFunctionById {\n if (!buildFunctionsConfig) {\n return {};\n }\n const result: BuildFunctionById = {};\n for (const [functionId, buildFunctionConfig] of Object.entries(buildFunctionsConfig)) {\n const buildFunction = this.createBuildFunctionFromConfig({\n id: functionId,\n ...buildFunctionConfig,\n });\n result[buildFunction.getFullId()] = buildFunction;\n }\n return result;\n }\n\n private createBuildFunctionFromConfig({\n id,\n name,\n inputs: inputsConfig,\n outputs: outputsConfig,\n shell,\n command,\n supportedRuntimePlatforms,\n path: customFunctionModulePath,\n }: BuildFunctionConfig & { id: string }): BuildFunction {\n const inputProviders =\n inputsConfig && this.createBuildStepInputProvidersFromBuildFunctionInputs(inputsConfig);\n const outputProviders =\n outputsConfig && this.createBuildStepOutputProvidersFromBuildFunctionOutputs(outputsConfig);\n return new BuildFunction({\n id,\n name,\n inputProviders,\n outputProviders,\n shell,\n command,\n customFunctionModulePath,\n supportedRuntimePlatforms,\n });\n }\n\n private createBuildStepInputsFromDefinition(\n buildStepInputs: BuildStepInputs,\n stepDisplayName: string\n ): BuildStepInput[] {\n return Object.entries(buildStepInputs).map(\n ([key, value]) =>\n new BuildStepInput(this.ctx, {\n id: key,\n stepDisplayName,\n defaultValue: value,\n required: true,\n allowedValueTypeName:\n typeof value === 'object'\n ? BuildStepInputValueTypeName.JSON\n : (typeof value as BuildStepInputValueTypeName),\n })\n );\n }\n\n private createBuildStepInputProvidersFromBuildFunctionInputs(\n buildFunctionInputs: BuildFunctionInputs\n ): BuildStepInputProvider[] {\n return buildFunctionInputs.map((entry) => {\n return typeof entry === 'string'\n ? BuildStepInput.createProvider({\n id: entry,\n required: true,\n allowedValueTypeName: BuildStepInputValueTypeName.STRING,\n })\n : BuildStepInput.createProvider({\n id: entry.name,\n required: entry.required ?? true,\n defaultValue: entry.defaultValue,\n allowedValues: entry.allowedValues,\n allowedValueTypeName: entry.allowedValueType,\n });\n });\n }\n\n private createBuildStepOutputsFromDefinition(\n buildStepOutputs: BuildStepOutputs,\n stepDisplayName: string\n ): BuildStepOutput[] {\n return buildStepOutputs.map((entry) =>\n typeof entry === 'string'\n ? new BuildStepOutput(this.ctx, { id: entry, stepDisplayName, required: true })\n : new BuildStepOutput(this.ctx, {\n id: entry.name,\n stepDisplayName,\n required: entry.required ?? true,\n })\n );\n }\n\n private createBuildStepOutputProvidersFromBuildFunctionOutputs(\n buildFunctionOutputs: BuildFunctionOutputs\n ): BuildStepOutputProvider[] {\n return buildFunctionOutputs.map((entry) =>\n typeof entry === 'string'\n ? BuildStepOutput.createProvider({ id: entry, required: true })\n : BuildStepOutput.createProvider({ id: entry.name, required: entry.required ?? true })\n );\n }\n\n private mergeBuildFunctionsWithExternal(\n configFunctions: BuildFunctionById,\n externalFunctions?: BuildFunction[]\n ): BuildFunctionById {\n const result: BuildFunctionById = { ...configFunctions };\n if (externalFunctions === undefined) {\n return result;\n }\n for (const buildFunction of externalFunctions) {\n // functions defined in config shadow the external ones\n const fullId = buildFunction.getFullId();\n if (!(fullId in result)) {\n result[fullId] = buildFunction;\n }\n }\n return result;\n }\n\n private validateExternalFunctions(externalFunctions?: BuildFunction[]): void {\n if (externalFunctions === undefined) {\n return;\n }\n const externalFunctionIds = externalFunctions.map((f) => f.getFullId());\n const duplicatedExternalFunctionIds = duplicates(externalFunctionIds);\n if (duplicatedExternalFunctionIds.length === 0) {\n return;\n }\n throw new BuildStepRuntimeError(\n `Provided external functions with duplicated IDs: ${duplicatedExternalFunctionIds\n .map((id) => `\"${id}\"`)\n .join(', ')}`\n );\n }\n\n private getExternalFunctionFullIds(): string[] {\n if (this.externalFunctions === undefined) {\n return [];\n }\n const ids = this.externalFunctions.map((f) => f.getFullId());\n return uniq(ids);\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"BuildConfigParser.js","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AAC,CAAC,MAAM,IAAI,MAAM,CAAC,EAAE;gBACvB,MAAM,CAAC,MAAM,CAAC,GAAG,aAAa,CAAC;aAChC;SACF;QACD,OAAO,MAAM,CAAC;IAChB,CAAC;IAEO,yBAAyB,CAAC,iBAAmC;QACnE,IAAI,iBAAiB,KAAK,SAAS,EAAE;YACnC,OAAO;SACR;QACD,MAAM,mBAAmB,GAAG,iBAAiB,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,SAAS,EAAE,CAAC,CAAC;QACxE,MAAM,6BAA6B,GAAG,UAAU,CAAC,mBAAmB,CAAC,CAAC;QACtE,IAAI,6BAA6B,CAAC,MAAM,KAAK,CAAC,EAAE;YAC9C,OAAO;SACR;QACD,MAAM,IAAI,gBAAgB,CACxB,oDAAoD,6BAA6B;aAC9E,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,IAAI,EAAE,GAAG,CAAC;aACtB,IAAI,CAAC,IAAI,CAAC,EAAE,CAChB,CAAC;IACJ,CAAC;IAEO,0BAA0B;QAChC,IAAI,IAAI,CAAC,iBAAiB,KAAK,SAAS,EAAE;YACxC,OAAO,EAAE,CAAC;SACX;QACD,MAAM,GAAG,GAAG,IAAI,CAAC,iBAAiB,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,SAAS,EAAE,CAAC,CAAC;QAC7D,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC;IACnB,CAAC;CACF","sourcesContent":["import assert from 'assert';\n\nimport {\n BuildConfig,\n BuildFunctionConfig,\n BuildFunctionInputs,\n BuildFunctionOutputs,\n BuildStepBareCommandRun,\n BuildStepBareFunctionCall,\n BuildStepCommandRun,\n BuildStepConfig,\n BuildStepFunctionCall,\n BuildStepInputs,\n BuildStepOutputs,\n isBuildStepBareCommandRun,\n isBuildStepBareFunctionCall,\n isBuildStepCommandRun,\n readAndValidateBuildConfigAsync,\n} from './BuildConfig.js';\nimport { BuildFunction, BuildFunctionById } from './BuildFunction.js';\nimport { BuildStep } from './BuildStep.js';\nimport {\n BuildStepInput,\n BuildStepInputProvider,\n BuildStepInputValueTypeName,\n} from './BuildStepInput.js';\nimport { BuildStepGlobalContext } from './BuildStepContext.js';\nimport { BuildStepOutput, BuildStepOutputProvider } from './BuildStepOutput.js';\nimport { BuildWorkflow } from './BuildWorkflow.js';\nimport { BuildWorkflowValidator } from './BuildWorkflowValidator.js';\nimport { BuildConfigError } from './errors.js';\nimport { duplicates } from './utils/expodash/duplicates.js';\nimport { uniq } from './utils/expodash/uniq.js';\n\nexport class BuildConfigParser {\n private readonly configPath: string;\n private readonly externalFunctions?: BuildFunction[];\n\n constructor(\n private readonly ctx: BuildStepGlobalContext,\n { configPath, externalFunctions }: { configPath: string; externalFunctions?: BuildFunction[] }\n ) {\n this.validateExternalFunctions(externalFunctions);\n\n this.configPath = configPath;\n this.externalFunctions = externalFunctions;\n }\n\n public async parseAsync(): Promise<BuildWorkflow> {\n const config = await readAndValidateBuildConfigAsync(this.configPath, {\n externalFunctionIds: this.getExternalFunctionFullIds(),\n });\n const configBuildFunctions = this.createBuildFunctionsFromConfig(config.functions);\n const buildFunctions = this.mergeBuildFunctionsWithExternal(\n configBuildFunctions,\n this.externalFunctions\n );\n const buildSteps = config.build.steps.map((stepConfig) =>\n this.createBuildStepFromConfig(stepConfig, buildFunctions)\n );\n const workflow = new BuildWorkflow(this.ctx, { buildSteps, buildFunctions });\n await new BuildWorkflowValidator(workflow).validateAsync();\n return workflow;\n }\n\n private createBuildStepFromConfig(\n buildStepConfig: BuildStepConfig,\n buildFunctions: BuildFunctionById\n ): BuildStep {\n if (isBuildStepCommandRun(buildStepConfig)) {\n return this.createBuildStepFromBuildStepCommandRun(buildStepConfig);\n } else if (isBuildStepBareCommandRun(buildStepConfig)) {\n return this.createBuildStepFromBuildStepBareCommandRun(buildStepConfig);\n } else if (isBuildStepBareFunctionCall(buildStepConfig)) {\n return this.createBuildStepFromBuildStepBareFunctionCall(buildFunctions, buildStepConfig);\n } else if (buildStepConfig !== null) {\n return this.createBuildStepFromBuildStepFunctionCall(buildFunctions, buildStepConfig);\n } else {\n throw new BuildConfigError(\n 'Invalid build step configuration detected. Build step cannot be empty.'\n );\n }\n }\n\n private createBuildStepFromBuildStepCommandRun({ run }: BuildStepCommandRun): BuildStep {\n const {\n id: maybeId,\n inputs: inputsConfig,\n outputs: outputsConfig,\n name,\n workingDirectory,\n shell,\n command,\n env,\n if: ifCondition,\n } = run;\n const id = BuildStep.getNewId(maybeId);\n const displayName = BuildStep.getDisplayName({ id, name, command });\n const inputs =\n inputsConfig && this.createBuildStepInputsFromDefinition(inputsConfig, displayName);\n const outputs =\n outputsConfig && this.createBuildStepOutputsFromDefinition(outputsConfig, displayName);\n return new BuildStep(this.ctx, {\n id,\n inputs,\n outputs,\n name,\n displayName,\n workingDirectory,\n shell,\n command,\n env,\n ifCondition,\n });\n }\n\n private createBuildStepFromBuildStepBareCommandRun({\n run: command,\n }: BuildStepBareCommandRun): BuildStep {\n const id = BuildStep.getNewId();\n const displayName = BuildStep.getDisplayName({ id, command });\n return new BuildStep(this.ctx, {\n id,\n displayName,\n command,\n });\n }\n\n private createBuildStepFromBuildStepBareFunctionCall(\n buildFunctions: BuildFunctionById,\n functionId: BuildStepBareFunctionCall\n ): BuildStep {\n const buildFunction = buildFunctions[functionId];\n return buildFunction.createBuildStepFromFunctionCall(this.ctx);\n }\n\n private createBuildStepFromBuildStepFunctionCall(\n buildFunctions: BuildFunctionById,\n buildStepFunctionCall: BuildStepFunctionCall\n ): BuildStep {\n const keys = Object.keys(buildStepFunctionCall);\n assert(\n keys.length === 1,\n 'There must be at most one function call in the step (enforced by joi).'\n );\n const functionId = keys[0];\n const buildFunctionCallConfig = buildStepFunctionCall[functionId];\n const buildFunction = buildFunctions[functionId];\n return buildFunction.createBuildStepFromFunctionCall(this.ctx, {\n id: buildFunctionCallConfig.id,\n name: buildFunctionCallConfig.name,\n callInputs: buildFunctionCallConfig.inputs,\n workingDirectory: buildFunctionCallConfig.workingDirectory,\n shell: buildFunctionCallConfig.shell,\n env: buildFunctionCallConfig.env,\n ifCondition: buildFunctionCallConfig.if,\n });\n }\n\n private createBuildFunctionsFromConfig(\n buildFunctionsConfig: BuildConfig['functions']\n ): BuildFunctionById {\n if (!buildFunctionsConfig) {\n return {};\n }\n const result: BuildFunctionById = {};\n for (const [functionId, buildFunctionConfig] of Object.entries(buildFunctionsConfig)) {\n const buildFunction = this.createBuildFunctionFromConfig({\n id: functionId,\n ...buildFunctionConfig,\n });\n result[buildFunction.getFullId()] = buildFunction;\n }\n return result;\n }\n\n private createBuildFunctionFromConfig({\n id,\n name,\n inputs: inputsConfig,\n outputs: outputsConfig,\n shell,\n command,\n supportedRuntimePlatforms,\n path: customFunctionModulePath,\n }: BuildFunctionConfig & { id: string }): BuildFunction {\n const inputProviders =\n inputsConfig && this.createBuildStepInputProvidersFromBuildFunctionInputs(inputsConfig);\n const outputProviders =\n outputsConfig && this.createBuildStepOutputProvidersFromBuildFunctionOutputs(outputsConfig);\n return new BuildFunction({\n id,\n name,\n inputProviders,\n outputProviders,\n shell,\n command,\n customFunctionModulePath,\n supportedRuntimePlatforms,\n });\n }\n\n private createBuildStepInputsFromDefinition(\n buildStepInputs: BuildStepInputs,\n stepDisplayName: string\n ): BuildStepInput[] {\n return Object.entries(buildStepInputs).map(\n ([key, value]) =>\n new BuildStepInput(this.ctx, {\n id: key,\n stepDisplayName,\n defaultValue: value,\n required: true,\n allowedValueTypeName:\n typeof value === 'object'\n ? BuildStepInputValueTypeName.JSON\n : (typeof value as BuildStepInputValueTypeName),\n })\n );\n }\n\n private createBuildStepInputProvidersFromBuildFunctionInputs(\n buildFunctionInputs: BuildFunctionInputs\n ): BuildStepInputProvider[] {\n return buildFunctionInputs.map((entry) => {\n return typeof entry === 'string'\n ? BuildStepInput.createProvider({\n id: entry,\n required: true,\n allowedValueTypeName: BuildStepInputValueTypeName.STRING,\n })\n : BuildStepInput.createProvider({\n id: entry.name,\n required: entry.required ?? true,\n defaultValue: entry.defaultValue,\n allowedValues: entry.allowedValues,\n allowedValueTypeName: entry.allowedValueType,\n });\n });\n }\n\n private createBuildStepOutputsFromDefinition(\n buildStepOutputs: BuildStepOutputs,\n stepDisplayName: string\n ): BuildStepOutput[] {\n return buildStepOutputs.map((entry) =>\n typeof entry === 'string'\n ? new BuildStepOutput(this.ctx, { id: entry, stepDisplayName, required: true })\n : new BuildStepOutput(this.ctx, {\n id: entry.name,\n stepDisplayName,\n required: entry.required ?? true,\n })\n );\n }\n\n private createBuildStepOutputProvidersFromBuildFunctionOutputs(\n buildFunctionOutputs: BuildFunctionOutputs\n ): BuildStepOutputProvider[] {\n return buildFunctionOutputs.map((entry) =>\n typeof entry === 'string'\n ? BuildStepOutput.createProvider({ id: entry, required: true })\n : BuildStepOutput.createProvider({ id: entry.name, required: entry.required ?? true })\n );\n }\n\n private mergeBuildFunctionsWithExternal(\n configFunctions: BuildFunctionById,\n externalFunctions?: BuildFunction[]\n ): BuildFunctionById {\n const result: BuildFunctionById = { ...configFunctions };\n if (externalFunctions === undefined) {\n return result;\n }\n for (const buildFunction of externalFunctions) {\n // functions defined in config shadow the external ones\n const fullId = buildFunction.getFullId();\n if (!(fullId in result)) {\n result[fullId] = buildFunction;\n }\n }\n return result;\n }\n\n private validateExternalFunctions(externalFunctions?: BuildFunction[]): void {\n if (externalFunctions === undefined) {\n return;\n }\n const externalFunctionIds = externalFunctions.map((f) => f.getFullId());\n const duplicatedExternalFunctionIds = duplicates(externalFunctionIds);\n if (duplicatedExternalFunctionIds.length === 0) {\n return;\n }\n throw new BuildConfigError(\n `Provided external functions with duplicated IDs: ${duplicatedExternalFunctionIds\n .map((id) => `\"${id}\"`)\n .join(', ')}`\n );\n }\n\n private getExternalFunctionFullIds(): string[] {\n if (this.externalFunctions === undefined) {\n return [];\n }\n const ids = this.externalFunctions.map((f) => f.getFullId());\n return uniq(ids);\n }\n}\n"]}
|
|
@@ -31,12 +31,13 @@ export declare class BuildFunction {
|
|
|
31
31
|
shell?: string;
|
|
32
32
|
});
|
|
33
33
|
getFullId(): string;
|
|
34
|
-
createBuildStepFromFunctionCall(ctx: BuildStepGlobalContext, { id, name, callInputs, workingDirectory, shell, env, }?: {
|
|
34
|
+
createBuildStepFromFunctionCall(ctx: BuildStepGlobalContext, { id, name, callInputs, workingDirectory, shell, env, ifCondition, }?: {
|
|
35
35
|
id?: string;
|
|
36
36
|
name?: string;
|
|
37
37
|
callInputs?: BuildFunctionCallInputs;
|
|
38
38
|
workingDirectory?: string;
|
|
39
39
|
shell?: string;
|
|
40
40
|
env?: BuildStepEnv;
|
|
41
|
+
ifCondition?: string;
|
|
41
42
|
}): BuildStep;
|
|
42
43
|
}
|
|
@@ -24,7 +24,7 @@ export class BuildFunction {
|
|
|
24
24
|
getFullId() {
|
|
25
25
|
return this.namespace === undefined ? this.id : `${this.namespace}/${this.id}`;
|
|
26
26
|
}
|
|
27
|
-
createBuildStepFromFunctionCall(ctx, { id, name, callInputs = {}, workingDirectory, shell, env, } = {}) {
|
|
27
|
+
createBuildStepFromFunctionCall(ctx, { id, name, callInputs = {}, workingDirectory, shell, env, ifCondition, } = {}) {
|
|
28
28
|
var _a, _b, _c;
|
|
29
29
|
const buildStepId = BuildStep.getNewId(id);
|
|
30
30
|
const buildStepName = name !== null && name !== void 0 ? name : this.name;
|
|
@@ -55,6 +55,7 @@ export class BuildFunction {
|
|
|
55
55
|
shell,
|
|
56
56
|
supportedRuntimePlatforms: this.supportedRuntimePlatforms,
|
|
57
57
|
env,
|
|
58
|
+
ifCondition,
|
|
58
59
|
});
|
|
59
60
|
}
|
|
60
61
|
}
|