Skip to content

Commit

Permalink
Upload fileName with EnvVar create/update commands (#2646)
Browse files Browse the repository at this point in the history
# Why

[ENG-13652: Show filename when value is a file](https://linear.app/expo/issue/ENG-13652/show-filename-when-value-is-a-file)

`eas env:create` and `eas:env:update` should upload fileName, just like website.

# How

* Added `fileName` parameter

# Test Plan

Tested manually
  • Loading branch information
khamilowicz authored Oct 22, 2024
1 parent 214cff0 commit 3a7dfb0
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
8 changes: 7 additions & 1 deletion packages/eas-cli/src/commands/env/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ export default class EnvironmentVariableCreate extends EasCommand {
link,
force,
type,
fileName,
} = await this.promptForMissingFlagsAsync(validatedFlags);

const {
Expand Down Expand Up @@ -167,6 +168,7 @@ export default class EnvironmentVariableCreate extends EasCommand {
visibility,
environments,
type,
fileName,
})
: await EnvironmentVariableMutation.createForAppAsync(
graphqlClient,
Expand All @@ -176,6 +178,7 @@ export default class EnvironmentVariableCreate extends EasCommand {
environments,
visibility,
type: type ?? EnvironmentSecretType.String,
fileName,
},
projectId
);
Expand Down Expand Up @@ -304,7 +307,7 @@ export default class EnvironmentVariableCreate extends EasCommand {
type: EnvironmentSecretType | undefined;
visibility: EnvironmentVariableVisibility;
}
>
> & { fileName?: string }
> {
if (!name) {
name = await promptVariableNameAsync(nonInteractive);
Expand Down Expand Up @@ -336,12 +339,14 @@ export default class EnvironmentVariableCreate extends EasCommand {
}

let environmentFilePath: string | undefined;
let fileName: string | undefined;

if (newType === EnvironmentSecretType.FileBase64) {
environmentFilePath = path.resolve(value);
if (!(await fs.pathExists(environmentFilePath))) {
throw new Error(`File "${value}" does not exist`);
}
fileName = path.basename(environmentFilePath);
}

value = environmentFilePath ? await fs.readFile(environmentFilePath, 'base64') : value;
Expand All @@ -366,6 +371,7 @@ export default class EnvironmentVariableCreate extends EasCommand {
scope: rest.scope ?? EnvironmentVariableScope.Project,
'non-interactive': nonInteractive,
type: newType,
fileName,
...rest,
};
}
Expand Down
11 changes: 7 additions & 4 deletions packages/eas-cli/src/commands/env/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ export default class EnvironmentVariableUpdate extends EasCommand {
environment: newEnvironments,
visibility: newVisibility,
type: newType,
fileName,
} = await this.promptForMissingFlagsAsync(selectedVariable, {
name,
value: rawValue,
Expand All @@ -176,6 +177,7 @@ export default class EnvironmentVariableUpdate extends EasCommand {
environments: newEnvironments,
type: newType,
visibility: newVisibility,
fileName: newValue ? fileName : undefined,
});
if (!variable) {
throw new Error(`Could not update variable with name ${name} ${suffix}`);
Expand Down Expand Up @@ -213,10 +215,12 @@ export default class EnvironmentVariableUpdate extends EasCommand {
Omit<UpdateFlags, 'type' | 'visibility'> & {
type?: EnvironmentSecretType;
visibility?: EnvironmentVariableVisibility;
fileName?: string;
}
> {
let newType;
let newVisibility: EnvironmentVariableVisibility | undefined;
let fileName: string | undefined;

if (type === 'file') {
newType = EnvironmentSecretType.FileBase64;
Expand All @@ -235,10 +239,6 @@ export default class EnvironmentVariableUpdate extends EasCommand {

if (!type && !value && !nonInteractive) {
newType = await promptVariableTypeAsync(nonInteractive, selectedVariable.type);

if (!newType || newType === selectedVariable.type) {
newType = undefined;
}
}

if (!value) {
Expand All @@ -254,6 +254,7 @@ export default class EnvironmentVariableUpdate extends EasCommand {

if (!value || value.length === 0 || value === selectedVariable.value) {
value = undefined;
newType = undefined;
}
}

Expand All @@ -264,6 +265,7 @@ export default class EnvironmentVariableUpdate extends EasCommand {
if (!(await fs.pathExists(environmentFilePath))) {
throw new Error(`File "${value}" does not exist`);
}
fileName = path.basename(environmentFilePath);
}

value = environmentFilePath ? await fs.readFile(environmentFilePath, 'base64') : value;
Expand Down Expand Up @@ -308,6 +310,7 @@ export default class EnvironmentVariableUpdate extends EasCommand {
scope: rest.scope ?? EnvironmentVariableScope.Project,
'non-interactive': nonInteractive,
type: newType,
fileName,
...rest,
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ type CreateVariableArgs = {
visibility: EnvironmentVariableVisibility;
environments: EnvironmentVariableEnvironment[];
type: EnvironmentSecretType;
fileName?: string;
};

export type EnvironmentVariablePushInput = {
Expand Down

0 comments on commit 3a7dfb0

Please sign in to comment.