@expo/steps 1.0.23 → 1.0.28
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 +27 -7
- package/dist_commonjs/BuildConfig.d.ts +6 -3
- package/dist_commonjs/BuildConfig.js.map +1 -1
- package/dist_commonjs/BuildConfigParser.cjs +45 -8
- package/dist_commonjs/BuildConfigParser.d.ts +3 -4
- package/dist_commonjs/BuildConfigParser.js.map +1 -1
- package/dist_commonjs/BuildFunction.cjs +12 -5
- package/dist_commonjs/BuildFunction.d.ts +9 -5
- package/dist_commonjs/BuildFunction.js.map +1 -1
- package/dist_commonjs/BuildStep.cjs +101 -26
- package/dist_commonjs/BuildStep.d.ts +28 -8
- package/dist_commonjs/BuildStep.js.map +1 -1
- package/dist_commonjs/BuildStepContext.cjs +99 -13
- package/dist_commonjs/BuildStepContext.d.ts +61 -11
- package/dist_commonjs/BuildStepContext.js.map +1 -1
- package/dist_commonjs/BuildStepInput.cjs +86 -6
- package/dist_commonjs/BuildStepInput.d.ts +39 -19
- package/dist_commonjs/BuildStepInput.js.map +1 -1
- package/dist_commonjs/BuildStepOutput.cjs +21 -1
- package/dist_commonjs/BuildStepOutput.d.ts +20 -10
- 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 +35 -4
- package/dist_commonjs/BuildWorkflowValidator.d.ts +2 -1
- package/dist_commonjs/BuildWorkflowValidator.js.map +1 -1
- package/dist_commonjs/cli/cli.cjs +23 -4
- package/dist_commonjs/cli/cli.d.ts +16 -1
- package/dist_commonjs/cli/cli.js.map +1 -1
- package/dist_commonjs/index.cjs +5 -3
- package/dist_commonjs/index.d.ts +3 -1
- package/dist_commonjs/index.js.map +1 -1
- package/dist_commonjs/scripts/runCustomFunction.cjs +106 -0
- package/dist_commonjs/scripts/runCustomFunction.d.ts +1 -0
- package/dist_commonjs/scripts/runCustomFunction.js.map +1 -0
- package/dist_commonjs/utils/customFunction.cjs +89 -0
- package/dist_commonjs/utils/customFunction.d.ts +18 -0
- package/dist_commonjs/utils/customFunction.js.map +1 -0
- 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 +6 -3
- package/dist_esm/BuildConfig.js +28 -8
- package/dist_esm/BuildConfig.js.map +1 -1
- package/dist_esm/BuildConfigParser.d.ts +3 -4
- package/dist_esm/BuildConfigParser.js +46 -9
- package/dist_esm/BuildConfigParser.js.map +1 -1
- package/dist_esm/BuildFunction.d.ts +9 -5
- package/dist_esm/BuildFunction.js +12 -5
- package/dist_esm/BuildFunction.js.map +1 -1
- package/dist_esm/BuildStep.d.ts +28 -8
- package/dist_esm/BuildStep.js +101 -27
- package/dist_esm/BuildStep.js.map +1 -1
- package/dist_esm/BuildStepContext.d.ts +61 -11
- package/dist_esm/BuildStepContext.js +98 -13
- package/dist_esm/BuildStepContext.js.map +1 -1
- package/dist_esm/BuildStepInput.d.ts +39 -19
- package/dist_esm/BuildStepInput.js +87 -7
- package/dist_esm/BuildStepInput.js.map +1 -1
- package/dist_esm/BuildStepOutput.d.ts +20 -10
- package/dist_esm/BuildStepOutput.js +21 -1
- 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.d.ts +2 -1
- package/dist_esm/BuildWorkflowValidator.js +32 -4
- package/dist_esm/BuildWorkflowValidator.js.map +1 -1
- package/dist_esm/cli/cli.d.ts +16 -1
- package/dist_esm/cli/cli.js +22 -5
- package/dist_esm/cli/cli.js.map +1 -1
- package/dist_esm/index.d.ts +3 -1
- package/dist_esm/index.js +2 -1
- package/dist_esm/index.js.map +1 -1
- package/dist_esm/scripts/runCustomFunction.d.ts +1 -0
- package/dist_esm/scripts/runCustomFunction.js +101 -0
- package/dist_esm/scripts/runCustomFunction.js.map +1 -0
- package/dist_esm/utils/customFunction.d.ts +18 -0
- package/dist_esm/utils/customFunction.js +81 -0
- package/dist_esm/utils/customFunction.js.map +1 -0
- 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 +8 -2
|
@@ -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.BuildStep = exports.BuildStepLogMarker = exports.BuildStepStatus = void 0;
|
|
6
|
+
exports.BuildStep = exports.BuildStepOutputAccessor = exports.BuildStepLogMarker = exports.BuildStepStatus = void 0;
|
|
7
7
|
const assert_1 = __importDefault(require("assert"));
|
|
8
8
|
const promises_1 = __importDefault(require("fs/promises"));
|
|
9
9
|
const path_1 = __importDefault(require("path"));
|
|
@@ -32,7 +32,43 @@ var BuildStepLogMarker;
|
|
|
32
32
|
})(BuildStepLogMarker = exports.BuildStepLogMarker || (exports.BuildStepLogMarker = {}));
|
|
33
33
|
// TODO: move to a place common with tests
|
|
34
34
|
const UUID_REGEX = /^[0-9a-fA-F]{8}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{12}$/;
|
|
35
|
-
class
|
|
35
|
+
class BuildStepOutputAccessor {
|
|
36
|
+
constructor(id, displayName, executed, outputById) {
|
|
37
|
+
this.id = id;
|
|
38
|
+
this.displayName = displayName;
|
|
39
|
+
this.executed = executed;
|
|
40
|
+
this.outputById = outputById;
|
|
41
|
+
}
|
|
42
|
+
getOutputValueByName(name) {
|
|
43
|
+
if (!this.executed) {
|
|
44
|
+
throw new errors_js_1.BuildStepRuntimeError(`Failed getting output "${name}" from step "${this.displayName}". The step has not been executed yet.`);
|
|
45
|
+
}
|
|
46
|
+
if (!this.hasOutputParameter(name)) {
|
|
47
|
+
throw new errors_js_1.BuildStepRuntimeError(`Step "${this.displayName}" does not have output "${name}".`);
|
|
48
|
+
}
|
|
49
|
+
return this.outputById[name].value;
|
|
50
|
+
}
|
|
51
|
+
hasOutputParameter(name) {
|
|
52
|
+
return name in this.outputById;
|
|
53
|
+
}
|
|
54
|
+
serialize() {
|
|
55
|
+
return {
|
|
56
|
+
id: this.id,
|
|
57
|
+
executed: this.executed,
|
|
58
|
+
outputById: Object.fromEntries(Object.entries(this.outputById).map(([key, value]) => [key, value.serialize()])),
|
|
59
|
+
displayName: this.displayName,
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
static deserialize(serialized) {
|
|
63
|
+
const outputById = Object.fromEntries(Object.entries(serialized.outputById).map(([key, value]) => [
|
|
64
|
+
key,
|
|
65
|
+
BuildStepOutput_js_1.BuildStepOutput.deserialize(value),
|
|
66
|
+
]));
|
|
67
|
+
return new BuildStepOutputAccessor(serialized.id, serialized.displayName, serialized.executed, outputById);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
exports.BuildStepOutputAccessor = BuildStepOutputAccessor;
|
|
71
|
+
class BuildStep extends BuildStepOutputAccessor {
|
|
36
72
|
static getNewId(userDefinedId) {
|
|
37
73
|
return userDefinedId !== null && userDefinedId !== void 0 ? userDefinedId : (0, uuid_1.v4)();
|
|
38
74
|
}
|
|
@@ -54,10 +90,12 @@ class BuildStep {
|
|
|
54
90
|
}
|
|
55
91
|
return id;
|
|
56
92
|
}
|
|
57
|
-
constructor(ctx, { id, name, displayName, inputs, outputs, command, fn, workingDirectory: maybeWorkingDirectory, shell, supportedRuntimePlatforms: maybeSupportedRuntimePlatforms, }) {
|
|
58
|
-
this.executed = false;
|
|
93
|
+
constructor(ctx, { id, name, displayName, inputs, outputs, command, fn, workingDirectory: maybeWorkingDirectory, shell, supportedRuntimePlatforms: maybeSupportedRuntimePlatforms, env, }) {
|
|
59
94
|
(0, assert_1.default)(command !== undefined || fn !== undefined, 'Either command or fn must be defined.');
|
|
60
95
|
(0, assert_1.default)(!(command !== undefined && fn !== undefined), 'Command and fn cannot be both set.');
|
|
96
|
+
const outputById = (0, BuildStepOutput_js_1.makeBuildStepOutputByIdMap)(outputs);
|
|
97
|
+
super(id, displayName, false, outputById);
|
|
98
|
+
this.executed = false;
|
|
61
99
|
this.id = id;
|
|
62
100
|
this.name = name;
|
|
63
101
|
this.displayName = displayName;
|
|
@@ -65,32 +103,33 @@ class BuildStep {
|
|
|
65
103
|
this.inputs = inputs;
|
|
66
104
|
this.outputs = outputs;
|
|
67
105
|
this.inputById = (0, BuildStepInput_js_1.makeBuildStepInputByIdMap)(inputs);
|
|
68
|
-
this.outputById =
|
|
106
|
+
this.outputById = outputById;
|
|
69
107
|
this.fn = fn;
|
|
70
108
|
this.command = command;
|
|
71
109
|
this.shell = shell !== null && shell !== void 0 ? shell : (0, command_js_1.getDefaultShell)();
|
|
72
110
|
this.status = BuildStepStatus.NEW;
|
|
73
111
|
this.internalId = (0, uuid_1.v4)();
|
|
74
|
-
const logger = ctx.
|
|
112
|
+
const logger = ctx.baseLogger.child({
|
|
75
113
|
buildStepInternalId: this.internalId,
|
|
76
114
|
buildStepId: this.id,
|
|
77
115
|
buildStepDisplayName: this.displayName,
|
|
78
116
|
});
|
|
79
117
|
const workingDirectory = maybeWorkingDirectory !== undefined
|
|
80
|
-
? path_1.default.resolve(ctx.
|
|
81
|
-
: ctx.
|
|
82
|
-
this.ctx = ctx.
|
|
118
|
+
? path_1.default.resolve(ctx.defaultWorkingDirectory, maybeWorkingDirectory)
|
|
119
|
+
: ctx.defaultWorkingDirectory;
|
|
120
|
+
this.ctx = ctx.stepCtx({ logger, workingDirectory });
|
|
121
|
+
this.env = env !== null && env !== void 0 ? env : {};
|
|
83
122
|
ctx.registerStep(this);
|
|
84
123
|
}
|
|
85
|
-
async executeAsync(
|
|
124
|
+
async executeAsync() {
|
|
86
125
|
try {
|
|
87
126
|
this.ctx.logger.info({ marker: BuildStepLogMarker.START_STEP }, `Executing build step "${this.displayName}"`);
|
|
88
127
|
this.status = BuildStepStatus.IN_PROGRESS;
|
|
89
128
|
if (this.command !== undefined) {
|
|
90
|
-
await this.executeCommandAsync(
|
|
129
|
+
await this.executeCommandAsync();
|
|
91
130
|
}
|
|
92
131
|
else {
|
|
93
|
-
await this.exectuteFnAsync(
|
|
132
|
+
await this.exectuteFnAsync();
|
|
94
133
|
}
|
|
95
134
|
this.ctx.logger.info({ marker: BuildStepLogMarker.END_STEP, result: BuildStepStatus.SUCCESS }, `Finished build step "${this.displayName}" successfully`);
|
|
96
135
|
this.status = BuildStepStatus.SUCCESS;
|
|
@@ -119,46 +158,70 @@ class BuildStep {
|
|
|
119
158
|
}
|
|
120
159
|
canBeRunOnRuntimePlatform() {
|
|
121
160
|
return (!this.supportedRuntimePlatforms ||
|
|
122
|
-
this.supportedRuntimePlatforms.includes(this.ctx.runtimePlatform));
|
|
161
|
+
this.supportedRuntimePlatforms.includes(this.ctx.global.runtimePlatform));
|
|
123
162
|
}
|
|
124
|
-
async executeCommandAsync(
|
|
163
|
+
async executeCommandAsync() {
|
|
125
164
|
(0, assert_1.default)(this.command, 'Command must be defined.');
|
|
126
165
|
try {
|
|
127
|
-
const command = this.
|
|
166
|
+
const command = this.interpolateInputsAndGlobalContextInCommand(this.command, this.inputs);
|
|
128
167
|
this.ctx.logger.debug(`Interpolated inputs in the command template`);
|
|
129
|
-
const outputsDir = await (0, BuildTemporaryFiles_js_1.createTemporaryOutputsDirectoryAsync)(this.ctx, this.id);
|
|
168
|
+
const outputsDir = await (0, BuildTemporaryFiles_js_1.createTemporaryOutputsDirectoryAsync)(this.ctx.global, this.id);
|
|
130
169
|
this.ctx.logger.debug(`Created temporary directory for step outputs: ${outputsDir}`);
|
|
131
|
-
const
|
|
170
|
+
const envsDir = await (0, BuildTemporaryFiles_js_1.createTemporaryEnvsDirectoryAsync)(this.ctx.global, this.id);
|
|
171
|
+
this.ctx.logger.debug(`Created temporary directory for step environment variables: ${outputsDir}`);
|
|
172
|
+
const scriptPath = await (0, BuildTemporaryFiles_js_1.saveScriptToTemporaryFileAsync)(this.ctx.global, this.id, command);
|
|
132
173
|
this.ctx.logger.debug(`Saved script to ${scriptPath}`);
|
|
133
174
|
const { command: shellCommand, args } = (0, command_js_1.getShellCommandAndArgs)(this.shell, scriptPath);
|
|
134
175
|
this.ctx.logger.debug(`Executing script: ${shellCommand}${args !== undefined ? ` ${args.join(' ')}` : ''}`);
|
|
135
176
|
await (0, spawn_js_1.spawnAsync)(shellCommand, args !== null && args !== void 0 ? args : [], {
|
|
136
177
|
cwd: this.ctx.workingDirectory,
|
|
137
178
|
logger: this.ctx.logger,
|
|
138
|
-
env: this.getScriptEnv(
|
|
179
|
+
env: this.getScriptEnv({ outputsDir, envsDir }),
|
|
139
180
|
});
|
|
140
181
|
this.ctx.logger.debug(`Script completed successfully`);
|
|
141
182
|
await this.collectAndValidateOutputsAsync(outputsDir);
|
|
183
|
+
await this.collectAndUpdateEnvsAsync(envsDir);
|
|
142
184
|
this.ctx.logger.debug('Finished collecting output paramters');
|
|
143
185
|
}
|
|
144
186
|
finally {
|
|
145
|
-
await (0, BuildTemporaryFiles_js_1.cleanUpStepTemporaryDirectoriesAsync)(this.ctx, this.id);
|
|
187
|
+
await (0, BuildTemporaryFiles_js_1.cleanUpStepTemporaryDirectoriesAsync)(this.ctx.global, this.id);
|
|
146
188
|
}
|
|
147
189
|
}
|
|
148
|
-
async exectuteFnAsync(
|
|
190
|
+
async exectuteFnAsync() {
|
|
149
191
|
(0, assert_1.default)(this.fn, 'Function (fn) must be defined');
|
|
150
|
-
|
|
192
|
+
try {
|
|
193
|
+
const outputsDir = await (0, BuildTemporaryFiles_js_1.createTemporaryOutputsDirectoryAsync)(this.ctx.global, this.id);
|
|
194
|
+
this.ctx.logger.debug(`Created temporary directory for step outputs: ${outputsDir}`);
|
|
195
|
+
const envsDir = await (0, BuildTemporaryFiles_js_1.createTemporaryEnvsDirectoryAsync)(this.ctx.global, this.id);
|
|
196
|
+
this.ctx.logger.debug(`Created temporary directory for step environment variables: ${outputsDir}`);
|
|
197
|
+
await this.fn(this.ctx, {
|
|
198
|
+
inputs: this.inputById,
|
|
199
|
+
outputs: this.outputById,
|
|
200
|
+
env: this.getScriptEnv({ outputsDir, envsDir }),
|
|
201
|
+
});
|
|
202
|
+
this.ctx.logger.debug(`Script completed successfully`);
|
|
203
|
+
await this.collectAndValidateOutputsAsync(outputsDir);
|
|
204
|
+
await this.collectAndUpdateEnvsAsync(envsDir);
|
|
205
|
+
this.ctx.logger.debug('Finished collecting output paramters');
|
|
206
|
+
}
|
|
207
|
+
finally {
|
|
208
|
+
await (0, BuildTemporaryFiles_js_1.cleanUpStepTemporaryDirectoriesAsync)(this.ctx.global, this.id);
|
|
209
|
+
}
|
|
151
210
|
}
|
|
152
|
-
|
|
211
|
+
interpolateInputsAndGlobalContextInCommand(command, inputs) {
|
|
153
212
|
if (!inputs) {
|
|
154
213
|
return command;
|
|
155
214
|
}
|
|
156
215
|
const vars = inputs.reduce((acc, input) => {
|
|
157
216
|
var _a, _b;
|
|
158
|
-
acc[input.id] =
|
|
217
|
+
acc[input.id] =
|
|
218
|
+
typeof input.value === 'object'
|
|
219
|
+
? JSON.stringify(input.value)
|
|
220
|
+
: (_b = (_a = input.value) === null || _a === void 0 ? void 0 : _a.toString()) !== null && _b !== void 0 ? _b : '';
|
|
159
221
|
return acc;
|
|
160
222
|
}, {});
|
|
161
|
-
|
|
223
|
+
const valueInterpolatedWithGlobalContext = this.ctx.global.interpolate(command);
|
|
224
|
+
return (0, template_js_1.interpolateWithInputs)(valueInterpolatedWithGlobalContext, vars);
|
|
162
225
|
}
|
|
163
226
|
async collectAndValidateOutputsAsync(outputsDir) {
|
|
164
227
|
var _a;
|
|
@@ -197,14 +260,26 @@ class BuildStep {
|
|
|
197
260
|
});
|
|
198
261
|
}
|
|
199
262
|
}
|
|
200
|
-
|
|
263
|
+
async collectAndUpdateEnvsAsync(envsDir) {
|
|
264
|
+
const filenames = await promises_1.default.readdir(envsDir);
|
|
265
|
+
const entries = await Promise.all(filenames.map(async (basename) => {
|
|
266
|
+
const rawContents = await promises_1.default.readFile(path_1.default.join(envsDir, basename), 'utf-8');
|
|
267
|
+
return [basename, rawContents];
|
|
268
|
+
}));
|
|
269
|
+
this.ctx.global.updateEnv({
|
|
270
|
+
...this.ctx.global.env,
|
|
271
|
+
...Object.fromEntries(entries),
|
|
272
|
+
});
|
|
273
|
+
}
|
|
274
|
+
getScriptEnv({ envsDir, outputsDir, }) {
|
|
201
275
|
var _a;
|
|
276
|
+
const env = { ...this.ctx.global.env, ...this.env };
|
|
202
277
|
const currentPath = (_a = env.PATH) !== null && _a !== void 0 ? _a : process.env.PATH;
|
|
203
278
|
const newPath = currentPath ? `${bin_js_1.BIN_PATH}:${currentPath}` : bin_js_1.BIN_PATH;
|
|
204
279
|
return {
|
|
205
280
|
...env,
|
|
206
|
-
__EXPO_STEPS_BUILD_ID: this.ctx.buildId,
|
|
207
281
|
__EXPO_STEPS_OUTPUTS_DIR: outputsDir,
|
|
282
|
+
__EXPO_STEPS_ENVS_DIR: envsDir,
|
|
208
283
|
__EXPO_STEPS_WORKING_DIRECTORY: this.ctx.workingDirectory,
|
|
209
284
|
PATH: newPath,
|
|
210
285
|
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { BuildStepContext } from './BuildStepContext.js';
|
|
1
|
+
import { BuildStepContext, BuildStepGlobalContext } from './BuildStepContext.js';
|
|
2
2
|
import { BuildStepInput, BuildStepInputById } from './BuildStepInput.js';
|
|
3
|
-
import { BuildStepOutput, BuildStepOutputById } from './BuildStepOutput.js';
|
|
3
|
+
import { BuildStepOutput, BuildStepOutputById, SerializedBuildStepOutput } from './BuildStepOutput.js';
|
|
4
4
|
import { BuildStepEnv } from './BuildStepEnv.js';
|
|
5
5
|
import { BuildRuntimePlatform } from './BuildRuntimePlatform.js';
|
|
6
6
|
export declare enum BuildStepStatus {
|
|
@@ -20,7 +20,24 @@ export type BuildStepFunction = (ctx: BuildStepContext, { inputs, outputs, env,
|
|
|
20
20
|
outputs: BuildStepOutputById;
|
|
21
21
|
env: BuildStepEnv;
|
|
22
22
|
}) => unknown;
|
|
23
|
-
export
|
|
23
|
+
export interface SerializedBuildStepOutputAccessor {
|
|
24
|
+
id: string;
|
|
25
|
+
executed: boolean;
|
|
26
|
+
outputById: Record<string, SerializedBuildStepOutput>;
|
|
27
|
+
displayName: string;
|
|
28
|
+
}
|
|
29
|
+
export declare class BuildStepOutputAccessor {
|
|
30
|
+
readonly id: string;
|
|
31
|
+
readonly displayName: string;
|
|
32
|
+
protected readonly executed: boolean;
|
|
33
|
+
protected readonly outputById: BuildStepOutputById;
|
|
34
|
+
constructor(id: string, displayName: string, executed: boolean, outputById: BuildStepOutputById);
|
|
35
|
+
getOutputValueByName(name: string): string | undefined;
|
|
36
|
+
hasOutputParameter(name: string): boolean;
|
|
37
|
+
serialize(): SerializedBuildStepOutputAccessor;
|
|
38
|
+
static deserialize(serialized: SerializedBuildStepOutputAccessor): BuildStepOutputAccessor;
|
|
39
|
+
}
|
|
40
|
+
export declare class BuildStep extends BuildStepOutputAccessor {
|
|
24
41
|
readonly id: string;
|
|
25
42
|
readonly name?: string;
|
|
26
43
|
readonly displayName: string;
|
|
@@ -31,18 +48,19 @@ export declare class BuildStep {
|
|
|
31
48
|
readonly fn?: BuildStepFunction;
|
|
32
49
|
readonly shell: string;
|
|
33
50
|
readonly ctx: BuildStepContext;
|
|
51
|
+
readonly env: BuildStepEnv;
|
|
34
52
|
status: BuildStepStatus;
|
|
35
53
|
private readonly internalId;
|
|
36
54
|
private readonly inputById;
|
|
37
|
-
|
|
38
|
-
|
|
55
|
+
protected readonly outputById: BuildStepOutputById;
|
|
56
|
+
protected executed: boolean;
|
|
39
57
|
static getNewId(userDefinedId?: string): string;
|
|
40
58
|
static getDisplayName({ id, name, command, }: {
|
|
41
59
|
id: string;
|
|
42
60
|
name?: string;
|
|
43
61
|
command?: string;
|
|
44
62
|
}): string;
|
|
45
|
-
constructor(ctx:
|
|
63
|
+
constructor(ctx: BuildStepGlobalContext, { id, name, displayName, inputs, outputs, command, fn, workingDirectory: maybeWorkingDirectory, shell, supportedRuntimePlatforms: maybeSupportedRuntimePlatforms, env, }: {
|
|
46
64
|
id: string;
|
|
47
65
|
name?: string;
|
|
48
66
|
displayName: string;
|
|
@@ -53,14 +71,16 @@ export declare class BuildStep {
|
|
|
53
71
|
workingDirectory?: string;
|
|
54
72
|
shell?: string;
|
|
55
73
|
supportedRuntimePlatforms?: BuildRuntimePlatform[];
|
|
74
|
+
env?: BuildStepEnv;
|
|
56
75
|
});
|
|
57
|
-
executeAsync(
|
|
76
|
+
executeAsync(): Promise<void>;
|
|
58
77
|
hasOutputParameter(name: string): boolean;
|
|
59
78
|
getOutputValueByName(name: string): string | undefined;
|
|
60
79
|
canBeRunOnRuntimePlatform(): boolean;
|
|
61
80
|
private executeCommandAsync;
|
|
62
81
|
private exectuteFnAsync;
|
|
63
|
-
private
|
|
82
|
+
private interpolateInputsAndGlobalContextInCommand;
|
|
64
83
|
private collectAndValidateOutputsAsync;
|
|
84
|
+
private collectAndUpdateEnvsAsync;
|
|
65
85
|
private getScriptEnv;
|
|
66
86
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BuildStep.js","s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ACtC,MAAM,SAAS,GAAG,uBAAuB,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YAC1E,MAAM,IAAI,iCAAqB,CAAC,4CAA4C,SAAS,EAAE,EAAE;gBACvF,QAAQ,EAAE,EAAE,GAAG,EAAE,uBAAuB,EAAE;aAC3C,CAAC,CAAC;SACJ;IACH,CAAC;IAEO,YAAY,CAAC,GAAiB,EAAE,UAAkB;;QACxD,MAAM,WAAW,GAAG,MAAA,GAAG,CAAC,IAAI,mCAAI,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC;QACjD,MAAM,OAAO,GAAG,WAAW,CAAC,CAAC,CAAC,GAAG,iBAAQ,IAAI,WAAW,EAAE,CAAC,CAAC,CAAC,iBAAQ,CAAC;QACtE,OAAO;YACL,GAAG,GAAG;YACN,qBAAqB,EAAE,IAAI,CAAC,GAAG,CAAC,OAAO;YACvC,wBAAwB,EAAE,UAAU;YACpC,8BAA8B,EAAE,IAAI,CAAC,GAAG,CAAC,gBAAgB;YACzD,IAAI,EAAE,OAAO;SACd,CAAC;IACJ,CAAC;CACF;AAnQD,8BAmQC","sourcesContent":["import assert from 'assert';\nimport fs from 'fs/promises';\nimport path from 'path';\n\nimport { v4 as uuidv4 } from 'uuid';\n\nimport { BuildStepContext } from './BuildStepContext.js';\nimport { BuildStepInput, BuildStepInputById, makeBuildStepInputByIdMap } from './BuildStepInput.js';\nimport {\n BuildStepOutput,\n BuildStepOutputById,\n makeBuildStepOutputByIdMap,\n} from './BuildStepOutput.js';\nimport { BIN_PATH } from './utils/shell/bin.js';\nimport { getDefaultShell, getShellCommandAndArgs } from './utils/shell/command.js';\nimport {\n cleanUpStepTemporaryDirectoriesAsync,\n createTemporaryOutputsDirectoryAsync,\n saveScriptToTemporaryFileAsync,\n} from './BuildTemporaryFiles.js';\nimport { spawnAsync } from './utils/shell/spawn.js';\nimport { interpolateWithInputs } from './utils/template.js';\nimport { BuildStepRuntimeError } from './errors.js';\nimport { BuildStepEnv } from './BuildStepEnv.js';\nimport { BuildRuntimePlatform } from './BuildRuntimePlatform.js';\n\nexport enum BuildStepStatus {\n NEW = 'new',\n IN_PROGRESS = 'in-progress',\n CANCELED = 'canceled',\n FAIL = 'fail',\n WARNING = 'warning',\n SUCCESS = 'success',\n}\n\nexport enum BuildStepLogMarker {\n START_STEP = 'start-step',\n END_STEP = 'end-step',\n}\n\nexport type BuildStepFunction = (\n ctx: BuildStepContext,\n {\n inputs,\n outputs,\n env,\n }: { inputs: BuildStepInputById; outputs: BuildStepOutputById; env: BuildStepEnv }\n) => unknown;\n\n// TODO: move to a place common with tests\nconst UUID_REGEX =\n /^[0-9a-fA-F]{8}\\b-[0-9a-fA-F]{4}\\b-[0-9a-fA-F]{4}\\b-[0-9a-fA-F]{4}\\b-[0-9a-fA-F]{12}$/;\n\nexport class BuildStep {\n public readonly id: string;\n public readonly name?: string;\n public readonly displayName: string;\n public readonly supportedRuntimePlatforms?: BuildRuntimePlatform[];\n public readonly inputs?: BuildStepInput[];\n public readonly outputs?: BuildStepOutput[];\n public readonly command?: string;\n public readonly fn?: BuildStepFunction;\n public readonly shell: string;\n public readonly ctx: BuildStepContext;\n public status: BuildStepStatus;\n\n private readonly internalId: string;\n private readonly inputById: BuildStepInputById;\n private readonly outputById: BuildStepOutputById;\n private executed = false;\n\n public static getNewId(userDefinedId?: string): string {\n return userDefinedId ?? uuidv4();\n }\n\n public static getDisplayName({\n id,\n name,\n command,\n }: {\n id: string;\n name?: string;\n command?: string;\n }): string {\n if (name) {\n return name;\n }\n if (!id.match(UUID_REGEX)) {\n return id;\n }\n if (command) {\n const splits = command.trim().split('\\n');\n for (const split of splits) {\n const trimmed = split.trim();\n if (trimmed && !trimmed.startsWith('#')) {\n return trimmed;\n }\n }\n }\n return id;\n }\n\n constructor(\n ctx: BuildStepContext,\n {\n id,\n name,\n displayName,\n inputs,\n outputs,\n command,\n fn,\n workingDirectory: maybeWorkingDirectory,\n shell,\n supportedRuntimePlatforms: maybeSupportedRuntimePlatforms,\n }: {\n id: string;\n name?: string;\n displayName: string;\n inputs?: BuildStepInput[];\n outputs?: BuildStepOutput[];\n command?: string;\n fn?: BuildStepFunction;\n workingDirectory?: string;\n shell?: string;\n supportedRuntimePlatforms?: BuildRuntimePlatform[];\n }\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.id = id;\n this.name = name;\n this.displayName = displayName;\n this.supportedRuntimePlatforms = maybeSupportedRuntimePlatforms;\n this.inputs = inputs;\n this.outputs = outputs;\n this.inputById = makeBuildStepInputByIdMap(inputs);\n this.outputById = makeBuildStepOutputByIdMap(outputs);\n this.fn = fn;\n this.command = command;\n this.shell = shell ?? getDefaultShell();\n this.status = BuildStepStatus.NEW;\n\n this.internalId = uuidv4();\n\n const logger = ctx.logger.child({\n buildStepInternalId: this.internalId,\n buildStepId: this.id,\n buildStepDisplayName: this.displayName,\n });\n const workingDirectory =\n maybeWorkingDirectory !== undefined\n ? path.resolve(ctx.workingDirectory, maybeWorkingDirectory)\n : ctx.workingDirectory;\n this.ctx = ctx.child({ logger, workingDirectory });\n\n ctx.registerStep(this);\n }\n\n public async executeAsync(env: BuildStepEnv = process.env): Promise<void> {\n try {\n this.ctx.logger.info(\n { marker: BuildStepLogMarker.START_STEP },\n `Executing build step \"${this.displayName}\"`\n );\n this.status = BuildStepStatus.IN_PROGRESS;\n\n if (this.command !== undefined) {\n await this.executeCommandAsync(env);\n } else {\n await this.exectuteFnAsync(env);\n }\n\n this.ctx.logger.info(\n { marker: BuildStepLogMarker.END_STEP, result: BuildStepStatus.SUCCESS },\n `Finished build step \"${this.displayName}\" successfully`\n );\n this.status = BuildStepStatus.SUCCESS;\n } catch (err) {\n this.ctx.logger.error({ err });\n this.ctx.logger.error(\n { marker: BuildStepLogMarker.END_STEP, result: BuildStepStatus.FAIL },\n `Build step \"${this.displayName}\" failed`\n );\n this.status = BuildStepStatus.FAIL;\n throw err;\n } finally {\n this.executed = true;\n }\n }\n\n public hasOutputParameter(name: string): boolean {\n return name in this.outputById;\n }\n\n public getOutputValueByName(name: string): string | undefined {\n if (!this.executed) {\n throw new BuildStepRuntimeError(\n `Failed getting output \"${name}\" from step \"${this.displayName}\". The step has not been executed yet.`\n );\n }\n if (!this.hasOutputParameter(name)) {\n throw new BuildStepRuntimeError(`Step \"${this.displayName}\" does not have output \"${name}\".`);\n }\n return this.outputById[name].value;\n }\n\n public canBeRunOnRuntimePlatform(): boolean {\n return (\n !this.supportedRuntimePlatforms ||\n this.supportedRuntimePlatforms.includes(this.ctx.runtimePlatform)\n );\n }\n\n private async executeCommandAsync(env: BuildStepEnv): Promise<void> {\n assert(this.command, 'Command must be defined.');\n\n try {\n const command = this.interpolateInputsInCommand(this.command, this.inputs);\n this.ctx.logger.debug(`Interpolated inputs in the command template`);\n\n const outputsDir = await createTemporaryOutputsDirectoryAsync(this.ctx, this.id);\n this.ctx.logger.debug(`Created temporary directory for step outputs: ${outputsDir}`);\n\n const scriptPath = await saveScriptToTemporaryFileAsync(this.ctx, this.id, command);\n this.ctx.logger.debug(`Saved script to ${scriptPath}`);\n\n const { command: shellCommand, args } = getShellCommandAndArgs(this.shell, scriptPath);\n this.ctx.logger.debug(\n `Executing script: ${shellCommand}${args !== undefined ? ` ${args.join(' ')}` : ''}`\n );\n await spawnAsync(shellCommand, args ?? [], {\n cwd: this.ctx.workingDirectory,\n logger: this.ctx.logger,\n env: this.getScriptEnv(env, outputsDir),\n });\n this.ctx.logger.debug(`Script completed successfully`);\n\n await this.collectAndValidateOutputsAsync(outputsDir);\n this.ctx.logger.debug('Finished collecting output paramters');\n } finally {\n await cleanUpStepTemporaryDirectoriesAsync(this.ctx, this.id);\n }\n }\n\n private async exectuteFnAsync(env: BuildStepEnv): Promise<void> {\n assert(this.fn, 'Function (fn) must be defined');\n\n await this.fn(this.ctx, { inputs: this.inputById, outputs: this.outputById, env });\n }\n\n private interpolateInputsInCommand(command: string, inputs?: BuildStepInput[]): string {\n if (!inputs) {\n return command;\n }\n const vars = inputs.reduce((acc, input) => {\n acc[input.id] = input.value?.toString() ?? '';\n return acc;\n }, {} as Record<string, string>);\n return interpolateWithInputs(command, vars);\n }\n\n private async collectAndValidateOutputsAsync(outputsDir: string): Promise<void> {\n const files = await fs.readdir(outputsDir);\n\n const nonDefinedOutputIds: string[] = [];\n for (const outputId of files) {\n if (!(outputId in this.outputById)) {\n nonDefinedOutputIds.push(outputId);\n } else {\n const file = path.join(outputsDir, outputId);\n const rawContents = await fs.readFile(file, 'utf-8');\n const value = rawContents.trim();\n this.outputById[outputId].set(value);\n }\n }\n\n if (nonDefinedOutputIds.length > 0) {\n const idsString = nonDefinedOutputIds.map((i) => `\"${i}\"`).join(', ');\n this.ctx.logger.warn(`Some outputs are not defined in step config: ${idsString}`);\n }\n\n const nonSetRequiredOutputIds: string[] = [];\n for (const output of this.outputs ?? []) {\n try {\n const value = output.value;\n this.ctx.logger.debug(`Output parameter \"${output.id}\" is set to \"${value}\"`);\n } catch (err) {\n this.ctx.logger.debug({ err }, `Getting value for output parameter \"${output.id}\" failed.`);\n nonSetRequiredOutputIds.push(output.id);\n }\n }\n if (nonSetRequiredOutputIds.length > 0) {\n const idsString = nonSetRequiredOutputIds.map((i) => `\"${i}\"`).join(', ');\n throw new BuildStepRuntimeError(`Some required outputs have not been set: ${idsString}`, {\n metadata: { ids: nonSetRequiredOutputIds },\n });\n }\n }\n\n private getScriptEnv(env: BuildStepEnv, outputsDir: string): Record<string, string> {\n const currentPath = env.PATH ?? process.env.PATH;\n const newPath = currentPath ? `${BIN_PATH}:${currentPath}` : BIN_PATH;\n return {\n ...env,\n __EXPO_STEPS_BUILD_ID: this.ctx.buildId,\n __EXPO_STEPS_OUTPUTS_DIR: outputsDir,\n __EXPO_STEPS_WORKING_DIRECTORY: this.ctx.workingDirectory,\n PATH: newPath,\n };\n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AAI,CAAC,OAAO,EAAE,QAAQ,CAAC,EAAE,OAAO,CAAC,CAAC;YAC7E,OAAO,CAAC,QAAQ,EAAE,WAAW,CAAC,CAAC;QACjC,CAAC,CAAC,CACH,CAAC;QACF,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,SAAS,CAAC;YACxB,GAAG,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,GAAG;YACtB,GAAG,MAAM,CAAC,WAAW,CAAC,OAAO,CAAC;SAC/B,CAAC,CAAC;IACL,CAAC;IAEO,YAAY,CAAC,EACnB,OAAO,EACP,UAAU,GAIX;;QACC,MAAM,GAAG,GAAG,EAAE,GAAG,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;QACpD,MAAM,WAAW,GAAG,MAAA,GAAG,CAAC,IAAI,mCAAI,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC;QACjD,MAAM,OAAO,GAAG,WAAW,CAAC,CAAC,CAAC,GAAG,iBAAQ,IAAI,WAAW,EAAE,CAAC,CAAC,CAAC,iBAAQ,CAAC;QACtE,OAAO;YACL,GAAG,GAAG;YACN,wBAAwB,EAAE,UAAU;YACpC,qBAAqB,EAAE,OAAO;YAC9B,8BAA8B,EAAE,IAAI,CAAC,GAAG,CAAC,gBAAgB;YACzD,IAAI,EAAE,OAAO;SACd,CAAC;IACJ,CAAC;CACF;AAlUD,8BAkUC","sourcesContent":["import assert from 'assert';\nimport fs from 'fs/promises';\nimport path from 'path';\n\nimport { v4 as uuidv4 } from 'uuid';\n\nimport { BuildStepContext, BuildStepGlobalContext } from './BuildStepContext.js';\nimport { BuildStepInput, BuildStepInputById, makeBuildStepInputByIdMap } from './BuildStepInput.js';\nimport {\n BuildStepOutput,\n BuildStepOutputById,\n SerializedBuildStepOutput,\n makeBuildStepOutputByIdMap,\n} from './BuildStepOutput.js';\nimport { BIN_PATH } from './utils/shell/bin.js';\nimport { getDefaultShell, getShellCommandAndArgs } from './utils/shell/command.js';\nimport {\n cleanUpStepTemporaryDirectoriesAsync,\n createTemporaryEnvsDirectoryAsync,\n createTemporaryOutputsDirectoryAsync,\n saveScriptToTemporaryFileAsync,\n} from './BuildTemporaryFiles.js';\nimport { spawnAsync } from './utils/shell/spawn.js';\nimport { interpolateWithInputs } from './utils/template.js';\nimport { BuildStepRuntimeError } from './errors.js';\nimport { BuildStepEnv } from './BuildStepEnv.js';\nimport { BuildRuntimePlatform } from './BuildRuntimePlatform.js';\n\nexport enum BuildStepStatus {\n NEW = 'new',\n IN_PROGRESS = 'in-progress',\n CANCELED = 'canceled',\n FAIL = 'fail',\n WARNING = 'warning',\n SUCCESS = 'success',\n}\n\nexport enum BuildStepLogMarker {\n START_STEP = 'start-step',\n END_STEP = 'end-step',\n}\n\nexport type BuildStepFunction = (\n ctx: BuildStepContext,\n {\n inputs,\n outputs,\n env,\n }: { inputs: BuildStepInputById; outputs: BuildStepOutputById; env: BuildStepEnv }\n) => unknown;\n\n// TODO: move to a place common with tests\nconst UUID_REGEX =\n /^[0-9a-fA-F]{8}\\b-[0-9a-fA-F]{4}\\b-[0-9a-fA-F]{4}\\b-[0-9a-fA-F]{4}\\b-[0-9a-fA-F]{12}$/;\n\nexport interface SerializedBuildStepOutputAccessor {\n id: string;\n executed: boolean;\n outputById: Record<string, SerializedBuildStepOutput>;\n displayName: string;\n}\n\nexport class BuildStepOutputAccessor {\n constructor(\n public readonly id: string,\n public readonly displayName: string,\n protected readonly executed: boolean,\n protected readonly outputById: BuildStepOutputById\n ) {}\n\n public getOutputValueByName(name: string): string | undefined {\n if (!this.executed) {\n throw new BuildStepRuntimeError(\n `Failed getting output \"${name}\" from step \"${this.displayName}\". The step has not been executed yet.`\n );\n }\n if (!this.hasOutputParameter(name)) {\n throw new BuildStepRuntimeError(`Step \"${this.displayName}\" does not have output \"${name}\".`);\n }\n return this.outputById[name].value;\n }\n\n public hasOutputParameter(name: string): boolean {\n return name in this.outputById;\n }\n\n public serialize(): SerializedBuildStepOutputAccessor {\n return {\n id: this.id,\n executed: this.executed,\n outputById: Object.fromEntries(\n Object.entries(this.outputById).map(([key, value]) => [key, value.serialize()])\n ),\n displayName: this.displayName,\n };\n }\n\n public static deserialize(\n serialized: SerializedBuildStepOutputAccessor\n ): BuildStepOutputAccessor {\n const outputById = Object.fromEntries(\n Object.entries(serialized.outputById).map(([key, value]) => [\n key,\n BuildStepOutput.deserialize(value),\n ])\n );\n return new BuildStepOutputAccessor(\n serialized.id,\n serialized.displayName,\n serialized.executed,\n outputById\n );\n }\n}\n\nexport class BuildStep extends BuildStepOutputAccessor {\n public readonly id: string;\n public readonly name?: string;\n public readonly displayName: string;\n public readonly supportedRuntimePlatforms?: BuildRuntimePlatform[];\n public readonly inputs?: BuildStepInput[];\n public readonly outputs?: BuildStepOutput[];\n public readonly command?: string;\n public readonly fn?: BuildStepFunction;\n public readonly shell: string;\n public readonly ctx: BuildStepContext;\n public readonly env: BuildStepEnv;\n public status: BuildStepStatus;\n\n private readonly internalId: string;\n private readonly inputById: BuildStepInputById;\n protected readonly outputById: BuildStepOutputById;\n protected executed = false;\n\n public static getNewId(userDefinedId?: string): string {\n return userDefinedId ?? uuidv4();\n }\n\n public static getDisplayName({\n id,\n name,\n command,\n }: {\n id: string;\n name?: string;\n command?: string;\n }): string {\n if (name) {\n return name;\n }\n if (!id.match(UUID_REGEX)) {\n return id;\n }\n if (command) {\n const splits = command.trim().split('\\n');\n for (const split of splits) {\n const trimmed = split.trim();\n if (trimmed && !trimmed.startsWith('#')) {\n return trimmed;\n }\n }\n }\n return id;\n }\n\n constructor(\n ctx: BuildStepGlobalContext,\n {\n id,\n name,\n displayName,\n inputs,\n outputs,\n command,\n fn,\n workingDirectory: maybeWorkingDirectory,\n shell,\n supportedRuntimePlatforms: maybeSupportedRuntimePlatforms,\n env,\n }: {\n id: string;\n name?: string;\n displayName: string;\n inputs?: BuildStepInput[];\n outputs?: BuildStepOutput[];\n command?: string;\n fn?: BuildStepFunction;\n workingDirectory?: string;\n shell?: string;\n supportedRuntimePlatforms?: BuildRuntimePlatform[];\n env?: BuildStepEnv;\n }\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 const outputById = makeBuildStepOutputByIdMap(outputs);\n super(id, displayName, false, outputById);\n\n this.id = id;\n this.name = name;\n this.displayName = displayName;\n this.supportedRuntimePlatforms = maybeSupportedRuntimePlatforms;\n this.inputs = inputs;\n this.outputs = outputs;\n this.inputById = makeBuildStepInputByIdMap(inputs);\n this.outputById = outputById;\n this.fn = fn;\n this.command = command;\n this.shell = shell ?? getDefaultShell();\n this.status = BuildStepStatus.NEW;\n\n this.internalId = uuidv4();\n\n const logger = ctx.baseLogger.child({\n buildStepInternalId: this.internalId,\n buildStepId: this.id,\n buildStepDisplayName: this.displayName,\n });\n const workingDirectory =\n maybeWorkingDirectory !== undefined\n ? path.resolve(ctx.defaultWorkingDirectory, maybeWorkingDirectory)\n : ctx.defaultWorkingDirectory;\n this.ctx = ctx.stepCtx({ logger, workingDirectory });\n this.env = env ?? {};\n\n ctx.registerStep(this);\n }\n\n public async executeAsync(): Promise<void> {\n try {\n this.ctx.logger.info(\n { marker: BuildStepLogMarker.START_STEP },\n `Executing build step \"${this.displayName}\"`\n );\n this.status = BuildStepStatus.IN_PROGRESS;\n\n if (this.command !== undefined) {\n await this.executeCommandAsync();\n } else {\n await this.exectuteFnAsync();\n }\n\n this.ctx.logger.info(\n { marker: BuildStepLogMarker.END_STEP, result: BuildStepStatus.SUCCESS },\n `Finished build step \"${this.displayName}\" successfully`\n );\n this.status = BuildStepStatus.SUCCESS;\n } catch (err) {\n this.ctx.logger.error({ err });\n this.ctx.logger.error(\n { marker: BuildStepLogMarker.END_STEP, result: BuildStepStatus.FAIL },\n `Build step \"${this.displayName}\" failed`\n );\n this.status = BuildStepStatus.FAIL;\n throw err;\n } finally {\n this.executed = true;\n }\n }\n\n public hasOutputParameter(name: string): boolean {\n return name in this.outputById;\n }\n\n public getOutputValueByName(name: string): string | undefined {\n if (!this.executed) {\n throw new BuildStepRuntimeError(\n `Failed getting output \"${name}\" from step \"${this.displayName}\". The step has not been executed yet.`\n );\n }\n if (!this.hasOutputParameter(name)) {\n throw new BuildStepRuntimeError(`Step \"${this.displayName}\" does not have output \"${name}\".`);\n }\n return this.outputById[name].value;\n }\n\n public canBeRunOnRuntimePlatform(): boolean {\n return (\n !this.supportedRuntimePlatforms ||\n this.supportedRuntimePlatforms.includes(this.ctx.global.runtimePlatform)\n );\n }\n\n private async executeCommandAsync(): Promise<void> {\n assert(this.command, 'Command must be defined.');\n\n try {\n const command = this.interpolateInputsAndGlobalContextInCommand(this.command, this.inputs);\n this.ctx.logger.debug(`Interpolated inputs in the command template`);\n\n const outputsDir = await createTemporaryOutputsDirectoryAsync(this.ctx.global, this.id);\n this.ctx.logger.debug(`Created temporary directory for step outputs: ${outputsDir}`);\n\n const envsDir = await createTemporaryEnvsDirectoryAsync(this.ctx.global, this.id);\n this.ctx.logger.debug(\n `Created temporary directory for step environment variables: ${outputsDir}`\n );\n\n const scriptPath = await saveScriptToTemporaryFileAsync(this.ctx.global, this.id, command);\n this.ctx.logger.debug(`Saved script to ${scriptPath}`);\n\n const { command: shellCommand, args } = getShellCommandAndArgs(this.shell, scriptPath);\n this.ctx.logger.debug(\n `Executing script: ${shellCommand}${args !== undefined ? ` ${args.join(' ')}` : ''}`\n );\n await spawnAsync(shellCommand, args ?? [], {\n cwd: this.ctx.workingDirectory,\n logger: this.ctx.logger,\n env: this.getScriptEnv({ outputsDir, envsDir }),\n });\n this.ctx.logger.debug(`Script completed successfully`);\n\n await this.collectAndValidateOutputsAsync(outputsDir);\n await this.collectAndUpdateEnvsAsync(envsDir);\n this.ctx.logger.debug('Finished collecting output paramters');\n } finally {\n await cleanUpStepTemporaryDirectoriesAsync(this.ctx.global, this.id);\n }\n }\n\n private async exectuteFnAsync(): Promise<void> {\n assert(this.fn, 'Function (fn) must be defined');\n\n try {\n const outputsDir = await createTemporaryOutputsDirectoryAsync(this.ctx.global, this.id);\n this.ctx.logger.debug(`Created temporary directory for step outputs: ${outputsDir}`);\n\n const envsDir = await createTemporaryEnvsDirectoryAsync(this.ctx.global, this.id);\n this.ctx.logger.debug(\n `Created temporary directory for step environment variables: ${outputsDir}`\n );\n\n await this.fn(this.ctx, {\n inputs: this.inputById,\n outputs: this.outputById,\n env: this.getScriptEnv({ outputsDir, envsDir }),\n });\n\n this.ctx.logger.debug(`Script completed successfully`);\n\n await this.collectAndValidateOutputsAsync(outputsDir);\n await this.collectAndUpdateEnvsAsync(envsDir);\n this.ctx.logger.debug('Finished collecting output paramters');\n } finally {\n await cleanUpStepTemporaryDirectoriesAsync(this.ctx.global, this.id);\n }\n }\n\n private interpolateInputsAndGlobalContextInCommand(\n command: string,\n inputs?: BuildStepInput[]\n ): string {\n if (!inputs) {\n return command;\n }\n const vars = inputs.reduce((acc, input) => {\n acc[input.id] =\n typeof input.value === 'object'\n ? JSON.stringify(input.value)\n : input.value?.toString() ?? '';\n return acc;\n }, {} as Record<string, string>);\n const valueInterpolatedWithGlobalContext = this.ctx.global.interpolate(command);\n return interpolateWithInputs(valueInterpolatedWithGlobalContext, vars);\n }\n\n private async collectAndValidateOutputsAsync(outputsDir: string): Promise<void> {\n const files = await fs.readdir(outputsDir);\n\n const nonDefinedOutputIds: string[] = [];\n for (const outputId of files) {\n if (!(outputId in this.outputById)) {\n nonDefinedOutputIds.push(outputId);\n } else {\n const file = path.join(outputsDir, outputId);\n const rawContents = await fs.readFile(file, 'utf-8');\n const value = rawContents.trim();\n this.outputById[outputId].set(value);\n }\n }\n\n if (nonDefinedOutputIds.length > 0) {\n const idsString = nonDefinedOutputIds.map((i) => `\"${i}\"`).join(', ');\n this.ctx.logger.warn(`Some outputs are not defined in step config: ${idsString}`);\n }\n\n const nonSetRequiredOutputIds: string[] = [];\n for (const output of this.outputs ?? []) {\n try {\n const value = output.value;\n this.ctx.logger.debug(`Output parameter \"${output.id}\" is set to \"${value}\"`);\n } catch (err) {\n this.ctx.logger.debug({ err }, `Getting value for output parameter \"${output.id}\" failed.`);\n nonSetRequiredOutputIds.push(output.id);\n }\n }\n if (nonSetRequiredOutputIds.length > 0) {\n const idsString = nonSetRequiredOutputIds.map((i) => `\"${i}\"`).join(', ');\n throw new BuildStepRuntimeError(`Some required outputs have not been set: ${idsString}`, {\n metadata: { ids: nonSetRequiredOutputIds },\n });\n }\n }\n\n private async collectAndUpdateEnvsAsync(envsDir: string): Promise<void> {\n const filenames = await fs.readdir(envsDir);\n\n const entries = await Promise.all(\n filenames.map(async (basename) => {\n const rawContents = await fs.readFile(path.join(envsDir, basename), 'utf-8');\n return [basename, rawContents];\n })\n );\n this.ctx.global.updateEnv({\n ...this.ctx.global.env,\n ...Object.fromEntries(entries),\n });\n }\n\n private getScriptEnv({\n envsDir,\n outputsDir,\n }: {\n envsDir: string;\n outputsDir: string;\n }): Record<string, string> {\n const env = { ...this.ctx.global.env, ...this.env };\n const currentPath = env.PATH ?? process.env.PATH;\n const newPath = currentPath ? `${BIN_PATH}:${currentPath}` : BIN_PATH;\n return {\n ...env,\n __EXPO_STEPS_OUTPUTS_DIR: outputsDir,\n __EXPO_STEPS_ENVS_DIR: envsDir,\n __EXPO_STEPS_WORKING_DIRECTORY: this.ctx.workingDirectory,\n PATH: newPath,\n };\n }\n}\n"]}
|
|
@@ -3,23 +3,40 @@ 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.BuildStepContext = void 0;
|
|
6
|
+
exports.BuildStepContext = exports.BuildStepGlobalContext = void 0;
|
|
7
7
|
const os_1 = __importDefault(require("os"));
|
|
8
8
|
const path_1 = __importDefault(require("path"));
|
|
9
|
+
const uuid_1 = require("uuid");
|
|
10
|
+
const BuildStep_js_1 = require("./BuildStep.cjs");
|
|
9
11
|
const template_js_1 = require("./utils/template.cjs");
|
|
10
12
|
const errors_js_1 = require("./errors.cjs");
|
|
11
|
-
class
|
|
12
|
-
constructor(
|
|
13
|
-
this.
|
|
14
|
-
this.logger = logger;
|
|
13
|
+
class BuildStepGlobalContext {
|
|
14
|
+
constructor(provider, skipCleanup, configPath) {
|
|
15
|
+
this.provider = provider;
|
|
15
16
|
this.skipCleanup = skipCleanup;
|
|
16
|
-
this.
|
|
17
|
-
this.projectSourceDirectory = projectSourceDirectory;
|
|
18
|
-
this.projectTargetDirectory = projectTargetDirectory;
|
|
17
|
+
this.configPath = configPath;
|
|
19
18
|
this.stepById = {};
|
|
20
|
-
this.stepsInternalBuildDirectory = path_1.default.join(os_1.default.tmpdir(), 'eas-build',
|
|
21
|
-
this.
|
|
22
|
-
|
|
19
|
+
this.stepsInternalBuildDirectory = path_1.default.join(os_1.default.tmpdir(), 'eas-build', (0, uuid_1.v4)());
|
|
20
|
+
this.runtimePlatform = provider.runtimePlatform;
|
|
21
|
+
this.baseLogger = provider.logger;
|
|
22
|
+
}
|
|
23
|
+
get projectSourceDirectory() {
|
|
24
|
+
return this.provider.projectSourceDirectory;
|
|
25
|
+
}
|
|
26
|
+
get projectTargetDirectory() {
|
|
27
|
+
return this.provider.projectTargetDirectory;
|
|
28
|
+
}
|
|
29
|
+
get defaultWorkingDirectory() {
|
|
30
|
+
return this.provider.defaultWorkingDirectory;
|
|
31
|
+
}
|
|
32
|
+
get env() {
|
|
33
|
+
return this.provider.env;
|
|
34
|
+
}
|
|
35
|
+
get staticContext() {
|
|
36
|
+
return this.provider.staticContext();
|
|
37
|
+
}
|
|
38
|
+
updateEnv(updatedEnv) {
|
|
39
|
+
this.provider.updateEnv(updatedEnv);
|
|
23
40
|
}
|
|
24
41
|
registerStep(step) {
|
|
25
42
|
this.stepById[step.id] = step;
|
|
@@ -31,8 +48,77 @@ class BuildStepContext {
|
|
|
31
48
|
}
|
|
32
49
|
return this.stepById[stepId].getOutputValueByName(outputId);
|
|
33
50
|
}
|
|
34
|
-
|
|
35
|
-
return
|
|
51
|
+
interpolate(value) {
|
|
52
|
+
return (0, template_js_1.interpolateWithGlobalContext)(value, (path) => {
|
|
53
|
+
var _a, _b;
|
|
54
|
+
return ((_b = (_a = (0, template_js_1.getObjectValueForInterpolation)(path, {
|
|
55
|
+
eas: {
|
|
56
|
+
runtimePlatform: this.runtimePlatform,
|
|
57
|
+
...this.staticContext,
|
|
58
|
+
},
|
|
59
|
+
})) === null || _a === void 0 ? void 0 : _a.toString()) !== null && _b !== void 0 ? _b : '');
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
stepCtx(options) {
|
|
63
|
+
return new BuildStepContext(this, options);
|
|
64
|
+
}
|
|
65
|
+
serialize() {
|
|
66
|
+
return {
|
|
67
|
+
stepsInternalBuildDirectory: this.stepsInternalBuildDirectory,
|
|
68
|
+
stepById: Object.fromEntries(Object.entries(this.stepById).map(([id, step]) => [id, step.serialize()])),
|
|
69
|
+
provider: {
|
|
70
|
+
projectSourceDirectory: this.provider.projectSourceDirectory,
|
|
71
|
+
projectTargetDirectory: this.provider.projectTargetDirectory,
|
|
72
|
+
defaultWorkingDirectory: this.provider.defaultWorkingDirectory,
|
|
73
|
+
runtimePlatform: this.provider.runtimePlatform,
|
|
74
|
+
staticContext: this.provider.staticContext(),
|
|
75
|
+
env: this.provider.env,
|
|
76
|
+
},
|
|
77
|
+
skipCleanup: this.skipCleanup,
|
|
78
|
+
configPath: this.configPath,
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
static deserialize(serialized, logger) {
|
|
82
|
+
const deserializedProvider = {
|
|
83
|
+
projectSourceDirectory: serialized.provider.projectSourceDirectory,
|
|
84
|
+
projectTargetDirectory: serialized.provider.projectTargetDirectory,
|
|
85
|
+
defaultWorkingDirectory: serialized.provider.defaultWorkingDirectory,
|
|
86
|
+
runtimePlatform: serialized.provider.runtimePlatform,
|
|
87
|
+
logger,
|
|
88
|
+
staticContext: () => serialized.provider.staticContext,
|
|
89
|
+
env: serialized.provider.env,
|
|
90
|
+
updateEnv: () => { },
|
|
91
|
+
};
|
|
92
|
+
const ctx = new BuildStepGlobalContext(deserializedProvider, serialized.skipCleanup, serialized.configPath);
|
|
93
|
+
for (const [id, stepOutputAccessor] of Object.entries(serialized.stepById)) {
|
|
94
|
+
ctx.stepById[id] = BuildStep_js_1.BuildStepOutputAccessor.deserialize(stepOutputAccessor);
|
|
95
|
+
}
|
|
96
|
+
ctx.stepsInternalBuildDirectory = serialized.stepsInternalBuildDirectory;
|
|
97
|
+
return ctx;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
exports.BuildStepGlobalContext = BuildStepGlobalContext;
|
|
101
|
+
class BuildStepContext {
|
|
102
|
+
constructor(ctx, { logger, workingDirectory, }) {
|
|
103
|
+
this.ctx = ctx;
|
|
104
|
+
this.logger = logger !== null && logger !== void 0 ? logger : ctx.baseLogger;
|
|
105
|
+
this.workingDirectory = workingDirectory !== null && workingDirectory !== void 0 ? workingDirectory : ctx.defaultWorkingDirectory;
|
|
106
|
+
}
|
|
107
|
+
get global() {
|
|
108
|
+
return this.ctx;
|
|
109
|
+
}
|
|
110
|
+
serialize() {
|
|
111
|
+
return {
|
|
112
|
+
workingDirectory: this.workingDirectory,
|
|
113
|
+
global: this.ctx.serialize(),
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
static deserialize(serialized, logger) {
|
|
117
|
+
const deserializedGlobal = BuildStepGlobalContext.deserialize(serialized.global, logger);
|
|
118
|
+
return new BuildStepContext(deserializedGlobal, {
|
|
119
|
+
logger,
|
|
120
|
+
workingDirectory: serialized.workingDirectory,
|
|
121
|
+
});
|
|
36
122
|
}
|
|
37
123
|
}
|
|
38
124
|
exports.BuildStepContext = BuildStepContext;
|
|
@@ -1,21 +1,71 @@
|
|
|
1
1
|
import { bunyan } from '@expo/logger';
|
|
2
|
-
import { BuildStep } from './BuildStep.js';
|
|
2
|
+
import { BuildStep, SerializedBuildStepOutputAccessor } from './BuildStep.js';
|
|
3
3
|
import { BuildRuntimePlatform } from './BuildRuntimePlatform.js';
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
import { BuildStepEnv } from './BuildStepEnv.js';
|
|
5
|
+
interface SerializedExternalBuildContextProvider {
|
|
6
|
+
projectSourceDirectory: string;
|
|
7
|
+
projectTargetDirectory: string;
|
|
8
|
+
defaultWorkingDirectory: string;
|
|
9
|
+
runtimePlatform: BuildRuntimePlatform;
|
|
10
|
+
staticContext: Record<string, any>;
|
|
11
|
+
env: BuildStepEnv;
|
|
12
|
+
}
|
|
13
|
+
export interface ExternalBuildContextProvider {
|
|
14
|
+
readonly projectSourceDirectory: string;
|
|
15
|
+
readonly projectTargetDirectory: string;
|
|
16
|
+
readonly defaultWorkingDirectory: string;
|
|
17
|
+
readonly runtimePlatform: BuildRuntimePlatform;
|
|
6
18
|
readonly logger: bunyan;
|
|
19
|
+
readonly staticContext: () => Record<string, any>;
|
|
20
|
+
readonly env: BuildStepEnv;
|
|
21
|
+
updateEnv(env: BuildStepEnv): void;
|
|
22
|
+
}
|
|
23
|
+
export interface SerializedBuildStepGlobalContext {
|
|
24
|
+
stepsInternalBuildDirectory: string;
|
|
25
|
+
stepById: Record<string, SerializedBuildStepOutputAccessor>;
|
|
26
|
+
provider: SerializedExternalBuildContextProvider;
|
|
27
|
+
skipCleanup: boolean;
|
|
28
|
+
configPath: string;
|
|
29
|
+
}
|
|
30
|
+
export declare class BuildStepGlobalContext {
|
|
31
|
+
private readonly provider;
|
|
7
32
|
readonly skipCleanup: boolean;
|
|
33
|
+
readonly configPath: string;
|
|
34
|
+
stepsInternalBuildDirectory: string;
|
|
8
35
|
readonly runtimePlatform: BuildRuntimePlatform;
|
|
9
|
-
readonly
|
|
10
|
-
readonly projectTargetDirectory: string;
|
|
11
|
-
readonly stepsInternalBuildDirectory: string;
|
|
12
|
-
readonly workingDirectory: string;
|
|
36
|
+
readonly baseLogger: bunyan;
|
|
13
37
|
private stepById;
|
|
14
|
-
constructor(
|
|
38
|
+
constructor(provider: ExternalBuildContextProvider, skipCleanup: boolean, configPath: string);
|
|
39
|
+
get projectSourceDirectory(): string;
|
|
40
|
+
get projectTargetDirectory(): string;
|
|
41
|
+
get defaultWorkingDirectory(): string;
|
|
42
|
+
get env(): BuildStepEnv;
|
|
43
|
+
get staticContext(): Record<string, any>;
|
|
44
|
+
updateEnv(updatedEnv: BuildStepEnv): void;
|
|
15
45
|
registerStep(step: BuildStep): void;
|
|
16
46
|
getStepOutputValue(path: string): string | undefined;
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
47
|
+
interpolate(value: string): string;
|
|
48
|
+
stepCtx(options: {
|
|
49
|
+
logger: bunyan;
|
|
50
|
+
workingDirectory: string;
|
|
20
51
|
}): BuildStepContext;
|
|
52
|
+
serialize(): SerializedBuildStepGlobalContext;
|
|
53
|
+
static deserialize(serialized: SerializedBuildStepGlobalContext, logger: bunyan): BuildStepGlobalContext;
|
|
54
|
+
}
|
|
55
|
+
export interface SerializedBuildStepContext {
|
|
56
|
+
workingDirectory: string;
|
|
57
|
+
global: SerializedBuildStepGlobalContext;
|
|
58
|
+
}
|
|
59
|
+
export declare class BuildStepContext {
|
|
60
|
+
private readonly ctx;
|
|
61
|
+
readonly logger: bunyan;
|
|
62
|
+
readonly workingDirectory: string;
|
|
63
|
+
constructor(ctx: BuildStepGlobalContext, { logger, workingDirectory, }: {
|
|
64
|
+
logger: bunyan;
|
|
65
|
+
workingDirectory: string;
|
|
66
|
+
});
|
|
67
|
+
get global(): BuildStepGlobalContext;
|
|
68
|
+
serialize(): SerializedBuildStepContext;
|
|
69
|
+
static deserialize(serialized: SerializedBuildStepContext, logger: bunyan): BuildStepContext;
|
|
21
70
|
}
|
|
71
|
+
export {};
|