Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Aspire.slnx
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,7 @@
</Folder>
<Folder Name="/tests/Cli/">
<Project Path="tests/Aspire.Cli.EndToEnd.Tests/Aspire.Cli.EndToEnd.Tests.csproj" />
<Project Path="tests/Aspire.Acquisition.Tests/Aspire.Acquisition.Tests.csproj" />
<Project Path="tests/Aspire.Cli.Tests/Aspire.Cli.Tests.csproj" />
</Folder>
<Folder Name="/tests/Components/">
Expand Down
34 changes: 33 additions & 1 deletion eng/scripts/get-aspire-cli-pr.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,10 @@ param(
[switch]$SkipPath,

[Parameter(HelpMessage = "Keep downloaded archive files after installation")]
[switch]$KeepArchive
[switch]$KeepArchive,

[Parameter(HelpMessage = "Show help information")]
[switch]$Help
)

# Global constants
Expand Down Expand Up @@ -1281,6 +1284,35 @@ function Start-DownloadAndInstall {
# =============================================================================

try {
# Show help if requested
if ($Help) {
Write-Message @"
Aspire CLI PR Download Script

DESCRIPTION:
Downloads and installs the Aspire CLI from a specific pull request's latest successful build.
Automatically detects the current platform and architecture.

Usage:
get-aspire-cli-pr.ps1 <PRNumber> [OPTIONS]
iex "& { `$(irm <url>/get-aspire-cli-pr.ps1) } <PRNumber> [OPTIONS]"

OPTIONS:
-PRNumber <int> Pull request number (required, positional)
-WorkflowRunId <long> Workflow run ID to download from (optional)
-InstallPath <string> Directory prefix to install
-OS <string> Override OS detection (win, linux, linux-musl, osx)
-Architecture <string> Override architecture detection (x64, arm64)
-HiveOnly Only install NuGet packages to the hive, skip CLI download
-SkipExtension Skip VS Code extension download and installation
-UseInsiders Install extension to VS Code Insiders instead of VS Code
-SkipPath Do not add the install path to PATH environment variable
-KeepArchive Keep downloaded archive files after installation
-Help Show this help information
"@ -Level Info
if ($InvokedFromFile) { exit 0 } else { return 0 }
}

# Validate PRNumber is provided when not showing help
if ($PRNumber -le 0) {
Write-Message "Error: PRNumber parameter is required" -Level Error
Expand Down
121 changes: 64 additions & 57 deletions eng/scripts/get-aspire-cli-pr.sh
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,7 @@ add_to_shell_profile() {
esac

# Get the appropriate shell config file
local config_file
local config_file=""

# Find the first existing config file
for file in $config_files; do
Expand Down Expand Up @@ -1054,73 +1054,80 @@ download_and_install_from_pr() {
fi
}

# =============================================================================
# Main Execution
# =============================================================================
# Main entry point — wraps everything after function definitions.
# Guarded so that `source get-aspire-cli-pr.sh` loads functions without
# executing the main flow (enables Tier-1 unit tests).
main() {
# Parse command line arguments
parse_args "$@"

Comment thread
radical marked this conversation as resolved.
# Parse command line arguments
parse_args "$@"

if [[ "$SHOW_HELP" == true ]]; then
show_help
exit 0
fi

HOST_OS=$(detect_os)
if [[ "$SHOW_HELP" == true ]]; then
show_help
exit 0
fi

if [[ "$HOST_OS" == "unsupported" ]]; then
say_error "Unsupported operating system detected: $(uname -s). Supported values: win (Git Bash/MinGW/MSYS), linux, linux-musl, osx. Use --os to override when appropriate."
exit 1
fi
HOST_OS=$(detect_os)

# Check gh dependency
check_gh_dependency
if [[ "$HOST_OS" == "unsupported" ]]; then
say_error "Unsupported operating system detected: $(uname -s). Supported values: win (Git Bash/MinGW/MSYS), linux, linux-musl, osx. Use --os to override when appropriate."
exit 1
fi

# Set default install prefix if not provided
if [[ -z "$INSTALL_PREFIX" ]]; then
INSTALL_PREFIX="$HOME/.aspire"
INSTALL_PREFIX_UNEXPANDED="\$HOME/.aspire"
else
INSTALL_PREFIX_UNEXPANDED="$INSTALL_PREFIX"
fi
# Check gh dependency
check_gh_dependency

# Set paths based on install prefix
cli_install_dir="$INSTALL_PREFIX/bin"
INSTALL_PATH_UNEXPANDED="$INSTALL_PREFIX_UNEXPANDED/bin"
# Set default install prefix if not provided
if [[ -z "$INSTALL_PREFIX" ]]; then
INSTALL_PREFIX="$HOME/.aspire"
INSTALL_PREFIX_UNEXPANDED="\$HOME/.aspire"
else
INSTALL_PREFIX_UNEXPANDED="$INSTALL_PREFIX"
fi

# Create a temporary directory for downloads
if [[ "$DRY_RUN" == true ]]; then
temp_dir="/tmp/aspire-cli-pr-dry-run"
else
temp_dir=$(mktemp -d -t aspire-cli-pr-download-XXXXXX)
say_verbose "Creating temporary directory: $temp_dir"
fi
# Set paths based on install prefix
cli_install_dir="$INSTALL_PREFIX/bin"
INSTALL_PATH_UNEXPANDED="$INSTALL_PREFIX_UNEXPANDED/bin"

# Set trap for cleanup on exit
cleanup() {
remove_temp_dir "$temp_dir"
}
trap cleanup EXIT
# Create a temporary directory for downloads
if [[ "$DRY_RUN" == true ]]; then
temp_dir="/tmp/aspire-cli-pr-dry-run"
else
temp_dir=$(mktemp -d -t aspire-cli-pr-download-XXXXXX)
say_verbose "Creating temporary directory: $temp_dir"
fi

# Download and install from PR or workflow run ID
if ! download_and_install_from_pr "$temp_dir"; then
exit 1
fi
# Set trap for cleanup on exit
cleanup() {
remove_temp_dir "$temp_dir"
}
trap cleanup EXIT

# Add to shell profile for persistent PATH
if [[ "$HIVE_ONLY" != true ]]; then
if [[ "$SKIP_PATH" == true ]]; then
say_info "Skipping PATH configuration due to --skip-path flag"
else
add_to_shell_profile "$cli_install_dir" "$INSTALL_PATH_UNEXPANDED"
# Download and install from PR or workflow run ID
if ! download_and_install_from_pr "$temp_dir"; then
exit 1
fi

# Add to current session PATH, if the path is not already in PATH
if [[ ":$PATH:" != *":$cli_install_dir:"* ]]; then
if [[ "$DRY_RUN" == true ]]; then
say_info "[DRY RUN] Would add $cli_install_dir to PATH"
else
export PATH="$cli_install_dir:$PATH"
# Add to shell profile for persistent PATH
if [[ "$HIVE_ONLY" != true ]]; then
if [[ "$SKIP_PATH" == true ]]; then
say_info "Skipping PATH configuration due to --skip-path flag"
else
add_to_shell_profile "$cli_install_dir" "$INSTALL_PATH_UNEXPANDED"

# Add to current session PATH, if the path is not already in PATH
if [[ ":$PATH:" != *":$cli_install_dir:"* ]]; then
if [[ "$DRY_RUN" == true ]]; then
say_info "[DRY RUN] Would add $cli_install_dir to PATH"
else
export PATH="$cli_install_dir:$PATH"
fi
fi
fi
fi
}

# Only run main when executed directly (not when sourced for unit tests).
# Use ${BASH_SOURCE[0]:-$0} so the guard works under `curl | bash -s` where BASH_SOURCE is unset.
if [[ "${BASH_SOURCE[0]:-$0}" == "${0}" ]]; then
main "$@"
fi
Loading
Loading