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
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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).
Expand Down
20 changes: 16 additions & 4 deletions scripts/install.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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', ''

Expand Down
34 changes: 31 additions & 3 deletions scripts/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,35 @@ set -e

GITHUB_REPO="microsoft/modernize-cli"
MIN_GH_VERSION="2.45.0"
PRERELEASE=0

# --- Helpers ---

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 {
Expand Down Expand Up @@ -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."
Expand Down
4 changes: 3 additions & 1 deletion specs/install.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down