Skip to content

Commit

Permalink
[eas-cli] Add --environment argument to worker:deploy (#2557)
Browse files Browse the repository at this point in the history
* Add `--environment` argument to worker:deploy

* Add to changelog

* Apply lints
  • Loading branch information
kitten authored Sep 13, 2024
1 parent 2fb079d commit 5c553ce
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ This is the log of notable changes to EAS CLI and related packages.
- Add `worker --prod` flag to deploy to production from the CLI. ([#2550](https://github.com/expo/eas-cli/pull/2550) by [@byCedric](https://github.com/byCedric))
- Add `worker --alias` flag to assign custom aliases when deploying. ([#2551](https://github.com/expo/eas-cli/pull/2551) by [@byCedric](https://github.com/byCedric)))
- Add `worker --id` flag to use a custom deployment identifier. ([#2552](https://github.com/expo/eas-cli/pull/2552) by [@byCedric](https://github.com/byCedric)))
- Add `worker --environment` flag to deploy with EAS environment variables. ([#2557](https://github.com/expo/eas-cli/pull/2557) by [@kitten](https://github.com/kitten)))

### 🐛 Bug fixes

Expand Down
15 changes: 13 additions & 2 deletions packages/eas-cli/src/commands/worker/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import fs from 'node:fs';
import * as path from 'node:path';

import EasCommand from '../../commandUtils/EasCommand';
import { EasNonInteractiveAndJsonFlags } from '../../commandUtils/flags';
import { EASEnvironmentFlag, EasNonInteractiveAndJsonFlags } from '../../commandUtils/flags';
import { EnvironmentVariableEnvironment } from '../../graphql/generated';
import Log from '../../log';
import { ora } from '../../ora';
import formatFields, { FormatFieldsItem } from '../../utils/formatFields';
Expand All @@ -28,11 +29,13 @@ interface DeployFlags {
json: boolean;
isProduction: boolean;
aliasName?: string;
environment?: EnvironmentVariableEnvironment;
deploymentIdentifier?: string;
}

interface RawDeployFlags {
'non-interactive': boolean;
environment?: string;
json: boolean;
prod: boolean;
alias?: string;
Expand Down Expand Up @@ -64,6 +67,7 @@ export default class WorkerDeploy extends EasCommand {
}),
// TODO(@kitten): Allow deployment identifier to be specified
...EasNonInteractiveAndJsonFlags,
...EASEnvironmentFlag,
};

static override contextDefinition = {
Expand Down Expand Up @@ -222,8 +226,15 @@ export default class WorkerDeploy extends EasCommand {
let progress = ora('Preparing project').start();

try {
const manifest = await WorkerAssets.createManifestAsync(
{
environment: flags.environment,
projectDir,
projectId,
},
graphqlClient
);
assetMap = await WorkerAssets.createAssetMapAsync(distClientPath);
const manifest = await WorkerAssets.createManifestAsync(projectDir);
tarPath = await WorkerAssets.packFilesIterableAsync(
emitWorkerTarballAsync({
assetMap,
Expand Down
31 changes: 29 additions & 2 deletions packages/eas-cli/src/worker/assets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ import path from 'node:path';
import { pipeline } from 'node:stream/promises';
import { pack } from 'tar-stream';

import { ExpoGraphqlClient } from '../commandUtils/context/contextUtils/createGraphqlClient';
import { EnvironmentVariableEnvironment } from '../graphql/generated';
import { EnvironmentVariablesQuery } from '../graphql/queries/EnvironmentVariablesQuery';

/** Returns whether a file or folder is ignored */
function isIgnoredName(name: string): boolean {
switch (name) {
Expand Down Expand Up @@ -92,9 +96,32 @@ export interface Manifest {
env: Record<string, string | undefined>;
}

interface CreateManifestParams {
projectId: string;
projectDir: string;
environment?: EnvironmentVariableEnvironment;
}

/** Creates a manifest configuration sent up for deployment */
export async function createManifestAsync(projectDir: string): Promise<Manifest> {
const { env } = getEnv(projectDir);
export async function createManifestAsync(
params: CreateManifestParams,
graphqlClient: ExpoGraphqlClient
): Promise<Manifest> {
let env: Record<string, string | undefined>;
if (params.environment) {
env = Object.fromEntries(
(
await EnvironmentVariablesQuery.byAppIdWithSensitiveAsync(graphqlClient, {
appId: params.projectId,
environment: params.environment,
})
).map(variable => [variable.name, variable.value ?? undefined])
);
} else {
// NOTE: This is required for the .env resolution
process.env.NODE_ENV = 'production';
env = getEnv(params.projectDir).env;
}
return { env };
}

Expand Down

0 comments on commit 5c553ce

Please sign in to comment.