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
2 changes: 2 additions & 0 deletions .github/workflows/release-assets.yml
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,8 @@ jobs:
run: |
mkdir -p staging
src="target/${TARGET}/release/${BIN}"
# Prefix must stay amber-. v1.16.0 and earlier shipped bee- leftovers;
# install.sh / install.ps1 fall back to that name for old tags.
if [ "${ARCHIVE}" = "zip" ]; then
cp "${src}" staging/amber.exe
python3 -c "import shutil; shutil.make_archive('amber-${RELEASE_TAG}-${TARGET}', 'zip', 'staging')"
Expand Down
9 changes: 9 additions & 0 deletions apps/website/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,18 @@ The production bundle is written to `dist/`. The `prebuild` step copies repo-roo

## Cloudflare Deploy

`get.amberjs.com` is a custom domain on the same Worker as `amberjs.com` (`apps/website/wrangler.toml`). There is no GitHub Actions deploy job; publishing is a local Wrangler deploy (needs a Cloudflare account with access to this Worker):

```bash
pnpm run deploy:dry-run
pnpm run deploy
```

`wrangler.toml` serves `dist/` as static assets and uses `single-page-application` fallback so direct links such as `/docs/installation` work on Cloudflare.

`src/worker.ts` serves `/install.sh` and `/install.ps1` from the R2 bucket `amber-dist` **when that object exists**, otherwise from the Worker static assets. Live `get.amberjs.com/install.sh` currently matches the asset-hosted copy (`content-type: application/x-sh`, `max-age=0`), so a Wrangler deploy updates the installer. If R2 later has `install.sh` / `install.ps1`, it shadows the deploy — also upload:

```bash
npx wrangler r2 object put install.sh --file=../../install.sh --bucket=amber-dist --remote --content-type text/plain
npx wrangler r2 object put install.ps1 --file=../../install.ps1 --bucket=amber-dist --remote --content-type text/plain
```
40 changes: 32 additions & 8 deletions apps/website/public/install.ps1
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Amber Windows installer. Downloads amber-vX-x86_64-pc-windows-msvc.zip from GitHub Releases.
# Amber Windows installer. Tries amber-vX-x86_64-pc-windows-msvc.zip, then legacy bee- zip.
param(
[string]$Version = $env:AMBER_VERSION,
[string]$InstallDir = $(if ($env:AMBER_INSTALL_DIR) { $env:AMBER_INSTALL_DIR } else { Join-Path $env:LOCALAPPDATA "amber\bin" }),
Expand All @@ -17,23 +17,47 @@ if ($Version -notmatch '^v') {
$Version = "v$Version"
}

$asset = "amber-$Version-$Target.zip"
$url = "https://github.com/$Repo/releases/download/$Version/$asset"
$tmp = Join-Path ([System.IO.Path]::GetTempPath()) $asset
if ($env:AMBER_RELEASE_BASE) {
$releaseRoot = $env:AMBER_RELEASE_BASE.TrimEnd("/") + "/$Version"
} else {
$releaseRoot = "https://github.com/$Repo/releases/download/$Version"
}

$urls = @(
"$releaseRoot/amber-$Version-$Target.zip",
"$releaseRoot/bee-$Version-$Target.zip"
)

$tmp = Join-Path ([System.IO.Path]::GetTempPath()) ("amber-" + [guid]::NewGuid().ToString("n") + ".zip")
$downloaded = $false
$tried = New-Object System.Collections.Generic.List[string]

Write-Host "Downloading $url"
Invoke-WebRequest -Uri $url -OutFile $tmp
foreach ($url in $urls) {
[void]$tried.Add($url)
Write-Host "Downloading $url"
try {
Invoke-WebRequest -Uri $url -OutFile $tmp -UseBasicParsing
$downloaded = $true
break
} catch {
Write-Host "amber install: not found: $url"
}
}

if (-not $downloaded) {
throw "amber install: download failed (tried: $($tried -join ' '))"
}

$extract = Join-Path ([System.IO.Path]::GetTempPath()) ("amber-" + [guid]::NewGuid().ToString("n"))
New-Item -ItemType Directory -Path $extract | Out-Null
Expand-Archive -Path $tmp -DestinationPath $extract -Force

$src = Get-ChildItem -Path $extract -Recurse -Filter "amber.exe" | Select-Object -First 1
if (-not $src) {
$src = Get-ChildItem -Path $extract -Recurse -Filter "amber.exe" | Select-Object -First 1
$src = Get-ChildItem -Path $extract -Recurse -Filter "bee.exe" | Select-Object -First 1
}
if (-not $src) {
throw "amber.exe not found in archive"
throw "amber.exe or bee.exe not found in archive"
}

New-Item -ItemType Directory -Path $InstallDir -Force | Out-Null
Expand Down
76 changes: 65 additions & 11 deletions apps/website/public/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ Environment variables:
AMBER_INSTALL_DIR Install directory (default: ~/.amber/bin)
AMBER_REPO GitHub repo (default: zh30/amberjs)

The installer tries amber-<tag>-<target>.tar.gz first, then the
legacy bee-<tag>-<target>.tar.gz asset from older releases. The
archive may contain a binary named amber or bee; it is always
installed as $AMBER_INSTALL_DIR/amber.

Examples:
AMBER_VERSION=v1.16.0 sh install.sh
AMBER_INSTALL_DIR=~/.local/bin sh install.sh
Expand All @@ -42,9 +47,14 @@ need_cmd() {
if need_cmd curl; then
http_get() { curl -fsSL "$1"; }
http_download() { curl -fsSL "$1" -o "$2"; }
http_try_download() {
code=$(curl -sSL -o "$2" -w "%{http_code}" "$1") || return 1
[ "$code" = "200" ]
}
elif need_cmd wget; then
http_get() { wget -qO- "$1"; }
http_download() { wget -qO "$2" "$1"; }
http_try_download() { wget -qO "$2" "$1"; }
else
fail "curl or wget is required"
fi
Expand Down Expand Up @@ -73,6 +83,23 @@ if [ "${1:-}" = "--print-platform" ]; then
exit 0
fi

release_asset_url() {
version_tag="$1"
filename="$2"
if [ -n "${AMBER_RELEASE_BASE:-}" ]; then
echo "${AMBER_RELEASE_BASE%/}/${version_tag}/${filename}"
else
echo "https://github.com/${AMBER_REPO}/releases/download/${version_tag}/${filename}"
fi
}

candidate_archive_urls() {
version_tag="$1"
target="$2"
release_asset_url "$version_tag" "amber-${version_tag}-${target}.tar.gz"
release_asset_url "$version_tag" "bee-${version_tag}-${target}.tar.gz"
}

resolve_version() {
if [ -n "${AMBER_VERSION:-}" ]; then
version="${AMBER_VERSION}"
Expand All @@ -89,30 +116,57 @@ resolve_version() {
esac
}

if [ "${1:-}" = "--print-asset-urls" ]; then
print_target=$(resolve_platform)
print_tag=$(resolve_version)
candidate_archive_urls "$print_tag" "$print_target"
exit 0
fi

find_extracted_binary() {
root="$1"
if [ -f "$root/amber" ]; then
echo "$root/amber"
return 0
fi
if [ -f "$root/bee" ]; then
echo "$root/bee"
return 0
fi
find "$root" -type f \( -name amber -o -name bee \) | head -n 1
}

install_binary() {
target="$1"
version_tag="$2"

tmpdir=$(mktemp -d 2>/dev/null || mktemp -d -t amber)
archive="$tmpdir/amber.tar.gz"
url="https://github.com/${AMBER_REPO}/releases/download/${version_tag}/amber-${version_tag}-${target}.tar.gz"

trap 'rm -rf "$tmpdir"' EXIT INT TERM

echo "Downloading ${url}"
http_download "$url" "$archive" || fail "download failed"
amber_url=$(release_asset_url "$version_tag" "amber-${version_tag}-${target}.tar.gz")
bee_url=$(release_asset_url "$version_tag" "bee-${version_tag}-${target}.tar.gz")
tried="${amber_url} ${bee_url}"
downloaded=""

tar -xzf "$archive" -C "$tmpdir" || fail "failed to extract archive"

if [ -f "$tmpdir/amber" ]; then
src="$tmpdir/amber"
elif [ -f "$tmpdir/amber" ]; then
src="$tmpdir/amber"
# Prefer amber- assets; fall back to bee- leftovers from v1.16.0 and earlier.
echo "Downloading ${amber_url}"
if http_try_download "$amber_url" "$archive"; then
downloaded="$amber_url"
else
src=$(find "$tmpdir" -type f \( -name amber -o -name amber \) | head -n 1)
echo "Downloading ${bee_url}"
if http_try_download "$bee_url" "$archive"; then
downloaded="$bee_url"
fi
fi

[ -n "${src:-}" ] || fail "amber binary not found in archive"
[ -n "$downloaded" ] || fail "download failed (tried: ${tried})"

tar -xzf "$archive" -C "$tmpdir" || fail "failed to extract archive"

src=$(find_extracted_binary "$tmpdir")
[ -n "${src:-}" ] || fail "amber or bee binary not found in archive"

mkdir -p "$AMBER_INSTALL_DIR"
cp "$src" "$AMBER_INSTALL_DIR/amber"
Expand Down
40 changes: 32 additions & 8 deletions install.ps1
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Amber Windows installer. Downloads amber-vX-x86_64-pc-windows-msvc.zip from GitHub Releases.
# Amber Windows installer. Tries amber-vX-x86_64-pc-windows-msvc.zip, then legacy bee- zip.
param(
[string]$Version = $env:AMBER_VERSION,
[string]$InstallDir = $(if ($env:AMBER_INSTALL_DIR) { $env:AMBER_INSTALL_DIR } else { Join-Path $env:LOCALAPPDATA "amber\bin" }),
Expand All @@ -17,23 +17,47 @@ if ($Version -notmatch '^v') {
$Version = "v$Version"
}

$asset = "amber-$Version-$Target.zip"
$url = "https://github.com/$Repo/releases/download/$Version/$asset"
$tmp = Join-Path ([System.IO.Path]::GetTempPath()) $asset
if ($env:AMBER_RELEASE_BASE) {
$releaseRoot = $env:AMBER_RELEASE_BASE.TrimEnd("/") + "/$Version"
} else {
$releaseRoot = "https://github.com/$Repo/releases/download/$Version"
}

$urls = @(
"$releaseRoot/amber-$Version-$Target.zip",
"$releaseRoot/bee-$Version-$Target.zip"
)

$tmp = Join-Path ([System.IO.Path]::GetTempPath()) ("amber-" + [guid]::NewGuid().ToString("n") + ".zip")
$downloaded = $false
$tried = New-Object System.Collections.Generic.List[string]

Write-Host "Downloading $url"
Invoke-WebRequest -Uri $url -OutFile $tmp
foreach ($url in $urls) {
[void]$tried.Add($url)
Write-Host "Downloading $url"
try {
Invoke-WebRequest -Uri $url -OutFile $tmp -UseBasicParsing
$downloaded = $true
break
} catch {
Write-Host "amber install: not found: $url"
}
}

if (-not $downloaded) {
throw "amber install: download failed (tried: $($tried -join ' '))"
}

$extract = Join-Path ([System.IO.Path]::GetTempPath()) ("amber-" + [guid]::NewGuid().ToString("n"))
New-Item -ItemType Directory -Path $extract | Out-Null
Expand-Archive -Path $tmp -DestinationPath $extract -Force

$src = Get-ChildItem -Path $extract -Recurse -Filter "amber.exe" | Select-Object -First 1
if (-not $src) {
$src = Get-ChildItem -Path $extract -Recurse -Filter "amber.exe" | Select-Object -First 1
$src = Get-ChildItem -Path $extract -Recurse -Filter "bee.exe" | Select-Object -First 1
}
if (-not $src) {
throw "amber.exe not found in archive"
throw "amber.exe or bee.exe not found in archive"
}

New-Item -ItemType Directory -Path $InstallDir -Force | Out-Null
Expand Down
76 changes: 65 additions & 11 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ Environment variables:
AMBER_INSTALL_DIR Install directory (default: ~/.amber/bin)
AMBER_REPO GitHub repo (default: zh30/amberjs)

The installer tries amber-<tag>-<target>.tar.gz first, then the
legacy bee-<tag>-<target>.tar.gz asset from older releases. The
archive may contain a binary named amber or bee; it is always
installed as $AMBER_INSTALL_DIR/amber.

Examples:
AMBER_VERSION=v1.16.0 sh install.sh
AMBER_INSTALL_DIR=~/.local/bin sh install.sh
Expand All @@ -42,9 +47,14 @@ need_cmd() {
if need_cmd curl; then
http_get() { curl -fsSL "$1"; }
http_download() { curl -fsSL "$1" -o "$2"; }
http_try_download() {
code=$(curl -sSL -o "$2" -w "%{http_code}" "$1") || return 1
[ "$code" = "200" ]
}
elif need_cmd wget; then
http_get() { wget -qO- "$1"; }
http_download() { wget -qO "$2" "$1"; }
http_try_download() { wget -qO "$2" "$1"; }
else
fail "curl or wget is required"
fi
Expand Down Expand Up @@ -73,6 +83,23 @@ if [ "${1:-}" = "--print-platform" ]; then
exit 0
fi

release_asset_url() {
version_tag="$1"
filename="$2"
if [ -n "${AMBER_RELEASE_BASE:-}" ]; then
echo "${AMBER_RELEASE_BASE%/}/${version_tag}/${filename}"
else
echo "https://github.com/${AMBER_REPO}/releases/download/${version_tag}/${filename}"
fi
}

candidate_archive_urls() {
version_tag="$1"
target="$2"
release_asset_url "$version_tag" "amber-${version_tag}-${target}.tar.gz"
release_asset_url "$version_tag" "bee-${version_tag}-${target}.tar.gz"
}

resolve_version() {
if [ -n "${AMBER_VERSION:-}" ]; then
version="${AMBER_VERSION}"
Expand All @@ -89,30 +116,57 @@ resolve_version() {
esac
}

if [ "${1:-}" = "--print-asset-urls" ]; then
print_target=$(resolve_platform)
print_tag=$(resolve_version)
candidate_archive_urls "$print_tag" "$print_target"
exit 0
fi

find_extracted_binary() {
root="$1"
if [ -f "$root/amber" ]; then
echo "$root/amber"
return 0
fi
if [ -f "$root/bee" ]; then
echo "$root/bee"
return 0
fi
find "$root" -type f \( -name amber -o -name bee \) | head -n 1
}

install_binary() {
target="$1"
version_tag="$2"

tmpdir=$(mktemp -d 2>/dev/null || mktemp -d -t amber)
archive="$tmpdir/amber.tar.gz"
url="https://github.com/${AMBER_REPO}/releases/download/${version_tag}/amber-${version_tag}-${target}.tar.gz"

trap 'rm -rf "$tmpdir"' EXIT INT TERM

echo "Downloading ${url}"
http_download "$url" "$archive" || fail "download failed"
amber_url=$(release_asset_url "$version_tag" "amber-${version_tag}-${target}.tar.gz")
bee_url=$(release_asset_url "$version_tag" "bee-${version_tag}-${target}.tar.gz")
tried="${amber_url} ${bee_url}"
downloaded=""

tar -xzf "$archive" -C "$tmpdir" || fail "failed to extract archive"

if [ -f "$tmpdir/amber" ]; then
src="$tmpdir/amber"
elif [ -f "$tmpdir/amber" ]; then
src="$tmpdir/amber"
# Prefer amber- assets; fall back to bee- leftovers from v1.16.0 and earlier.
echo "Downloading ${amber_url}"
if http_try_download "$amber_url" "$archive"; then
downloaded="$amber_url"
else
src=$(find "$tmpdir" -type f \( -name amber -o -name amber \) | head -n 1)
echo "Downloading ${bee_url}"
if http_try_download "$bee_url" "$archive"; then
downloaded="$bee_url"
fi
fi

[ -n "${src:-}" ] || fail "amber binary not found in archive"
[ -n "$downloaded" ] || fail "download failed (tried: ${tried})"

tar -xzf "$archive" -C "$tmpdir" || fail "failed to extract archive"

src=$(find_extracted_binary "$tmpdir")
[ -n "${src:-}" ] || fail "amber or bee binary not found in archive"

mkdir -p "$AMBER_INSTALL_DIR"
cp "$src" "$AMBER_INSTALL_DIR/amber"
Expand Down
Loading
Loading