Skip to content

Commit

Permalink
fix(globe_cli): Bad state no element error on deployment fixed (#8)
Browse files Browse the repository at this point in the history
* fix: Bad state no element error on deployment fixed

* fix: typo deployProgess to deployProgress

* fix: add invalid status and status check for DeploymentEnvironment and DeploymentState

* chore: added archiver to wordlist
  • Loading branch information
kaziwaseef authored Dec 13, 2023
1 parent 6945cfa commit 6856942
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 10 deletions.
3 changes: 2 additions & 1 deletion .github/.cspell/words_dictionary.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
# Actual english words (or common abbreviations) missing from CSpell
upvote
upvote
archiver
18 changes: 13 additions & 5 deletions packages/globe_cli/lib/src/commands/deploy_command.dart
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class DeployCommand extends BaseGlobeCommand {

final validated = await scope.validate();

final deployProgess = logger.progress(
final deployProgress = logger.progress(
'Deploying to ${styleBold.wrap('${validated.organization.slug}/${validated.project.slug}')}${environment == DeploymentEnvironment.production ? ' (production)' : ''}',
);

Expand All @@ -63,7 +63,7 @@ class DeployCommand extends BaseGlobeCommand {
archive: archive,
);

deployProgess.complete();
deployProgress.complete();

logger.success(
'${lightGreen.wrap('✓')} Deployment has been queued',
Expand All @@ -85,7 +85,8 @@ class DeployCommand extends BaseGlobeCommand {
deploymentId: deployment.id,
);

if (update.state == DeploymentState.working) {
if (update.state == DeploymentState.working ||
update.state == DeploymentState.deploying) {
if (logs != null) return;

status.complete();
Expand Down Expand Up @@ -136,6 +137,13 @@ class DeployCommand extends BaseGlobeCommand {
logger.info('Deployment cancelled');
}

if (update.state == DeploymentState.invalid) {
status.complete();
status = logger.progress(
'Invalid Deployment State Received. Waiting for valid state',
);
}

if (update.state == DeploymentState.success ||
update.state == DeploymentState.cancelled ||
update.state == DeploymentState.error) {
Expand All @@ -148,11 +156,11 @@ class DeployCommand extends BaseGlobeCommand {

return ExitCode.success.code;
} on ApiException catch (e) {
deployProgess.fail();
deployProgress.fail();
logger.err('✗ Failed to deploy project: ${e.message}');
return ExitCode.software.code;
} catch (e, s) {
deployProgess.fail();
deployProgress.fail();
logger
..err('✗ Failed to deploy project: $e')
..err(s.toString());
Expand Down
14 changes: 11 additions & 3 deletions packages/globe_cli/lib/src/utils/api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -436,9 +436,13 @@ class Deployment {
projectId: projectId,
environment: DeploymentEnvironment.values.firstWhere(
(e) => e.name == environment,
orElse: () => DeploymentEnvironment.invalid,
),
status: status,
state: DeploymentState.values.firstWhere((e) => e.name == state),
state: DeploymentState.values.firstWhere(
(e) => e.name == state,
orElse: () => DeploymentState.invalid,
),
message: message ?? '',
url: url,
hash: hash,
Expand Down Expand Up @@ -466,9 +470,12 @@ class Deployment {
enum DeploymentState {
pending('Queued'),
working('In progress'),
deploying('Deploying'),
success('Deployment successful'),
error('Deployment failed'),
cancelled('Deployment cancelled');
cancelled('Deployment cancelled'),
// state is not a valid state, but is used to represent an invalid state.
invalid('Invalid');

const DeploymentState(this.message);

Expand Down Expand Up @@ -518,7 +525,8 @@ class FrameworkPresetOptions {

enum DeploymentEnvironment {
preview,
production;
production,
invalid;
}

enum Role {
Expand Down
2 changes: 1 addition & 1 deletion packages/globe_cli/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ packages:
path: "../globe_lints"
relative: true
source: path
version: "1.0.0"
version: "1.0.1"
graphs:
dependency: transitive
description:
Expand Down

0 comments on commit 6856942

Please sign in to comment.