From a404bb383d86cc52327cd6d20dbe7ee071587073 Mon Sep 17 00:00:00 2001 From: Cedric van Putten Date: Thu, 12 Sep 2024 11:43:01 +0100 Subject: [PATCH] feature(eas-cli): add `worker --alias` flag (#2551) * feature(eas-cli): add `worker --alias` flag * docs: add changelog entry * fix(eas-cli): add missing `ora.start` Co-authored-by: Szymon Dziedzic --------- Co-authored-by: Szymon Dziedzic --- CHANGELOG.md | 1 + .../eas-cli/src/commands/worker/deploy.ts | 23 +++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index d46a4ae802..a9d7f183c8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ This is the log of notable changes to EAS CLI and related packages. - Add `worker:alias` command to assign aliases from the CLI. ([#2548](https://github.com/expo/eas-cli/pull/2548) by [@byCedric](https://github.com/byCedric)) - 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))) ### 🐛 Bug fixes diff --git a/packages/eas-cli/src/commands/worker/deploy.ts b/packages/eas-cli/src/commands/worker/deploy.ts index 8579329a3f..c87490f14f 100644 --- a/packages/eas-cli/src/commands/worker/deploy.ts +++ b/packages/eas-cli/src/commands/worker/deploy.ts @@ -10,6 +10,7 @@ import { ora } from '../../ora'; import { createProgressTracker } from '../../utils/progress'; import * as WorkerAssets from '../../worker/assets'; import { + assignWorkerDeploymentAliasAsync, assignWorkerDeploymentProductionAsync, getSignedDeploymentUrlAsync, } from '../../worker/deployment'; @@ -25,12 +26,14 @@ interface DeployFlags { nonInteractive: boolean; json: boolean; prod: boolean; + aliasName?: string; } interface RawDeployFlags { 'non-interactive': boolean; json: boolean; prod: boolean; + alias?: string; } export default class WorkerDeploy extends EasCommand { @@ -42,6 +45,9 @@ export default class WorkerDeploy extends EasCommand { static override state = 'beta'; static override flags = { + alias: Flags.string({ + description: 'Custom alias for the deployment', + }), prod: Flags.boolean({ description: 'Deploy to production', default: false, @@ -227,6 +233,22 @@ export default class WorkerDeploy extends EasCommand { await uploadAssetsAsync(assetMap, deployResult.uploads); + if (flags.aliasName) { + progress = ora(chalk`Assigning alias {bold ${flags.aliasName}} to worker deployment`).start(); + try { + await assignWorkerDeploymentAliasAsync({ + graphqlClient, + appId: projectId, + deploymentId: deployResult.id, + aliasName: flags.aliasName, + }); + progress.succeed(chalk`Assigned alias {bold ${flags.aliasName}} to worker deployment`); + } catch (error: any) { + progress.fail(chalk`Failed to assign {bold ${flags.aliasName}} alias to worker deployment`); + throw error; + } + } + const expoBaseDomain = process.env.EXPO_STAGING ? 'staging.expo' : 'expo'; const dashboardUrl = `https://${expoBaseDomain}.dev/projects/${projectId}/serverless/deployments`; @@ -265,6 +287,7 @@ export default class WorkerDeploy extends EasCommand { nonInteractive: flags['non-interactive'], json: flags['json'], prod: !!flags.prod, + aliasName: flags.alias?.trim().toLowerCase(), }; } }