Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[build-tools] Log stdout if build:internal fails #459

Merged
merged 1 commit into from
Oct 31, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 39 additions & 26 deletions packages/build-tools/src/common/easBuildInternal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,29 +44,42 @@ export async function runEasBuildInternalAsync<TJob extends BuildJob>({
autoSubmitArgs.push('--auto-submit');
}

const result = await spawn(
cmd,
[
...args,
'build:internal',
'--platform',
job.platform,
'--profile',
buildProfile,
...autoSubmitArgs,
],
{
cwd,
env: {
...env,
EXPO_TOKEN: nullthrows(job.secrets, 'Secrets must be defined for non-custom builds')
.robotAccessToken,
...extraEnv,
},
logger,
mode: PipeMode.STDERR_ONLY_AS_STDOUT,
}
);
let result;
try {
result = await spawn(
cmd,
[
...args,
'build:internal',
'--platform',
job.platform,
'--profile',
buildProfile,
...autoSubmitArgs,
],
{
cwd,
env: {
...env,
EXPO_TOKEN: nullthrows(job.secrets, 'Secrets must be defined for non-custom builds')
.robotAccessToken,
...extraEnv,
},
logger,
mode: PipeMode.STDERR_ONLY_AS_STDOUT,
}
);
} catch (err: any) {
// Logging of build:internal is weird. We set mode = STDERR_ONLY_AS_STDOUT,
// because we don't want to pipe stdout to to the logger as it will contain
// the job object with its secrets. However, if the build fails, stderr alone
// is often not enough to debug the issue, so we also log stdout in those cases.
// It will look awkward (first stderr from pipe, then stdout from here), but
// it's better than nothing.
logger.error(`${err.stdout}`);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume that printing job object with it's secrets is the last operation performed by this command, right? If so if there is any error there shouldn't be any secrets in stdout?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not last per se, but it's close to last. After we print the job we may also start a submission (which theoretically may fail).

Maybe we should revert this after we find the issue with the orchestrator?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, we can if it contains any sensitive data and there is a risk of leaking it 🤔

throw err;
}

const stdout = result.stdout.toString();
const parsed = JSON.parse(stdout);
return validateEasBuildInternalResult({
Expand Down Expand Up @@ -121,9 +134,9 @@ async function resolveEasCommandPrefixAndEnvAsync(): Promise<{
const npxArgsPrefix = (await isAtLeastNpm7Async()) ? ['-y'] : [];
if (process.env.ENVIRONMENT === 'development') {
return {
cmd: process.env.EAS_BUILD_INTERNAL_EXECUTABLE ?? `eas`,
args: [],
extraEnv: { EXPO_LOCAL: '1' },
cmd: 'npx',
args: [...npxArgsPrefix, `eas-cli@${EAS_CLI_STAGING_NPM_TAG}`],
extraEnv: {},
};
} else if (process.env.ENVIRONMENT === 'staging') {
return {
Expand Down
Loading