Skip to content

Commit 543b32c

Browse files
committed
[ENG-14822][steps] Coerce env in steps to string
1 parent c6d4fae commit 543b32c

File tree

2 files changed

+30
-5
lines changed

2 files changed

+30
-5
lines changed

packages/steps/src/BuildConfig.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,12 @@ const BuildFunctionCallSchema = Joi.object({
188188
name: Joi.string(),
189189
workingDirectory: Joi.string(),
190190
shell: Joi.string(),
191-
env: Joi.object().pattern(Joi.string(), Joi.string().allow('')),
191+
env: Joi.object().pattern(
192+
Joi.string(),
193+
Joi.alternatives()
194+
.try(Joi.number(), Joi.string().allow(''))
195+
.custom((value) => String(value))
196+
),
192197
if: Joi.string(),
193198
timeout_minutes: Joi.number().positive(),
194199
// Internal field for metrics collection. Not documented publicly.

packages/steps/src/__tests__/BuildConfig-test.ts

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ describe(validateConfig, () => {
258258

259259
expect(() => {
260260
validateConfig(BuildConfigSchema, buildConfig);
261-
}).toThrowError(/"build.steps\[0\].run.env.ENV1" must be a string/);
261+
}).toThrowError(/"build.steps\[0\].run.env.ENV1" must be one of \[number, string\]/);
262262
});
263263
test('invalid env type', () => {
264264
const buildConfig = {
@@ -278,7 +278,27 @@ describe(validateConfig, () => {
278278

279279
expect(() => {
280280
validateConfig(BuildConfigSchema, buildConfig);
281-
}).toThrowError(/"build.steps\[0\].run.env.ENV1" must be a string/);
281+
}).toThrowError(/"build.steps\[0\].run.env.ENV1" must be one of \[number, string\]/);
282+
});
283+
test('env number coerced to string', () => {
284+
const buildConfig = {
285+
build: {
286+
steps: [
287+
{
288+
run: {
289+
command: 'echo 123',
290+
env: {
291+
HOMEBREW_NO_AUTO_UPDATE: 1,
292+
},
293+
},
294+
},
295+
],
296+
},
297+
};
298+
299+
const config = validateConfig(BuildConfigSchema, buildConfig);
300+
assert(isBuildStepCommandRun(config.build.steps[0]));
301+
expect(config.build.steps[0].run.env).toEqual({ HOMEBREW_NO_AUTO_UPDATE: '1' });
282302
});
283303
test('valid timeout_minutes', () => {
284304
const buildConfig = {
@@ -518,7 +538,7 @@ describe(validateConfig, () => {
518538

519539
expect(() => {
520540
validateConfig(BuildConfigSchema, buildConfig);
521-
}).toThrowError(/"build.steps\[0\].say_hi.env.ENV1" must be a string/);
541+
}).toThrowError(/"build.steps\[0\].say_hi.env.ENV1" must be one of \[number, string\]/);
522542
});
523543
test('invalid env structure', () => {
524544
const buildConfig = {
@@ -544,7 +564,7 @@ describe(validateConfig, () => {
544564

545565
expect(() => {
546566
validateConfig(BuildConfigSchema, buildConfig);
547-
}).toThrowError(/"build.steps\[0\].say_hi.env.ENV1" must be a string/);
567+
}).toThrowError(/"build.steps\[0\].say_hi.env.ENV1" must be one of \[number, string\]/);
548568
});
549569
test('call with inputs boolean', () => {
550570
const buildConfig = {

0 commit comments

Comments
 (0)