Skip to content

Commit 7d68940

Browse files
Copilotdavidfowlmitchdennyradical
authored
Update CLI download scripts to set global channel on install (dotnet#13504)
* Initial plan * Update CLI download scripts to set global channel on install Added functionality to save the selected channel to globalsettings.json when installing the Aspire CLI using quality-based downloads. - Added map_quality_to_channel function to bash script to convert quality (release/staging/dev) to channel name (stable/staging/daily) - Added save_global_channel_setting function to bash script to write the channel to ~/.aspire/globalsettings.json - Added ConvertTo-ChannelName function to PowerShell script - Added Save-GlobalChannelSetting function to PowerShell script - Both scripts now save the channel setting after successful installation (only when using quality-based downloads, not when specifying version) Co-authored-by: davidfowl <95136+davidfowl@users.noreply.github.com> * Simplify home directory detection in Save-GlobalChannelSetting Remove redundant $IsWindows check as $env:USERPROFILE fallback handles all cases. Co-authored-by: davidfowl <95136+davidfowl@users.noreply.github.com> * Add channel setting to get-aspire-cli-pr scripts - Added save_global_channel_setting function to get-aspire-cli-pr.sh - Added Save-GlobalChannelSetting function to get-aspire-cli-pr.ps1 - Both PR scripts now save channel as 'pr-<PR_NUMBER>' after install - Fixed PowerShell 5.1 compatibility for ConvertFrom-Json -AsHashtable - Added verbose logging when jq fails to parse settings file Co-authored-by: davidfowl <95136+davidfowl@users.noreply.github.com> * Remove channel key for release/stable builds instead of setting it When installing the release/stable channel, instead of setting the channel to "stable", the channel key is now removed from the config file entirely. This prevents the creation of a nuget.config file. - Added remove_global_channel_setting function to get-aspire-cli.sh - Added Remove-GlobalChannelSetting function to get-aspire-cli.ps1 - Updated logic to remove channel for stable, save for other channels Co-authored-by: mitchdenny <513398+mitchdenny@users.noreply.github.com> * Refactor global settings to use aspire config CLI commands - Renamed save_global_channel_setting to save_global_settings - Renamed Save-GlobalChannelSetting to Save-GlobalSettings - Renamed remove_global_channel_setting to remove_global_settings - Renamed Remove-GlobalChannelSetting to Remove-GlobalSettings - Now uses 'aspire config set -g key value' and 'aspire config unset -g key' - Added fallback to direct file edit if CLI commands fail - Added expected schema comments to all functions Co-authored-by: radical <95136+radical@users.noreply.github.com> * Remove fallback to direct file editing for global config Removed the fallback logic that would directly edit the globalsettings.json file when CLI commands fail. Now the scripts only use `aspire config set -g` and `aspire config unset -g` commands without any fallback. Co-authored-by: davidfowl <95136+davidfowl@users.noreply.github.com> * Change 'aspire config unset' to 'aspire config delete' Fixed the command to use the correct 'aspire config delete -g' command instead of the non-existent 'aspire config unset -g'. Co-authored-by: mitchdenny <513398+mitchdenny@users.noreply.github.com> * Suppress command output and use Verbose level for errors - Changed `$output = ...` to `$null = ...` to suppress command output - Changed error messages from Warning to Verbose level - Applied to both get-aspire-cli.ps1 and get-aspire-cli-pr.ps1 Co-authored-by: radical <1472+radical@users.noreply.github.com> * Fix output handling: keep output/warnings for set, verbose for delete - Revert get-aspire-cli.ps1 Save-GlobalSettings to keep output and use Warning - Revert get-aspire-cli-pr.ps1 Save-GlobalSettings to keep output and use Warning - Update get-aspire-cli.ps1 Remove-GlobalSettings to log output at Verbose level - Update get-aspire-cli.sh remove_global_settings to log output at verbose level Co-authored-by: radical <1472+radical@users.noreply.github.com> * Improve output handling for Save-GlobalSettings - On success: log output at Verbose level - On failure: include output in the warning message - Applied to both get-aspire-cli.ps1 and get-aspire-cli.sh Co-authored-by: radical <1472+radical@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: davidfowl <95136+davidfowl@users.noreply.github.com> Co-authored-by: mitchdenny <513398+mitchdenny@users.noreply.github.com> Co-authored-by: radical <95136+radical@users.noreply.github.com> Co-authored-by: radical <1472+radical@users.noreply.github.com>
1 parent 259bbee commit 7d68940

File tree

4 files changed

+277
-3
lines changed

4 files changed

+277
-3
lines changed

eng/scripts/get-aspire-cli-pr.ps1

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -590,6 +590,37 @@ function Remove-TempDirectory {
590590
# END: Shared code
591591
# =============================================================================
592592

593+
# Function to save global settings using the aspire CLI
594+
# Uses 'aspire config set -g' to set global configuration values
595+
# Expected schema of ~/.aspire/globalsettings.json:
596+
# {
597+
# "channel": "string" // The channel name (e.g., "daily", "staging", "pr-1234")
598+
# }
599+
function Save-GlobalSettings {
600+
[CmdletBinding(SupportsShouldProcess)]
601+
param(
602+
[Parameter(Mandatory = $true)]
603+
[string]$CliPath,
604+
605+
[Parameter(Mandatory = $true)]
606+
[string]$Key,
607+
608+
[Parameter(Mandatory = $true)]
609+
[string]$Value
610+
)
611+
612+
if ($PSCmdlet.ShouldProcess("$Key = $Value", "Set global config via aspire CLI")) {
613+
Write-Message "Setting global config: $Key = $Value" -Level Verbose
614+
615+
$output = & $CliPath config set -g $Key $Value 2>&1
616+
if ($LASTEXITCODE -ne 0) {
617+
Write-Message "Failed to set global config via aspire CLI" -Level Warning
618+
return
619+
}
620+
Write-Message "Global config saved: $Key = $Value" -Level Verbose
621+
}
622+
}
623+
593624
# Function to check if gh command is available
594625
function Test-GitHubCLIDependency {
595626
[CmdletBinding()]
@@ -1096,6 +1127,15 @@ function Start-DownloadAndInstall {
10961127
}
10971128
}
10981129

1130+
# Save the global channel setting to the PR hive channel
1131+
# This allows 'aspire new' and 'aspire init' to use the same channel by default
1132+
if (-not $HiveOnly) {
1133+
# Determine CLI path
1134+
$cliExe = if ($Script:HostOS -eq "win") { "aspire.exe" } else { "aspire" }
1135+
$cliPath = Join-Path $cliBinDir $cliExe
1136+
Save-GlobalSettings -CliPath $cliPath -Key "channel" -Value "pr-$PRNumber"
1137+
}
1138+
10991139
# Update PATH environment variables
11001140
if (-not $HiveOnly) {
11011141
if ($SkipPath) {

eng/scripts/get-aspire-cli-pr.sh

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,36 @@ install_archive() {
408408
say_verbose "Successfully installed archive"
409409
}
410410

411+
# Function to save global settings using the aspire CLI
412+
# Uses 'aspire config set -g' to set global configuration values
413+
# Parameters:
414+
# $1 - cli_path: Path to the aspire CLI executable
415+
# $2 - key: The configuration key to set
416+
# $3 - value: The value to set
417+
# Expected schema of ~/.aspire/globalsettings.json:
418+
# {
419+
# "channel": "string" // The channel name (e.g., "daily", "staging", "pr-1234")
420+
# }
421+
save_global_settings() {
422+
local cli_path="$1"
423+
local key="$2"
424+
local value="$3"
425+
426+
if [[ "$DRY_RUN" == true ]]; then
427+
say_info "[DRY RUN] Would run: $cli_path config set -g $key $value"
428+
return 0
429+
fi
430+
431+
say_verbose "Setting global config: $key = $value"
432+
433+
if ! "$cli_path" config set -g "$key" "$value" 2>/dev/null; then
434+
say_warn "Failed to set global config via aspire CLI"
435+
return 1
436+
fi
437+
438+
say_verbose "Global config saved: $key = $value"
439+
}
440+
411441
# Function to add PATH to shell configuration file
412442
# Parameters:
413443
# $1 - config_file: Path to the shell configuration file
@@ -1008,6 +1038,19 @@ download_and_install_from_pr() {
10081038
install_aspire_extension "$extension_download_dir"
10091039
fi
10101040
fi
1041+
1042+
# Save the global channel setting to the PR hive channel
1043+
# This allows 'aspire new' and 'aspire init' to use the same channel by default
1044+
if [[ "$HIVE_ONLY" != true ]]; then
1045+
# Determine CLI path
1046+
local cli_path
1047+
if [[ -f "$cli_install_dir/aspire.exe" ]]; then
1048+
cli_path="$cli_install_dir/aspire.exe"
1049+
else
1050+
cli_path="$cli_install_dir/aspire"
1051+
fi
1052+
save_global_settings "$cli_path" "channel" "pr-$PR_NUMBER"
1053+
fi
10111054
}
10121055

10131056
# =============================================================================

eng/scripts/get-aspire-cli.ps1

Lines changed: 93 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -602,6 +602,82 @@ function Expand-AspireCliArchive {
602602
}
603603
}
604604

605+
# Function to map quality to channel name
606+
function ConvertTo-ChannelName {
607+
[CmdletBinding()]
608+
[OutputType([string])]
609+
param(
610+
[Parameter(Mandatory = $true)]
611+
[string]$Quality
612+
)
613+
614+
switch ($Quality.ToLowerInvariant()) {
615+
"release" { return "stable" }
616+
"staging" { return "staging" }
617+
"dev" { return "daily" }
618+
default { return $Quality }
619+
}
620+
}
621+
622+
# Function to save global settings using the aspire CLI
623+
# Uses 'aspire config set -g' to set global configuration values
624+
# Expected schema of ~/.aspire/globalsettings.json:
625+
# {
626+
# "channel": "string" // The channel name (e.g., "daily", "staging", "pr-1234")
627+
# }
628+
function Save-GlobalSettings {
629+
[CmdletBinding(SupportsShouldProcess)]
630+
param(
631+
[Parameter(Mandatory = $true)]
632+
[string]$CliPath,
633+
634+
[Parameter(Mandatory = $true)]
635+
[string]$Key,
636+
637+
[Parameter(Mandatory = $true)]
638+
[string]$Value
639+
)
640+
641+
if ($PSCmdlet.ShouldProcess("$Key = $Value", "Set global config via aspire CLI")) {
642+
Write-Message "Setting global config: $Key = $Value" -Level Verbose
643+
644+
$output = & $CliPath config set -g $Key $Value 2>&1
645+
if ($LASTEXITCODE -ne 0) {
646+
Write-Message "Failed to set global config via aspire CLI: $output" -Level Warning
647+
return
648+
}
649+
if ($output) {
650+
Write-Message "$output" -Level Verbose
651+
}
652+
Write-Message "Global config saved: $Key = $Value" -Level Verbose
653+
}
654+
}
655+
656+
# Function to remove a global setting using the aspire CLI
657+
# Uses 'aspire config delete -g' to remove global configuration values
658+
# This is used when installing the release/stable channel to avoid forcing nuget.config creation
659+
function Remove-GlobalSettings {
660+
[CmdletBinding(SupportsShouldProcess)]
661+
param(
662+
[Parameter(Mandatory = $true)]
663+
[string]$CliPath,
664+
665+
[Parameter(Mandatory = $true)]
666+
[string]$Key
667+
)
668+
669+
if ($PSCmdlet.ShouldProcess($Key, "Remove global config via aspire CLI")) {
670+
Write-Message "Removing global config: $Key" -Level Verbose
671+
672+
$output = & $CliPath config delete -g $Key 2>&1
673+
if ($LASTEXITCODE -ne 0) {
674+
Write-Message "Failed to delete global config via aspire CLI: $output" -Level Verbose
675+
return
676+
}
677+
Write-Message "Global config removed: $Key" -Level Verbose
678+
}
679+
}
680+
605681
# Simplified installation path determination
606682
function Get-InstallPath {
607683
[CmdletBinding()]
@@ -972,16 +1048,30 @@ function Install-AspireCli {
9721048
Write-Message "Successfully downloaded and validated: $($urls.ArchiveFilename)" -Level Verbose
9731049
}
9741050

1051+
# Determine CLI path (needed for config operations)
1052+
$cliExe = if ($targetOS -eq "win") { "aspire.exe" } else { "aspire" }
1053+
$cliPath = Join-Path $InstallPath $cliExe
1054+
9751055
if ($PSCmdlet.ShouldProcess($InstallPath, "Install CLI")) {
9761056
# Unpack the archive
9771057
Expand-AspireCliArchive -ArchiveFile $archivePath -DestinationPath $InstallPath -OS $targetOS
9781058

979-
$cliExe = if ($targetOS -eq "win") { "aspire.exe" } else { "aspire" }
980-
$cliPath = Join-Path $InstallPath $cliExe
981-
9821059
Write-Message "Aspire CLI successfully installed to: $cliPath" -Level Success
9831060
}
9841061

1062+
# Save the global channel setting if using quality-based download (not version-specific)
1063+
# This allows 'aspire new' and 'aspire init' to use the same channel by default
1064+
# For release/stable channel, remove the setting to avoid forcing nuget.config creation
1065+
if ([string]::IsNullOrWhiteSpace($Version)) {
1066+
$channel = ConvertTo-ChannelName -Quality $Quality
1067+
if ($channel -eq "stable") {
1068+
Remove-GlobalSettings -CliPath $cliPath -Key "channel"
1069+
}
1070+
else {
1071+
Save-GlobalSettings -CliPath $cliPath -Key "channel" -Value $channel
1072+
}
1073+
}
1074+
9851075
# Download and install VS Code extension if requested
9861076
if ($InstallExtension) {
9871077
Write-Message "" -Level Info

eng/scripts/get-aspire-cli.sh

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -454,6 +454,94 @@ install_archive() {
454454
say_verbose "Successfully installed archive"
455455
}
456456

457+
# Function to map quality to channel name
458+
# Parameters:
459+
# $1 - quality: The quality string (release, staging, dev)
460+
# Returns: The corresponding channel name (stable, staging, daily)
461+
map_quality_to_channel() {
462+
local quality="$1"
463+
464+
case "$quality" in
465+
release)
466+
printf "stable"
467+
;;
468+
staging)
469+
printf "staging"
470+
;;
471+
dev)
472+
printf "daily"
473+
;;
474+
*)
475+
# Unknown quality, return as-is
476+
printf "%s" "$quality"
477+
;;
478+
esac
479+
}
480+
481+
# Function to save the global settings using the aspire CLI
482+
# Uses 'aspire config set -g' to set global configuration values
483+
# Parameters:
484+
# $1 - cli_path: Path to the aspire CLI executable
485+
# $2 - key: The configuration key to set
486+
# $3 - value: The value to set
487+
# Expected schema of ~/.aspire/globalsettings.json:
488+
# {
489+
# "channel": "string" // The channel name (e.g., "daily", "staging", "pr-1234")
490+
# }
491+
save_global_settings() {
492+
local cli_path="$1"
493+
local key="$2"
494+
local value="$3"
495+
496+
if [[ "$DRY_RUN" == true ]]; then
497+
say_info "[DRY RUN] Would run: $cli_path config set -g $key $value"
498+
return 0
499+
fi
500+
501+
say_verbose "Setting global config: $key = $value"
502+
503+
local output
504+
output=$("$cli_path" config set -g "$key" "$value" 2>&1)
505+
local exit_code=$?
506+
if [[ $exit_code -ne 0 ]]; then
507+
say_warn "Failed to set global config via aspire CLI: $output"
508+
return 1
509+
fi
510+
if [[ -n "$output" ]]; then
511+
say_verbose "$output"
512+
fi
513+
514+
say_verbose "Global config saved: $key = $value"
515+
}
516+
517+
# Function to remove a global setting using the aspire CLI
518+
# Uses 'aspire config delete -g' to remove global configuration values
519+
# This is used when installing the release/stable channel to avoid forcing nuget.config creation
520+
# Parameters:
521+
# $1 - cli_path: Path to the aspire CLI executable
522+
# $2 - key: The configuration key to remove
523+
remove_global_settings() {
524+
local cli_path="$1"
525+
local key="$2"
526+
527+
if [[ "$DRY_RUN" == true ]]; then
528+
say_info "[DRY RUN] Would run: $cli_path config delete -g $key"
529+
return 0
530+
fi
531+
532+
say_verbose "Removing global config: $key"
533+
534+
local output
535+
output=$("$cli_path" config delete -g "$key" 2>&1)
536+
local exit_code=$?
537+
if [[ $exit_code -ne 0 ]]; then
538+
say_verbose "Failed to delete global config via aspire CLI: $output"
539+
return 1
540+
fi
541+
542+
say_verbose "Global config removed: $key"
543+
}
544+
457545
# Function to add PATH to shell configuration file
458546
# Parameters:
459547
# $1 - config_file: Path to the shell configuration file
@@ -908,6 +996,19 @@ download_and_install_archive() {
908996

909997
say_info "Aspire CLI successfully installed to: ${GREEN}$cli_path${RESET}"
910998

999+
# Save the global channel setting if using quality-based download (not version-specific)
1000+
# This allows 'aspire new' and 'aspire init' to use the same channel by default
1001+
# For release/stable channel, remove the setting to avoid forcing nuget.config creation
1002+
if [[ -z "$VERSION" ]]; then
1003+
local channel
1004+
channel=$(map_quality_to_channel "$QUALITY")
1005+
if [[ "$channel" == "stable" ]]; then
1006+
remove_global_settings "$cli_path" "channel"
1007+
else
1008+
save_global_settings "$cli_path" "channel" "$channel"
1009+
fi
1010+
fi
1011+
9111012
# Download and install VS Code extension if requested
9121013
if [[ "$INSTALL_EXTENSION" == true ]]; then
9131014
printf "\n"

0 commit comments

Comments
 (0)