From 421490a6c8e38683c027d75633b7f5bb91f1a6ef Mon Sep 17 00:00:00 2001 From: Radoslaw Krzemien Date: Wed, 11 Dec 2024 13:19:07 +0100 Subject: [PATCH 1/3] [steps] Use quotes on env var value Added quotes around the env var value when saving it into the file. The reason for it is that if you set the env value to something like "line 1 line 2 line 3" without the quotes it would remove the implicit new-line characters and save it as 1 line See: https://linear.app/expo/issue/ENG-14373/fix-multiline-slack-message-from-env-vars --- packages/steps/bin/set-env | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/steps/bin/set-env b/packages/steps/bin/set-env index 4fefb639..8006ce06 100755 --- a/packages/steps/bin/set-env +++ b/packages/steps/bin/set-env @@ -20,4 +20,4 @@ if [[ "$NAME" == *"="* ]]; then exit 1 fi -echo -n $VALUE > $__EXPO_STEPS_ENVS_DIR/$NAME +echo -n "$VALUE" > $__EXPO_STEPS_ENVS_DIR/$NAME From 948c25db79a1114ae7519697e7b207a57c985497 Mon Sep 17 00:00:00 2001 From: Radoslaw Krzemien Date: Wed, 11 Dec 2024 13:20:21 +0100 Subject: [PATCH 2/3] [steps] Add util function Added an util function to replace the doubly backslashed escape character in the raw env value with actual escape characters See: https://linear.app/expo/issue/ENG-14373/fix-multiline-slack-message-from-env-vars --- packages/steps/src/utils/envUtils.ts | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 packages/steps/src/utils/envUtils.ts diff --git a/packages/steps/src/utils/envUtils.ts b/packages/steps/src/utils/envUtils.ts new file mode 100644 index 00000000..2c22a433 --- /dev/null +++ b/packages/steps/src/utils/envUtils.ts @@ -0,0 +1,17 @@ +export function fixEscapeCharactersInRawEnvValue(rawValue: string): string { + const escapeCharsMatches = rawValue.match(/\\(\w)/g); + let updatedValue = rawValue; + for (const match of escapeCharsMatches ?? []) { + if (match[1] === 'n') { + updatedValue = updatedValue.replace(`${match[0]}${match[1]}`, '\n'); + } + if (match[1] === 't') { + updatedValue = updatedValue.replace(`${match[0]}${match[1]}`, '\t'); + } + if (match[1] === 'r') { + updatedValue = updatedValue.replace(`${match[0]}${match[1]}`, '\r'); + } + } + + return updatedValue; +} From 7a1636e2185b0b57b9b12a0b12b3d2f098ff9aba Mon Sep 17 00:00:00 2001 From: Radoslaw Krzemien Date: Wed, 11 Dec 2024 13:22:06 +0100 Subject: [PATCH 3/3] [steps] Fix escape chars Used the previously added function to fix the escape characters when reading the raw env value from the file and updating the context See: https://linear.app/expo/issue/ENG-14373/fix-multiline-slack-message-from-env-vars --- packages/steps/src/BuildStep.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/steps/src/BuildStep.ts b/packages/steps/src/BuildStep.ts index 5d428cbe..0e6358fc 100644 --- a/packages/steps/src/BuildStep.ts +++ b/packages/steps/src/BuildStep.ts @@ -28,6 +28,7 @@ import { BuildStepEnv } from './BuildStepEnv.js'; import { BuildRuntimePlatform } from './BuildRuntimePlatform.js'; import { jsepEval } from './utils/jsepEval.js'; import { interpolateJobContext } from './interpolation.js'; +import { fixEscapeCharactersInRawEnvValue } from './utils/envUtils.js'; export enum BuildStepStatus { NEW = 'new', @@ -484,7 +485,8 @@ export class BuildStep extends BuildStepOutputAccessor { const entries = await Promise.all( filenames.map(async (basename) => { const rawContents = await fs.readFile(path.join(envsDir, basename), 'utf-8'); - return [basename, rawContents]; + const updatedContents = fixEscapeCharactersInRawEnvValue(rawContents); + return [basename, updatedContents]; }) ); this.ctx.global.updateEnv({