@expo/steps 1.0.23 → 1.0.25
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/set-env +23 -0
- package/dist_commonjs/BuildConfig.cjs +21 -5
- package/dist_commonjs/BuildConfig.d.ts +2 -0
- package/dist_commonjs/BuildConfig.js.map +1 -1
- package/dist_commonjs/BuildConfigParser.cjs +6 -2
- package/dist_commonjs/BuildConfigParser.d.ts +2 -2
- package/dist_commonjs/BuildConfigParser.js.map +1 -1
- package/dist_commonjs/BuildFunction.cjs +2 -1
- package/dist_commonjs/BuildFunction.d.ts +4 -2
- package/dist_commonjs/BuildFunction.js.map +1 -1
- package/dist_commonjs/BuildStep.cjs +49 -22
- package/dist_commonjs/BuildStep.d.ts +7 -4
- package/dist_commonjs/BuildStep.js.map +1 -1
- package/dist_commonjs/BuildStepContext.cjs +50 -13
- package/dist_commonjs/BuildStepContext.d.ts +35 -10
- package/dist_commonjs/BuildStepContext.js.map +1 -1
- package/dist_commonjs/BuildStepInput.cjs +59 -5
- package/dist_commonjs/BuildStepInput.d.ts +11 -5
- package/dist_commonjs/BuildStepInput.js.map +1 -1
- package/dist_commonjs/BuildStepOutput.d.ts +3 -3
- package/dist_commonjs/BuildStepOutput.js.map +1 -1
- package/dist_commonjs/BuildTemporaryFiles.cjs +11 -2
- package/dist_commonjs/BuildTemporaryFiles.d.ts +5 -4
- package/dist_commonjs/BuildTemporaryFiles.js.map +1 -1
- package/dist_commonjs/BuildWorkflow.cjs +2 -2
- package/dist_commonjs/BuildWorkflow.d.ts +3 -4
- package/dist_commonjs/BuildWorkflow.js.map +1 -1
- package/dist_commonjs/BuildWorkflowValidator.cjs +10 -3
- package/dist_commonjs/BuildWorkflowValidator.js.map +1 -1
- package/dist_commonjs/cli/cli.cjs +22 -3
- package/dist_commonjs/cli/cli.d.ts +16 -1
- package/dist_commonjs/cli/cli.js.map +1 -1
- package/dist_commonjs/index.cjs +2 -2
- package/dist_commonjs/index.d.ts +2 -1
- package/dist_commonjs/index.js.map +1 -1
- package/dist_commonjs/utils/template.cjs +40 -8
- package/dist_commonjs/utils/template.d.ts +5 -1
- package/dist_commonjs/utils/template.js.map +1 -1
- package/dist_esm/BuildConfig.d.ts +2 -0
- package/dist_esm/BuildConfig.js +21 -5
- package/dist_esm/BuildConfig.js.map +1 -1
- package/dist_esm/BuildConfigParser.d.ts +2 -2
- package/dist_esm/BuildConfigParser.js +7 -3
- package/dist_esm/BuildConfigParser.js.map +1 -1
- package/dist_esm/BuildFunction.d.ts +4 -2
- package/dist_esm/BuildFunction.js +2 -1
- package/dist_esm/BuildFunction.js.map +1 -1
- package/dist_esm/BuildStep.d.ts +7 -4
- package/dist_esm/BuildStep.js +50 -23
- package/dist_esm/BuildStep.js.map +1 -1
- package/dist_esm/BuildStepContext.d.ts +35 -10
- package/dist_esm/BuildStepContext.js +49 -13
- package/dist_esm/BuildStepContext.js.map +1 -1
- package/dist_esm/BuildStepInput.d.ts +11 -5
- package/dist_esm/BuildStepInput.js +60 -6
- package/dist_esm/BuildStepInput.js.map +1 -1
- package/dist_esm/BuildStepOutput.d.ts +3 -3
- package/dist_esm/BuildStepOutput.js.map +1 -1
- package/dist_esm/BuildTemporaryFiles.d.ts +5 -4
- package/dist_esm/BuildTemporaryFiles.js +9 -1
- package/dist_esm/BuildTemporaryFiles.js.map +1 -1
- package/dist_esm/BuildWorkflow.d.ts +3 -4
- package/dist_esm/BuildWorkflow.js +2 -2
- package/dist_esm/BuildWorkflow.js.map +1 -1
- package/dist_esm/BuildWorkflowValidator.js +10 -3
- package/dist_esm/BuildWorkflowValidator.js.map +1 -1
- package/dist_esm/cli/cli.d.ts +16 -1
- package/dist_esm/cli/cli.js +21 -4
- package/dist_esm/cli/cli.js.map +1 -1
- package/dist_esm/index.d.ts +2 -1
- package/dist_esm/index.js +1 -1
- package/dist_esm/index.js.map +1 -1
- package/dist_esm/utils/template.d.ts +5 -1
- package/dist_esm/utils/template.js +35 -8
- package/dist_esm/utils/template.js.map +1 -1
- package/package.json +4 -2
package/bin/set-env
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
|
|
3
|
+
set -eo pipefail
|
|
4
|
+
|
|
5
|
+
NAME=$1
|
|
6
|
+
VALUE=$2
|
|
7
|
+
|
|
8
|
+
if [[ -z "$__EXPO_STEPS_ENVS_DIR" ]]; then
|
|
9
|
+
echo "Set __EXPO_STEPS_ENVS_DIR"
|
|
10
|
+
exit 1
|
|
11
|
+
fi
|
|
12
|
+
|
|
13
|
+
if [[ -z "$NAME" || -z "$VALUE" ]]; then
|
|
14
|
+
echo "Usage: set-env NAME VALUE"
|
|
15
|
+
exit 2
|
|
16
|
+
fi
|
|
17
|
+
|
|
18
|
+
if [[ "$NAME" == *"="* ]]; then
|
|
19
|
+
echo "Environment name can't include ="
|
|
20
|
+
exit 1
|
|
21
|
+
fi
|
|
22
|
+
|
|
23
|
+
echo -n $VALUE > $__EXPO_STEPS_ENVS_DIR/$NAME
|
|
@@ -13,6 +13,7 @@ const errors_js_1 = require("./errors.cjs");
|
|
|
13
13
|
const BuildRuntimePlatform_js_1 = require("./BuildRuntimePlatform.cjs");
|
|
14
14
|
const BuildFunction_js_1 = require("./BuildFunction.cjs");
|
|
15
15
|
const BuildStepInput_js_1 = require("./BuildStepInput.cjs");
|
|
16
|
+
const template_js_1 = require("./utils/template.cjs");
|
|
16
17
|
const BuildFunctionInputsSchema = joi_1.default.array().items(joi_1.default.alternatives().conditional(joi_1.default.ref('.'), {
|
|
17
18
|
is: joi_1.default.string(),
|
|
18
19
|
then: joi_1.default.string().required(),
|
|
@@ -26,19 +27,29 @@ const BuildFunctionInputsSchema = joi_1.default.array().items(joi_1.default.alte
|
|
|
26
27
|
})
|
|
27
28
|
.when('allowedValueType', {
|
|
28
29
|
is: BuildStepInput_js_1.BuildStepInputValueTypeName.STRING,
|
|
29
|
-
then: joi_1.default.string(),
|
|
30
|
+
then: joi_1.default.string().allow(''),
|
|
30
31
|
})
|
|
31
32
|
.when('allowedValueType', {
|
|
32
33
|
is: BuildStepInput_js_1.BuildStepInputValueTypeName.BOOLEAN,
|
|
33
|
-
then: joi_1.default.boolean(),
|
|
34
|
+
then: joi_1.default.alternatives(joi_1.default.boolean(), joi_1.default.string().pattern(template_js_1.BUILD_STEP_OR_BUILD_GLOBAL_CONTEXT_REFERENCE_REGEX, 'context or output reference regex pattern')).messages({
|
|
35
|
+
'alternatives.types': '{{#label}} must be a boolean or reference to output or context value',
|
|
36
|
+
}),
|
|
34
37
|
})
|
|
35
38
|
.when('allowedValueType', {
|
|
36
39
|
is: BuildStepInput_js_1.BuildStepInputValueTypeName.NUMBER,
|
|
37
|
-
then: joi_1.default.number(),
|
|
40
|
+
then: joi_1.default.alternatives(joi_1.default.number(), joi_1.default.string().pattern(template_js_1.BUILD_STEP_OR_BUILD_GLOBAL_CONTEXT_REFERENCE_REGEX, 'context or output reference regex pattern')).messages({
|
|
41
|
+
'alternatives.types': '{{#label}} must be a number or reference to output or context value',
|
|
42
|
+
}),
|
|
43
|
+
})
|
|
44
|
+
.when('allowedValueType', {
|
|
45
|
+
is: BuildStepInput_js_1.BuildStepInputValueTypeName.JSON,
|
|
46
|
+
then: joi_1.default.alternatives(joi_1.default.object(), joi_1.default.string().pattern(template_js_1.BUILD_STEP_OR_BUILD_GLOBAL_CONTEXT_REFERENCE_REGEX, 'context or output reference regex pattern')).messages({
|
|
47
|
+
'alternatives.types': '{{#label}} must be a object or reference to output or context value',
|
|
48
|
+
}),
|
|
38
49
|
}),
|
|
39
50
|
allowedValues: joi_1.default.when('allowedValueType', {
|
|
40
51
|
is: BuildStepInput_js_1.BuildStepInputValueTypeName.STRING,
|
|
41
|
-
then: joi_1.default.array().items(joi_1.default.string()),
|
|
52
|
+
then: joi_1.default.array().items(joi_1.default.string().allow('')),
|
|
42
53
|
})
|
|
43
54
|
.when('allowedValueType', {
|
|
44
55
|
is: BuildStepInput_js_1.BuildStepInputValueTypeName.BOOLEAN,
|
|
@@ -47,6 +58,10 @@ const BuildFunctionInputsSchema = joi_1.default.array().items(joi_1.default.alte
|
|
|
47
58
|
.when('allowedValueType', {
|
|
48
59
|
is: BuildStepInput_js_1.BuildStepInputValueTypeName.NUMBER,
|
|
49
60
|
then: joi_1.default.array().items(joi_1.default.number()),
|
|
61
|
+
})
|
|
62
|
+
.when('allowedValueType', {
|
|
63
|
+
is: BuildStepInput_js_1.BuildStepInputValueTypeName.JSON,
|
|
64
|
+
then: joi_1.default.array().items(joi_1.default.object()),
|
|
50
65
|
}),
|
|
51
66
|
allowedValueType: joi_1.default.string()
|
|
52
67
|
.valid(...Object.values(BuildStepInput_js_1.BuildStepInputValueTypeName))
|
|
@@ -64,10 +79,11 @@ const BuildStepOutputsSchema = joi_1.default.array().items(joi_1.default.alterna
|
|
|
64
79
|
}).required()));
|
|
65
80
|
const BuildFunctionCallSchema = joi_1.default.object({
|
|
66
81
|
id: joi_1.default.string(),
|
|
67
|
-
inputs: joi_1.default.object().pattern(joi_1.default.string(), joi_1.default.alternatives().try(joi_1.default.string(), joi_1.default.boolean(), joi_1.default.number())),
|
|
82
|
+
inputs: joi_1.default.object().pattern(joi_1.default.string(), joi_1.default.alternatives().try(joi_1.default.string().allow(''), joi_1.default.boolean(), joi_1.default.number(), joi_1.default.object())),
|
|
68
83
|
name: joi_1.default.string(),
|
|
69
84
|
workingDirectory: joi_1.default.string(),
|
|
70
85
|
shell: joi_1.default.string(),
|
|
86
|
+
env: joi_1.default.object().pattern(joi_1.default.string(), joi_1.default.string().allow('')),
|
|
71
87
|
}).rename('working_directory', 'workingDirectory');
|
|
72
88
|
const BuildStepConfigSchema = joi_1.default.any()
|
|
73
89
|
.when(joi_1.default.object().pattern(joi_1.default.string().disallow('run').required(), joi_1.default.object().unknown().required()), {
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import Joi from 'joi';
|
|
2
2
|
import { BuildRuntimePlatform } from './BuildRuntimePlatform.js';
|
|
3
3
|
import { BuildStepInputValueType, BuildStepInputValueTypeName } from './BuildStepInput.js';
|
|
4
|
+
import { BuildStepEnv } from './BuildStepEnv.js';
|
|
4
5
|
export type BuildFunctions = Record<string, BuildFunctionConfig>;
|
|
5
6
|
interface BuildFunctionsConfigFile {
|
|
6
7
|
configFilesToImport?: string[];
|
|
@@ -32,6 +33,7 @@ export type BuildFunctionCallConfig = {
|
|
|
32
33
|
name?: string;
|
|
33
34
|
workingDirectory?: string;
|
|
34
35
|
shell?: string;
|
|
36
|
+
env?: BuildStepEnv;
|
|
35
37
|
};
|
|
36
38
|
export type BuildStepInputs = Record<string, BuildStepInputValueType>;
|
|
37
39
|
export type BuildStepOutputs = (string | {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BuildConfig.js","sourceRoot":"","sources":["../src/BuildConfig.ts"],"names":[],"mappings":";;;;;;AAAA,oDAA4B;AAC5B,2DAA6B;AAC7B,gDAAwB;AAExB,8CAAsB;AACtB,gDAAwB;AAExB,2CAAmE;AACnE,uEAAiE;AACjE,yDAAmD;AACnD,2DAA2F;AAwE3F,MAAM,yBAAyB,GAAG,aAAG,CAAC,KAAK,EAAE,CAAC,KAAK,CACjD,aAAG,CAAC,YAAY,EAAE,CAAC,WAAW,CAAC,aAAG,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE;IAC3C,EAAE,EAAE,aAAG,CAAC,MAAM,EAAE;IAChB,IAAI,EAAE,aAAG,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAC7B,SAAS,EAAE,aAAG,CAAC,MAAM,CAAC;QACpB,IAAI,EAAE,aAAG,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;QAC7B,YAAY,EAAE,aAAG,CAAC,IAAI,CAAC,eAAe,EAAE;YACtC,EAAE,EAAE,aAAG,CAAC,KAAK,EAAE;YACf,IAAI,EAAE,aAAG,CAAC,KAAK,CAAC,aAAG,CAAC,EAAE,CAAC,eAAe,CAAC,CAAC,CAAC,QAA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,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,4BAAgB,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;AAhCD,8DAgCC","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 { BuildStepInputValueType, BuildStepInputValueTypeName } from './BuildStepInput.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};\n\nexport type BuildStepInputs = Record<string, BuildStepInputValueType>;\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}\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(),\n })\n .when('allowedValueType', {\n is: BuildStepInputValueTypeName.BOOLEAN,\n then: Joi.boolean(),\n })\n .when('allowedValueType', {\n is: BuildStepInputValueTypeName.NUMBER,\n then: Joi.number(),\n }),\n allowedValues: Joi.when('allowedValueType', {\n is: BuildStepInputValueTypeName.STRING,\n then: Joi.array().items(Joi.string()),\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 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(), Joi.boolean(), Joi.number())\n ),\n name: Joi.string(),\n workingDirectory: Joi.string(),\n shell: Joi.string(),\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().required(),\n shell: Joi.string(),\n}).rename('supported_platforms', 'supportedRuntimePlatforms');\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 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 for (const functionName in childConfig.functions) {\n if (!(functionName in importedFunctions)) {\n importedFunctions[functionName] = childConfig.functions[functionName];\n }\n }\n if (childConfig.configFilesToImport) {\n const childDir = path.dirname(childConfigPath);\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"]}
|
|
1
|
+
{"version":3,"file":"BuildConfig.js","sourceRoot":"","sources":["../src/BuildConfig.ts"],"names":[],"mappings":";;;;;;AAAA,oDAA4B;AAC5B,2DAA6B;AAC7B,gDAAwB;AAExB,8CAAsB;AACtB,gDAAwB;AAExB,2CAAmE;AACnE,uEAAiE;AACjE,yDAAmD;AACnD,2DAA2F;AAE3F,qDAAyF;AAyEzF,MAAM,yBAAyB,GAAG,aAAG,CAAC,KAAK,EAAE,CAAC,KAAK,CACjD,aAAG,CAAC,YAAY,EAAE,CAAC,WAAW,CAAC,aAAG,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE;IAC3C,EAAE,EAAE,aAAG,CAAC,MAAM,EAAE;IAChB,IAAI,EAAE,aAAG,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAC7B,SAAS,EAAE,aAAG,CAAC,MAAM,CAAC;QACpB,IAAI,EAAE,aAAG,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;QAC7B,YAAY,EAAE,aAAG,CAAC,IAAI,CAAC,eAAe,EAAE;YACtC,EAAE,EAAE,aAAG,CAAC,KAAK,EAAE;YACf,IAAI,EAAE,aAAG,CAAC,KAAK,CAAC,aAAG,CAAC,EAAE,CAAC,eAAe,CAAC,CAAC,CAAC,QAAQ,CAAC;gB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IAAI,oBAAoB,CAAC,MAAM,GAAG,CAAC,EAAE;QACnC,MAAM,IAAI,4BAAgB,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;AAhCD,8DAgCC","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 { BuildStepInputValueType, BuildStepInputValueTypeName } 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, BuildStepInputValueType>;\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}\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().required(),\n shell: Joi.string(),\n}).rename('supported_platforms', 'supportedRuntimePlatforms');\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 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 for (const functionName in childConfig.functions) {\n if (!(functionName in importedFunctions)) {\n importedFunctions[functionName] = childConfig.functions[functionName];\n }\n }\n if (childConfig.configFilesToImport) {\n const childDir = path.dirname(childConfigPath);\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"]}
|
|
@@ -48,7 +48,7 @@ class BuildConfigParser {
|
|
|
48
48
|
}
|
|
49
49
|
}
|
|
50
50
|
createBuildStepFromBuildStepCommandRun({ run }) {
|
|
51
|
-
const { id: maybeId, inputs: inputsConfig, outputs: outputsConfig, name, workingDirectory, shell, command, } = run;
|
|
51
|
+
const { id: maybeId, inputs: inputsConfig, outputs: outputsConfig, name, workingDirectory, shell, command, env, } = run;
|
|
52
52
|
const id = BuildStep_js_1.BuildStep.getNewId(maybeId);
|
|
53
53
|
const displayName = BuildStep_js_1.BuildStep.getDisplayName({ id, name, command });
|
|
54
54
|
const inputs = inputsConfig && this.createBuildStepInputsFromDefinition(inputsConfig, displayName);
|
|
@@ -62,6 +62,7 @@ class BuildConfigParser {
|
|
|
62
62
|
workingDirectory,
|
|
63
63
|
shell,
|
|
64
64
|
command,
|
|
65
|
+
env,
|
|
65
66
|
});
|
|
66
67
|
}
|
|
67
68
|
createBuildStepFromBuildStepBareCommandRun({ run: command, }) {
|
|
@@ -89,6 +90,7 @@ class BuildConfigParser {
|
|
|
89
90
|
callInputs: buildFunctionCallConfig.inputs,
|
|
90
91
|
workingDirectory: buildFunctionCallConfig.workingDirectory,
|
|
91
92
|
shell: buildFunctionCallConfig.shell,
|
|
93
|
+
env: buildFunctionCallConfig.env,
|
|
92
94
|
});
|
|
93
95
|
}
|
|
94
96
|
createBuildFunctionsFromConfig(buildFunctionsConfig) {
|
|
@@ -124,7 +126,9 @@ class BuildConfigParser {
|
|
|
124
126
|
stepDisplayName,
|
|
125
127
|
defaultValue: value,
|
|
126
128
|
required: true,
|
|
127
|
-
allowedValueTypeName: typeof value
|
|
129
|
+
allowedValueTypeName: typeof value === 'object'
|
|
130
|
+
? BuildStepInput_js_1.BuildStepInputValueTypeName.JSON
|
|
131
|
+
: typeof value,
|
|
128
132
|
}));
|
|
129
133
|
}
|
|
130
134
|
createBuildStepInputProvidersFromBuildFunctionInputs(buildFunctionInputs) {
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { BuildFunction } from './BuildFunction.js';
|
|
2
|
-
import {
|
|
2
|
+
import { BuildStepGlobalContext } from './BuildStepContext.js';
|
|
3
3
|
import { BuildWorkflow } from './BuildWorkflow.js';
|
|
4
4
|
export declare class BuildConfigParser {
|
|
5
5
|
private readonly ctx;
|
|
6
6
|
private readonly configPath;
|
|
7
7
|
private readonly externalFunctions?;
|
|
8
|
-
constructor(ctx:
|
|
8
|
+
constructor(ctx: BuildStepGlobalContext, { configPath, externalFunctions }: {
|
|
9
9
|
configPath: string;
|
|
10
10
|
externalFunctions?: BuildFunction[];
|
|
11
11
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BuildConfigParser.js","sourceRoot":"","sources":["../src/BuildConfigParser.ts"],"names":[],"mappings":";;;;;;AAAA,oDAA4B;AAE5B,qDAgB0B;AAC1B,yDAAsE;AACtE,iDAA2C;AAE3C,2DAI6B;AAC7B,6DAAgF;AAChF,yDAAmD;AACnD,2EAAqE;AACrE,2CAAoD;AACpD,kEAA4D;AAC5D,sDAAgD;AAEhD,MAAa,iBAAiB;IAI5B,YACmB,GAAqB,EACtC,EAAE,UAAU,EAAE,iBAAiB,EAA+D;QAD7E,QAAG,GAAH,GAAG,CAAkB;QAGtC,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,MAAM,MAAM,GAAG,MAAM,IAAA,gDAA+B,EAAC,IAAI,CAAC,UAAU,EAAE;YACpE,mBAAmB,EAAE,IAAI,CAAC,0BAA0B,EAAE;SACvD,CAAC,CAAC;QACH,MAAM,oBAAoB,GAAG,IAAI,CAAC,8BAA8B,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;QACnF,MAAM,cAAc,GAAG,IAAI,CAAC,+BAA+B,CACzD,oBAAoB,EACpB,IAAI,CAAC,iBAAiB,CACvB,CAAC;QACF,MAAM,UAAU,GAAG,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,UAAU,EAAE,EAAE,CACvD,IAAI,CAAC,yBAAyB,CAAC,UAAU,EAAE,cAAc,CAAC,CAC3D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AAC;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,IAAA,cAAI,EAAC,GAAG,CAAC,CAAC;IACnB,CAAC;CACF;AA9PD,8CA8PC","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 { BuildStepContext } from './BuildStepContext.js';\nimport {\n BuildStepInput,\n BuildStepInputProvider,\n BuildStepInputValueTypeName,\n} from './BuildStepInput.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: BuildStepContext,\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 new BuildWorkflowValidator(workflow).validate();\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 } = 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 });\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 });\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 }: 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 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: 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({ id: entry })\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","sourceRoot":"","sources":["../src/BuildConfigParser.ts"],"names":[],"mappings":";;;;;;AAAA,oDAA4B;AAE5B,qDAgB0B;AAC1B,yDAAsE;AACtE,iDAA2C;AAC3C,2DAI6B;AAE7B,6DAAgF;AAChF,yDAAmD;AACnD,2EAAqE;AACrE,2CAAoD;AACpD,kEAA4D;AAC5D,sDAAgD;AAEhD,MAAa,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,MAAM,MAAM,GAAG,MAAM,IAAA,gDAA+B,EAAC,IAAI,CAAC,UAAU,EAAE;YACpE,mBAAmB,EAAE,IAAI,CAAC,0BAA0B,EAAE;SACvD,CAAC,CAAC;QACH,MAAM,oBAAoB,GAAG,IAAI,CAAC,8BAA8B,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;QACnF,MAAM,cAAc,GAAG,IAAI,CAAC,+BAA+B,CACzD,oBAAoB,EACpB,IAAI,CAAC,iBAAiB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AAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,SAAS,EAAE,CAAC,CAAC;QACxE,MAAM,6BAA6B,GAAG,IAAA,0BAAU,EAAC,mBAAmB,CAAC,CAAC;QACtE,IAAI,6BAA6B,CAAC,MAAM,KAAK,CAAC,EAAE;YAC9C,OAAO;SACR;QACD,MAAM,IAAI,iCAAqB,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,IAAA,cAAI,EAAC,GAAG,CAAC,CAAC;IACnB,CAAC;CACF;AApQD,8CAoQC","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 new BuildWorkflowValidator(workflow).validate();\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 }: 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 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({ id: entry })\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"]}
|
|
@@ -26,7 +26,7 @@ class BuildFunction {
|
|
|
26
26
|
getFullId() {
|
|
27
27
|
return this.namespace === undefined ? this.id : `${this.namespace}/${this.id}`;
|
|
28
28
|
}
|
|
29
|
-
createBuildStepFromFunctionCall(ctx, { id, name, callInputs = {}, workingDirectory, shell, } = {}) {
|
|
29
|
+
createBuildStepFromFunctionCall(ctx, { id, name, callInputs = {}, workingDirectory, shell, env, } = {}) {
|
|
30
30
|
var _a, _b;
|
|
31
31
|
const buildStepId = BuildStep_js_1.BuildStep.getNewId(id);
|
|
32
32
|
const buildStepName = name !== null && name !== void 0 ? name : this.name;
|
|
@@ -54,6 +54,7 @@ class BuildFunction {
|
|
|
54
54
|
outputs,
|
|
55
55
|
shell,
|
|
56
56
|
supportedRuntimePlatforms: this.supportedRuntimePlatforms,
|
|
57
|
+
env,
|
|
57
58
|
});
|
|
58
59
|
}
|
|
59
60
|
}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { BuildRuntimePlatform } from './BuildRuntimePlatform.js';
|
|
2
2
|
import { BuildStep, BuildStepFunction } from './BuildStep.js';
|
|
3
|
-
import {
|
|
3
|
+
import { BuildStepGlobalContext } from './BuildStepContext.js';
|
|
4
4
|
import { BuildStepInputProvider, BuildStepInputValueType } from './BuildStepInput.js';
|
|
5
5
|
import { BuildStepOutputProvider } from './BuildStepOutput.js';
|
|
6
|
+
import { BuildStepEnv } from './BuildStepEnv.js';
|
|
6
7
|
export type BuildFunctionById = Record<string, BuildFunction>;
|
|
7
8
|
export type BuildFunctionCallInputs = Record<string, BuildStepInputValueType>;
|
|
8
9
|
export declare class BuildFunction {
|
|
@@ -28,11 +29,12 @@ export declare class BuildFunction {
|
|
|
28
29
|
shell?: string;
|
|
29
30
|
});
|
|
30
31
|
getFullId(): string;
|
|
31
|
-
createBuildStepFromFunctionCall(ctx:
|
|
32
|
+
createBuildStepFromFunctionCall(ctx: BuildStepGlobalContext, { id, name, callInputs, workingDirectory, shell, env, }?: {
|
|
32
33
|
id?: string;
|
|
33
34
|
name?: string;
|
|
34
35
|
callInputs?: BuildFunctionCallInputs;
|
|
35
36
|
workingDirectory?: string;
|
|
36
37
|
shell?: string;
|
|
38
|
+
env?: BuildStepEnv;
|
|
37
39
|
}): BuildStep;
|
|
38
40
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BuildFunction.js","sourceRoot":"","sources":["../src/BuildFunction.ts"],"names":[],"mappings":";;;;;;AAAA,oDAA4B;AAG5B,iDAA8D;
|
|
1
|
+
{"version":3,"file":"BuildFunction.js","sourceRoot":"","sources":["../src/BuildFunction.ts"],"names":[],"mappings":";;;;;;AAAA,oDAA4B;AAG5B,iDAA8D;AAS9D,MAAa,aAAa;IAWj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AI,aAAJ,IAAI,cAAJ,IAAI,GAAI,IAAI,CAAC,IAAI,CAAC;QACxC,MAAM,oBAAoB,GAAG,wBAAS,CAAC,cAAc,CAAC;YACpD,EAAE,EAAE,WAAW;YACf,OAAO,EAAE,IAAI,CAAC,OAAO;YACrB,IAAI,EAAE,aAAa;SACpB,CAAC,CAAC;QAEH,MAAM,MAAM,GAAG,MAAA,IAAI,CAAC,cAAc,0CAAE,GAAG,CAAC,CAAC,aAAa,EAAE,EAAE;YACxD,MAAM,KAAK,GAAG,aAAa,CAAC,GAAG,EAAE,WAAW,CAAC,CAAC;YAC9C,IAAI,KAAK,CAAC,EAAE,IAAI,UAAU,EAAE;gBAC1B,KAAK,CAAC,GAAG,CAAC,UAAU,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,CAAC;aACjC;YACD,OAAO,KAAK,CAAC;QACf,CAAC,CAAC,CAAC;QACH,MAAM,OAAO,GAAG,MAAA,IAAI,CAAC,eAAe,0CAAE,GAAG,CAAC,CAAC,cAAc,EAAE,EAAE,CAAC,cAAc,CAAC,GAAG,EAAE,WAAW,CAAC,CAAC,CAAC;QAEhG,OAAO,IAAI,wBAAS,CAAC,GAAG,EAAE;YACxB,EAAE,EAAE,WAAW;YACf,IAAI,EAAE,aAAa;YACnB,WAAW,EAAE,oBAAoB;YACjC,OAAO,EAAE,IAAI,CAAC,OAAO;YACrB,EAAE,EAAE,IAAI,CAAC,EAAE;YACX,gBAAgB;YAChB,MAAM;YACN,OAAO;YACP,KAAK;YACL,yBAAyB,EAAE,IAAI,CAAC,yBAAyB;YACzD,GAAG;SACJ,CAAC,CAAC;IACL,CAAC;CACF;AAvGD,sCAuGC","sourcesContent":["import assert from 'assert';\n\nimport { BuildRuntimePlatform } from './BuildRuntimePlatform.js';\nimport { BuildStep, BuildStepFunction } from './BuildStep.js';\nimport { BuildStepGlobalContext } from './BuildStepContext.js';\nimport { BuildStepInputProvider, BuildStepInputValueType } from './BuildStepInput.js';\nimport { BuildStepOutputProvider } from './BuildStepOutput.js';\nimport { BuildStepEnv } from './BuildStepEnv.js';\n\nexport type BuildFunctionById = Record<string, BuildFunction>;\nexport type BuildFunctionCallInputs = Record<string, BuildStepInputValueType>;\n\nexport class BuildFunction {\n public readonly namespace?: string;\n public readonly id: string;\n public readonly name?: string;\n public readonly supportedRuntimePlatforms?: BuildRuntimePlatform[];\n public readonly inputProviders?: BuildStepInputProvider[];\n public readonly outputProviders?: BuildStepOutputProvider[];\n public readonly command?: string;\n public readonly fn?: BuildStepFunction;\n public readonly shell?: string;\n\n public static isFulldIdNamespaced(fullId: string): boolean {\n return fullId.includes('/');\n }\n\n constructor({\n namespace,\n id,\n name,\n supportedRuntimePlatforms,\n inputProviders,\n outputProviders,\n command,\n fn,\n shell,\n }: {\n namespace?: string;\n id: string;\n name?: string;\n supportedRuntimePlatforms?: BuildRuntimePlatform[];\n inputProviders?: BuildStepInputProvider[];\n outputProviders?: BuildStepOutputProvider[];\n command?: string;\n fn?: BuildStepFunction;\n shell?: string;\n }) {\n assert(command !== undefined || fn !== undefined, 'Either command or fn must be defined.');\n assert(!(command !== undefined && fn !== undefined), 'Command and fn cannot be both set.');\n\n this.namespace = namespace;\n this.id = id;\n this.name = name;\n this.supportedRuntimePlatforms = supportedRuntimePlatforms;\n this.inputProviders = inputProviders;\n this.outputProviders = outputProviders;\n this.command = command;\n this.fn = fn;\n this.shell = shell;\n }\n\n public getFullId(): string {\n return this.namespace === undefined ? this.id : `${this.namespace}/${this.id}`;\n }\n\n public createBuildStepFromFunctionCall(\n ctx: BuildStepGlobalContext,\n {\n id,\n name,\n callInputs = {},\n workingDirectory,\n shell,\n env,\n }: {\n id?: string;\n name?: string;\n callInputs?: BuildFunctionCallInputs;\n workingDirectory?: string;\n shell?: string;\n env?: BuildStepEnv;\n } = {}\n ): BuildStep {\n const buildStepId = BuildStep.getNewId(id);\n const buildStepName = name ?? this.name;\n const buildStepDisplayName = BuildStep.getDisplayName({\n id: buildStepId,\n command: this.command,\n name: buildStepName,\n });\n\n const inputs = this.inputProviders?.map((inputProvider) => {\n const input = inputProvider(ctx, buildStepId);\n if (input.id in callInputs) {\n input.set(callInputs[input.id]);\n }\n return input;\n });\n const outputs = this.outputProviders?.map((outputProvider) => outputProvider(ctx, buildStepId));\n\n return new BuildStep(ctx, {\n id: buildStepId,\n name: buildStepName,\n displayName: buildStepDisplayName,\n command: this.command,\n fn: this.fn,\n workingDirectory,\n inputs,\n outputs,\n shell,\n supportedRuntimePlatforms: this.supportedRuntimePlatforms,\n env,\n });\n }\n}\n"]}
|
|
@@ -54,7 +54,7 @@ class BuildStep {
|
|
|
54
54
|
}
|
|
55
55
|
return id;
|
|
56
56
|
}
|
|
57
|
-
constructor(ctx, { id, name, displayName, inputs, outputs, command, fn, workingDirectory: maybeWorkingDirectory, shell, supportedRuntimePlatforms: maybeSupportedRuntimePlatforms, }) {
|
|
57
|
+
constructor(ctx, { id, name, displayName, inputs, outputs, command, fn, workingDirectory: maybeWorkingDirectory, shell, supportedRuntimePlatforms: maybeSupportedRuntimePlatforms, env, }) {
|
|
58
58
|
this.executed = false;
|
|
59
59
|
(0, assert_1.default)(command !== undefined || fn !== undefined, 'Either command or fn must be defined.');
|
|
60
60
|
(0, assert_1.default)(!(command !== undefined && fn !== undefined), 'Command and fn cannot be both set.');
|
|
@@ -71,26 +71,27 @@ class BuildStep {
|
|
|
71
71
|
this.shell = shell !== null && shell !== void 0 ? shell : (0, command_js_1.getDefaultShell)();
|
|
72
72
|
this.status = BuildStepStatus.NEW;
|
|
73
73
|
this.internalId = (0, uuid_1.v4)();
|
|
74
|
-
const logger = ctx.
|
|
74
|
+
const logger = ctx.baseLogger.child({
|
|
75
75
|
buildStepInternalId: this.internalId,
|
|
76
76
|
buildStepId: this.id,
|
|
77
77
|
buildStepDisplayName: this.displayName,
|
|
78
78
|
});
|
|
79
79
|
const workingDirectory = maybeWorkingDirectory !== undefined
|
|
80
|
-
? path_1.default.resolve(ctx.
|
|
81
|
-
: ctx.
|
|
82
|
-
this.ctx = ctx.
|
|
80
|
+
? path_1.default.resolve(ctx.defaultWorkingDirectory, maybeWorkingDirectory)
|
|
81
|
+
: ctx.defaultWorkingDirectory;
|
|
82
|
+
this.ctx = ctx.stepCtx({ logger, workingDirectory });
|
|
83
|
+
this.env = env !== null && env !== void 0 ? env : {};
|
|
83
84
|
ctx.registerStep(this);
|
|
84
85
|
}
|
|
85
|
-
async executeAsync(
|
|
86
|
+
async executeAsync() {
|
|
86
87
|
try {
|
|
87
88
|
this.ctx.logger.info({ marker: BuildStepLogMarker.START_STEP }, `Executing build step "${this.displayName}"`);
|
|
88
89
|
this.status = BuildStepStatus.IN_PROGRESS;
|
|
89
90
|
if (this.command !== undefined) {
|
|
90
|
-
await this.executeCommandAsync(
|
|
91
|
+
await this.executeCommandAsync();
|
|
91
92
|
}
|
|
92
93
|
else {
|
|
93
|
-
await this.exectuteFnAsync(
|
|
94
|
+
await this.exectuteFnAsync();
|
|
94
95
|
}
|
|
95
96
|
this.ctx.logger.info({ marker: BuildStepLogMarker.END_STEP, result: BuildStepStatus.SUCCESS }, `Finished build step "${this.displayName}" successfully`);
|
|
96
97
|
this.status = BuildStepStatus.SUCCESS;
|
|
@@ -119,46 +120,60 @@ class BuildStep {
|
|
|
119
120
|
}
|
|
120
121
|
canBeRunOnRuntimePlatform() {
|
|
121
122
|
return (!this.supportedRuntimePlatforms ||
|
|
122
|
-
this.supportedRuntimePlatforms.includes(this.ctx.runtimePlatform));
|
|
123
|
+
this.supportedRuntimePlatforms.includes(this.ctx.global.runtimePlatform));
|
|
123
124
|
}
|
|
124
|
-
async executeCommandAsync(
|
|
125
|
+
async executeCommandAsync() {
|
|
125
126
|
(0, assert_1.default)(this.command, 'Command must be defined.');
|
|
126
127
|
try {
|
|
127
|
-
const command = this.
|
|
128
|
+
const command = this.interpolateInputsAndGlobalContextInCommand(this.command, this.inputs);
|
|
128
129
|
this.ctx.logger.debug(`Interpolated inputs in the command template`);
|
|
129
|
-
const outputsDir = await (0, BuildTemporaryFiles_js_1.createTemporaryOutputsDirectoryAsync)(this.ctx, this.id);
|
|
130
|
+
const outputsDir = await (0, BuildTemporaryFiles_js_1.createTemporaryOutputsDirectoryAsync)(this.ctx.global, this.id);
|
|
130
131
|
this.ctx.logger.debug(`Created temporary directory for step outputs: ${outputsDir}`);
|
|
131
|
-
const
|
|
132
|
+
const envsDir = await (0, BuildTemporaryFiles_js_1.createTemporaryEnvsDirectoryAsync)(this.ctx.global, this.id);
|
|
133
|
+
this.ctx.logger.debug(`Created temporary directory for step environment variables: ${outputsDir}`);
|
|
134
|
+
const scriptPath = await (0, BuildTemporaryFiles_js_1.saveScriptToTemporaryFileAsync)(this.ctx.global, this.id, command);
|
|
132
135
|
this.ctx.logger.debug(`Saved script to ${scriptPath}`);
|
|
133
136
|
const { command: shellCommand, args } = (0, command_js_1.getShellCommandAndArgs)(this.shell, scriptPath);
|
|
134
137
|
this.ctx.logger.debug(`Executing script: ${shellCommand}${args !== undefined ? ` ${args.join(' ')}` : ''}`);
|
|
135
138
|
await (0, spawn_js_1.spawnAsync)(shellCommand, args !== null && args !== void 0 ? args : [], {
|
|
136
139
|
cwd: this.ctx.workingDirectory,
|
|
137
140
|
logger: this.ctx.logger,
|
|
138
|
-
env: this.getScriptEnv(
|
|
141
|
+
env: this.getScriptEnv({ outputsDir, envsDir }),
|
|
139
142
|
});
|
|
140
143
|
this.ctx.logger.debug(`Script completed successfully`);
|
|
141
144
|
await this.collectAndValidateOutputsAsync(outputsDir);
|
|
145
|
+
await this.collectAndUpdateEnvsAsync(envsDir);
|
|
142
146
|
this.ctx.logger.debug('Finished collecting output paramters');
|
|
143
147
|
}
|
|
144
148
|
finally {
|
|
145
|
-
await (0, BuildTemporaryFiles_js_1.cleanUpStepTemporaryDirectoriesAsync)(this.ctx, this.id);
|
|
149
|
+
await (0, BuildTemporaryFiles_js_1.cleanUpStepTemporaryDirectoriesAsync)(this.ctx.global, this.id);
|
|
146
150
|
}
|
|
147
151
|
}
|
|
148
|
-
async exectuteFnAsync(
|
|
152
|
+
async exectuteFnAsync() {
|
|
149
153
|
(0, assert_1.default)(this.fn, 'Function (fn) must be defined');
|
|
150
|
-
await this.fn(this.ctx, {
|
|
154
|
+
await this.fn(this.ctx, {
|
|
155
|
+
inputs: this.inputById,
|
|
156
|
+
outputs: this.outputById,
|
|
157
|
+
env: {
|
|
158
|
+
...this.ctx.global.env,
|
|
159
|
+
...this.env,
|
|
160
|
+
},
|
|
161
|
+
});
|
|
151
162
|
}
|
|
152
|
-
|
|
163
|
+
interpolateInputsAndGlobalContextInCommand(command, inputs) {
|
|
153
164
|
if (!inputs) {
|
|
154
165
|
return command;
|
|
155
166
|
}
|
|
156
167
|
const vars = inputs.reduce((acc, input) => {
|
|
157
168
|
var _a, _b;
|
|
158
|
-
acc[input.id] =
|
|
169
|
+
acc[input.id] =
|
|
170
|
+
typeof input.value === 'object'
|
|
171
|
+
? JSON.stringify(input.value)
|
|
172
|
+
: (_b = (_a = input.value) === null || _a === void 0 ? void 0 : _a.toString()) !== null && _b !== void 0 ? _b : '';
|
|
159
173
|
return acc;
|
|
160
174
|
}, {});
|
|
161
|
-
|
|
175
|
+
const valueInterpolatedWithGlobalContext = this.ctx.global.interpolate(command);
|
|
176
|
+
return (0, template_js_1.interpolateWithInputs)(valueInterpolatedWithGlobalContext, vars);
|
|
162
177
|
}
|
|
163
178
|
async collectAndValidateOutputsAsync(outputsDir) {
|
|
164
179
|
var _a;
|
|
@@ -197,14 +212,26 @@ class BuildStep {
|
|
|
197
212
|
});
|
|
198
213
|
}
|
|
199
214
|
}
|
|
200
|
-
|
|
215
|
+
async collectAndUpdateEnvsAsync(envsDir) {
|
|
216
|
+
const filenames = await promises_1.default.readdir(envsDir);
|
|
217
|
+
const entries = await Promise.all(filenames.map(async (basename) => {
|
|
218
|
+
const rawContents = await promises_1.default.readFile(path_1.default.join(envsDir, basename), 'utf-8');
|
|
219
|
+
return [basename, rawContents];
|
|
220
|
+
}));
|
|
221
|
+
this.ctx.global.updateEnv({
|
|
222
|
+
...this.ctx.global.env,
|
|
223
|
+
...Object.fromEntries(entries),
|
|
224
|
+
});
|
|
225
|
+
}
|
|
226
|
+
getScriptEnv({ envsDir, outputsDir, }) {
|
|
201
227
|
var _a;
|
|
228
|
+
const env = { ...this.ctx.global.env, ...this.env };
|
|
202
229
|
const currentPath = (_a = env.PATH) !== null && _a !== void 0 ? _a : process.env.PATH;
|
|
203
230
|
const newPath = currentPath ? `${bin_js_1.BIN_PATH}:${currentPath}` : bin_js_1.BIN_PATH;
|
|
204
231
|
return {
|
|
205
232
|
...env,
|
|
206
|
-
__EXPO_STEPS_BUILD_ID: this.ctx.buildId,
|
|
207
233
|
__EXPO_STEPS_OUTPUTS_DIR: outputsDir,
|
|
234
|
+
__EXPO_STEPS_ENVS_DIR: envsDir,
|
|
208
235
|
__EXPO_STEPS_WORKING_DIRECTORY: this.ctx.workingDirectory,
|
|
209
236
|
PATH: newPath,
|
|
210
237
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { BuildStepContext } from './BuildStepContext.js';
|
|
1
|
+
import { BuildStepContext, BuildStepGlobalContext } from './BuildStepContext.js';
|
|
2
2
|
import { BuildStepInput, BuildStepInputById } from './BuildStepInput.js';
|
|
3
3
|
import { BuildStepOutput, BuildStepOutputById } from './BuildStepOutput.js';
|
|
4
4
|
import { BuildStepEnv } from './BuildStepEnv.js';
|
|
@@ -31,6 +31,7 @@ export declare class BuildStep {
|
|
|
31
31
|
readonly fn?: BuildStepFunction;
|
|
32
32
|
readonly shell: string;
|
|
33
33
|
readonly ctx: BuildStepContext;
|
|
34
|
+
readonly env: BuildStepEnv;
|
|
34
35
|
status: BuildStepStatus;
|
|
35
36
|
private readonly internalId;
|
|
36
37
|
private readonly inputById;
|
|
@@ -42,7 +43,7 @@ export declare class BuildStep {
|
|
|
42
43
|
name?: string;
|
|
43
44
|
command?: string;
|
|
44
45
|
}): string;
|
|
45
|
-
constructor(ctx:
|
|
46
|
+
constructor(ctx: BuildStepGlobalContext, { id, name, displayName, inputs, outputs, command, fn, workingDirectory: maybeWorkingDirectory, shell, supportedRuntimePlatforms: maybeSupportedRuntimePlatforms, env, }: {
|
|
46
47
|
id: string;
|
|
47
48
|
name?: string;
|
|
48
49
|
displayName: string;
|
|
@@ -53,14 +54,16 @@ export declare class BuildStep {
|
|
|
53
54
|
workingDirectory?: string;
|
|
54
55
|
shell?: string;
|
|
55
56
|
supportedRuntimePlatforms?: BuildRuntimePlatform[];
|
|
57
|
+
env?: BuildStepEnv;
|
|
56
58
|
});
|
|
57
|
-
executeAsync(
|
|
59
|
+
executeAsync(): Promise<void>;
|
|
58
60
|
hasOutputParameter(name: string): boolean;
|
|
59
61
|
getOutputValueByName(name: string): string | undefined;
|
|
60
62
|
canBeRunOnRuntimePlatform(): boolean;
|
|
61
63
|
private executeCommandAsync;
|
|
62
64
|
private exectuteFnAsync;
|
|
63
|
-
private
|
|
65
|
+
private interpolateInputsAndGlobalContextInCommand;
|
|
64
66
|
private collectAndValidateOutputsAsync;
|
|
67
|
+
private collectAndUpdateEnvsAsync;
|
|
65
68
|
private getScriptEnv;
|
|
66
69
|
}
|