From 7ce7863dfec83e7fd4f76d3b81a74a9ece5261bd Mon Sep 17 00:00:00 2001 From: Shiwei Zhang Date: Wed, 17 Jun 2026 11:07:38 +0800 Subject: [PATCH] Support --prerelease in install scripts Add an opt-in --prerelease (install.sh) / -Prerelease (install.ps1) flag that installs the newest release overall, including prereleases, by resolving the version from the GitHub releases list endpoint instead of releases/latest. Default behavior is unchanged. Also documents the option in README.md and specs/install.md. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- README.md | 8 ++++++++ scripts/install.ps1 | 20 ++++++++++++++++---- scripts/install.sh | 34 +++++++++++++++++++++++++++++++--- specs/install.md | 4 +++- 4 files changed, 58 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 4bd2038..6c3c08c 100644 --- a/README.md +++ b/README.md @@ -42,6 +42,10 @@ curl -fsSL https://raw.githubusercontent.com/microsoft/modernize-cli/main/script The script automatically downloads the latest release, install the modernize bundle to `~/.local/share/modernize`, place the `modernize` command in `~/.local/bin`, and add the command directory to your PATH. +> [!TIP] +> To install the latest prerelease instead, append `--prerelease`: +> `curl -fsSL https://raw.githubusercontent.com/microsoft/modernize-cli/main/scripts/install.sh | sh -s -- --prerelease` + After installation, reload your shell profile to apply the PATH update: ```bash source ~/.bashrc # or source ~/.zshrc for Zsh @@ -67,6 +71,10 @@ winget install GitHub.Copilot.modernization.agent --silent iex (irm https://raw.githubusercontent.com/microsoft/modernize-cli/main/scripts/install.ps1) ``` +> [!TIP] +> To install the latest prerelease instead, run with `-Prerelease`: +> `& ([scriptblock]::Create((irm https://raw.githubusercontent.com/microsoft/modernize-cli/main/scripts/install.ps1))) -Prerelease` + **Option 3 — MSI installer:** Download and run the latest MSI from the [Releases page](https://github.com/microsoft/modernize-cli/releases/latest). diff --git a/scripts/install.ps1 b/scripts/install.ps1 index 3a6e87d..0980bba 100644 --- a/scripts/install.ps1 +++ b/scripts/install.ps1 @@ -7,10 +7,13 @@ version, extracts the binary, and adds it to the current user PATH. .PARAMETER InstallDir Directory to install modernize into. Defaults to %LOCALAPPDATA%\Programs\modernize. +.PARAMETER Prerelease + Install the latest prerelease instead of the latest stable release. #> [CmdletBinding()] param( - [string]$InstallDir = (Join-Path (Join-Path $env:LOCALAPPDATA 'Programs') 'modernize') + [string]$InstallDir = (Join-Path (Join-Path $env:LOCALAPPDATA 'Programs') 'modernize'), + [switch]$Prerelease ) $ErrorActionPreference = 'Stop' @@ -73,18 +76,27 @@ if (Get-Command gh -ErrorAction SilentlyContinue) { # --- Fetch latest release --- -Write-Info 'Fetching latest release...' - $apiHeaders = @{ Accept = 'application/vnd.github+json'; 'User-Agent' = 'modernize-installer' } +if ($Prerelease) { + Write-Info 'Fetching latest prerelease...' + $releaseUri = "https://api.github.com/repos/$GitHubRepo/releases?per_page=1" +} else { + Write-Info 'Fetching latest release...' + $releaseUri = "https://api.github.com/repos/$GitHubRepo/releases/latest" +} + try { $release = Invoke-RestMethod ` - -Uri "https://api.github.com/repos/$GitHubRepo/releases/latest" ` + -Uri $releaseUri ` -Headers $apiHeaders } catch { Exit-Error "Failed to fetch release info from GitHub: $_" } +# The list endpoint returns an array (newest first); select the first release. +if ($release -is [System.Array]) { $release = $release[0] } + $tag = $release.tag_name $version = $tag -replace '^v', '' diff --git a/scripts/install.sh b/scripts/install.sh index 431af9b..a34df0e 100755 --- a/scripts/install.sh +++ b/scripts/install.sh @@ -3,6 +3,7 @@ set -e GITHUB_REPO="microsoft/modernize-cli" MIN_GH_VERSION="2.45.0" +PRERELEASE=0 # --- Helpers --- @@ -10,6 +11,27 @@ info() { printf '\033[0;32m[info]\033[0m %s\n' "$*"; } warn() { printf '\033[0;33m[warn]\033[0m %s\n' "$*" >&2; } error() { printf '\033[0;31m[error]\033[0m %s\n' "$*" >&2; exit 1; } +usage() { + cat <<'EOF' +Usage: install.sh [options] + +Options: + --prerelease Install the latest prerelease instead of the latest stable release + -h, --help Show this help message and exit +EOF +} + +# --- Parse arguments --- + +while [ $# -gt 0 ]; do + case "$1" in + --prerelease) PRERELEASE=1 ;; + -h|--help) usage; exit 0 ;; + *) usage >&2; error "Unknown option: $1" ;; + esac + shift +done + version_lt() { # Returns 0 (true) if $1 < $2 awk -v v1="$1" -v v2="$2" 'BEGIN { @@ -72,17 +94,23 @@ fi # --- Fetch latest release version --- -info "Fetching latest release..." +if [ "$PRERELEASE" -eq 1 ]; then + info "Fetching latest prerelease..." + RELEASE_API="https://api.github.com/repos/${GITHUB_REPO}/releases?per_page=1" +else + info "Fetching latest release..." + RELEASE_API="https://api.github.com/repos/${GITHUB_REPO}/releases/latest" +fi if command -v curl > /dev/null 2>&1; then RELEASE_JSON=$(curl -fsSL \ -H "Accept: application/vnd.github+json" \ - "https://api.github.com/repos/${GITHUB_REPO}/releases/latest") \ + "$RELEASE_API") \ || error "Failed to fetch release info from GitHub." elif command -v wget > /dev/null 2>&1; then RELEASE_JSON=$(wget -qO- \ --header="Accept: application/vnd.github+json" \ - "https://api.github.com/repos/${GITHUB_REPO}/releases/latest") \ + "$RELEASE_API") \ || error "Failed to fetch release info from GitHub." else error "Neither curl nor wget found. Please install one of them." diff --git a/specs/install.md b/specs/install.md index 5bbd5ad..6ef1140 100644 --- a/specs/install.md +++ b/specs/install.md @@ -8,7 +8,9 @@ 3) Obtain a GitHub token via `gh auth token` (if gh CLI is available and authenticated) -4) Fetch the latest release metadata from the GitHub API (`api.github.com/repos/.../releases/latest`), using the token as a Bearer header if available +4) Fetch the release metadata from the GitHub API, using the token as a Bearer header if available: + - Default: latest stable release (`api.github.com/repos/.../releases/latest`) + - With `--prerelease` (shell) / `-Prerelease` (PowerShell): newest release overall including prereleases, via the releases list endpoint (`api.github.com/repos/.../releases?per_page=1`), taking the first (newest) entry 5) Resolve the archive filename from the release metadata based on the detected os-arch