Skip to content

Commit

Permalink
Support File type environment variables
Browse files Browse the repository at this point in the history
  • Loading branch information
khamilowicz committed Aug 21, 2024
1 parent 75b310e commit c9cb3bd
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 15 deletions.
59 changes: 47 additions & 12 deletions packages/eas-cli/graphql.schema.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 25 additions & 2 deletions packages/eas-cli/src/commands/env/create.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import { Flags } from '@oclif/core';
import assert from 'assert';
import chalk from 'chalk';
import fs from 'fs-extra';
import path from 'path';

import EasCommand from '../../commandUtils/EasCommand';
import {
Expand All @@ -11,6 +14,7 @@ import {
import {
EnvironmentVariableEnvironment,
EnvironmentVariableScope,
EnvironmentVariableType,
EnvironmentVariableVisibility,
} from '../../graphql/generated';
import { EnvironmentVariableMutation } from '../../graphql/mutations/EnvironmentVariableMutation';
Expand All @@ -32,6 +36,7 @@ type CreateFlags = {
value?: string;
link?: boolean;
force?: boolean;
type?: EnvironmentVariableType;
visibility?: EnvironmentVariableVisibility;
scope?: EnvironmentVariableScope;
environment?: EnvironmentVariableEnvironment;
Expand All @@ -58,6 +63,11 @@ export default class EnvironmentVariableCreate extends EasCommand {
description: 'Overwrite existing variable',
default: false,
}),
type: Flags.enum({
description: 'The type of variable',
options: [EnvironmentVariableType.String, EnvironmentVariableType.File],
default: EnvironmentVariableType.String,
}),
...EASVariableVisibilityFlag,
...EASVariableScopeFlag,
...EASEnvironmentFlag,
Expand All @@ -82,6 +92,7 @@ export default class EnvironmentVariableCreate extends EasCommand {
visibility,
link,
force,
type,
} = this.validateFlags(flags);

const {
Expand Down Expand Up @@ -110,6 +121,15 @@ export default class EnvironmentVariableCreate extends EasCommand {
});
}

let environmentFilePath: string | undefined;
if (type === EnvironmentVariableType.File) {
environmentFilePath = path.resolve(value);
if (!(await fs.pathExists(environmentFilePath))) {
throw new Error(`File "${value}" does not exist`);
}
value = await fs.readFile(environmentFilePath, 'base64');
}

if (scope === EnvironmentVariableScope.Project) {
if (!environment) {
environment = await promptVariableEnvironmentAsync(nonInteractive);
Expand Down Expand Up @@ -178,6 +198,7 @@ export default class EnvironmentVariableCreate extends EasCommand {
environment,
visibility,
overwrite,
type,
},
projectId
);
Expand Down Expand Up @@ -221,6 +242,7 @@ export default class EnvironmentVariableCreate extends EasCommand {
name,
value,
visibility,
type,
},
ownerAccount.id
);
Expand Down Expand Up @@ -254,12 +276,13 @@ export default class EnvironmentVariableCreate extends EasCommand {
}
}

private validateFlags(flags: CreateFlags): CreateFlags {
private validateFlags(flags: CreateFlags): CreateFlags & { type: EnvironmentVariableType } {
if (flags.scope !== EnvironmentVariableScope.Shared && flags.link) {
throw new Error(
`Unexpected argument: --link can only be used when creating shared variables`
);
}
assert(flags.type, 'type is required');
if (
flags.scope === EnvironmentVariableScope.Shared &&
flags.environment &&
Expand All @@ -270,6 +293,6 @@ export default class EnvironmentVariableCreate extends EasCommand {
'Unexpected argument: --environment in non-interactive mode can only be used with --link flag.'
);
}
return flags;
return { ...flags, type: flags.type };
}
}
8 changes: 7 additions & 1 deletion packages/eas-cli/src/graphql/generated.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
CreateEnvironmentVariableForAppMutation,
DeleteEnvironmentVariableMutation,
EnvironmentVariableFragment,
EnvironmentVariableType,
EnvironmentVariableVisibility,
LinkSharedEnvironmentVariableMutation,
UnlinkSharedEnvironmentVariableMutation,
Expand Down Expand Up @@ -108,6 +109,7 @@ export const EnvironmentVariableMutation = {
value: string;
visibility: EnvironmentVariableVisibility;
overwrite?: boolean;
type: EnvironmentVariableType;
}
| UpdateVariableArgs,
accountId: string
Expand Down Expand Up @@ -148,6 +150,7 @@ export const EnvironmentVariableMutation = {
environment: string;
visibility: EnvironmentVariableVisibility;
overwrite?: boolean;
type: EnvironmentVariableType;
}
| (UpdateVariableArgs & { environment: string }),
appId: string
Expand Down

0 comments on commit c9cb3bd

Please sign in to comment.