Skip to content

Commit

Permalink
[eas-cli] Silence all non-command output in non-interactive mode of e…
Browse files Browse the repository at this point in the history
…as env:exec
  • Loading branch information
wschurman committed Jan 7, 2025
1 parent f05d6ca commit 163c212
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 16 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ This is the log of notable changes to EAS CLI and related packages.

### 🎉 New features

- Silence all non-command output in non-interactive mode of eas env:exec. ([#2800](https://github.com/expo/eas-cli/pull/2800) by [@wschurman](https://github.com/wschurman))

### 🐛 Bug fixes

### 🧹 Chores
Expand Down
74 changes: 58 additions & 16 deletions packages/eas-cli/src/commands/env/exec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,10 @@ export default class EnvExec extends EasCommand {
},
];

private isNonInteractive: boolean = false;

async runAsync(): Promise<void> {
const { flags, args } = await this.parse(EnvExec);

const parsedFlags = this.sanitizeFlagsAndArgs(flags, args);

const {
Expand All @@ -65,19 +66,29 @@ export default class EnvExec extends EasCommand {
nonInteractive: parsedFlags.nonInteractive,
});

this.isNonInteractive = parsedFlags.nonInteractive;

const environment =
parsedFlags.environment ??
(await promptVariableEnvironmentAsync({ nonInteractive: parsedFlags.nonInteractive }));
const environmentVariables = await this.loadEnvironmentVariablesAsync({
graphqlClient,
projectId,
environment,
nonInteractive: parsedFlags.nonInteractive,
});

await this.runCommandWithEnvVarsAsync({
command: parsedFlags.command,
environmentVariables,
});
if (parsedFlags.nonInteractive) {
await this.runCommandNonInteractiveWithEnvVarsAsync({
command: parsedFlags.command,
environmentVariables,
});
} else {
await this.runCommandWithEnvVarsAsync({
command: parsedFlags.command,
environmentVariables,
});
}
}

private sanitizeFlagsAndArgs(
Expand All @@ -103,6 +114,33 @@ export default class EnvExec extends EasCommand {
};
}

private async runCommandNonInteractiveWithEnvVarsAsync({
command,
environmentVariables,
}: {
command: string;
environmentVariables: Record<string, string>;
}): Promise<void> {
await spawnAsync('bash', ['-c', command], {
stdio: 'inherit',
env: {
...process.env,
...environmentVariables,
},
});
}

// eslint-disable-next-line async-protect/async-suffix
protected override async catch(err: Error): Promise<any> {
// when in non-interactive, make the behavior of this command a pure passthrough, outputting only the subprocess' stdout and stderr and exiting with the
// sub-command's exit status
if (this.isNonInteractive) {
process.exitCode = process.exitCode ?? (err as any).status ?? 1;
} else {
await super.catch(err);
}
}

private async runCommandWithEnvVarsAsync({
command,
environmentVariables,
Expand Down Expand Up @@ -147,10 +185,12 @@ export default class EnvExec extends EasCommand {
graphqlClient,
projectId,
environment,
nonInteractive,
}: {
graphqlClient: ExpoGraphqlClient;
projectId: string;
environment: EnvironmentVariableEnvironment;
nonInteractive: boolean;
}): Promise<Record<string, string>> {
const environmentVariablesQueryResult =
await EnvironmentVariablesQuery.byAppIdWithSensitiveAsync(graphqlClient, {
Expand All @@ -162,18 +202,20 @@ export default class EnvExec extends EasCommand {
({ value }) => !!value
);

if (nonSecretEnvironmentVariables.length > 0) {
Log.log(
`Environment variables with visibility "Plain text" and "Sensitive" loaded from the "${environment.toLowerCase()}" environment on EAS: ${nonSecretEnvironmentVariables
.map(e => e.name)
.join(', ')}.`
);
} else {
Log.log(
`No environment variables with visibility "Plain text" and "Sensitive" found for the "${environment.toLowerCase()}" environment on EAS.`
);
if (!nonInteractive) {
if (nonSecretEnvironmentVariables.length > 0) {
Log.log(
`Environment variables with visibility "Plain text" and "Sensitive" loaded from the "${environment.toLowerCase()}" environment on EAS: ${nonSecretEnvironmentVariables
.map(e => e.name)
.join(', ')}.`
);
} else {
Log.log(
`No environment variables with visibility "Plain text" and "Sensitive" found for the "${environment.toLowerCase()}" environment on EAS.`
);
}
Log.newLine();
}
Log.newLine();

const environmentVariables: Record<string, string> = {};
for (const { name, value } of nonSecretEnvironmentVariables) {
Expand Down

0 comments on commit 163c212

Please sign in to comment.