fix(install): resolve latest without the rate-limited API, and test the installer
`install.sh` asked the release API for the latest tag. That API allows 60 requests an hour per IP without a token, which one office behind a NAT or a CI runner exhausts — and a throttled response has no `tag_name`, so the installer reported "could not resolve latest release tag" and gave no hint that rate limiting was the cause. It now follows the `/releases/latest` redirect, which carries no such limit and which Gitea implements identically, and keeps the API as the fallback for the wget path that cannot read the effective URL. Verified against the real release: resolves v26.8.0-beta.0, verifies the checksum, and the installed binary runs. Releases with a hyphen in the tag are now flagged as prereleases. Nothing set the flag, so every beta answered `/releases/latest` — the very thing the installer resolves by default. That is harmless while every release is a beta and wrong the moment a stable one exists, because the next beta published after it would silently displace it for everyone installing without MATCHA_VERSION. `test_install.sh` has existed since the installer landed and no workflow ever ran it — the same shape as the starter gap: a check that exists, passes, and guards nothing. CI runs it now on Linux and macOS with shellcheck alongside, and it covers a third case, since the branch this commit changes fails by producing a message: an unresolvable `latest` must name MATCHA_VERSION and must leave no binary behind. Signed-off-by: Diego Resendez <diego.resendez@zero-oneit.com>
This commit is contained in:
6 files changed
+78
-4
No files matched your search
@@ -75,3 +75,19 @@ jobs:
|
||||
echo "Bump CORE_VERSION in src/template.rs and let the starter job prove it still boots."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# install.sh has had a test since the installer landed, and no workflow ever
|
||||
# ran it. It exercises the script against a file:// fixture — no network — and
|
||||
# checks both halves that matter: a good archive installs, and a bad checksum
|
||||
# aborts without leaving a binary behind.
|
||||
installer:
|
||||
runs-on: ${{ matrix.os }}
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
os: [ubuntu-latest, macos-14]
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- run: shellcheck install.sh test_install.sh
|
||||
if: matrix.os == 'ubuntu-latest'
|
||||
- run: ./test_install.sh
|
||||
@@ -78,6 +78,11 @@ jobs:
|
||||
- name: Upload to release
|
||||
uses: softprops/action-gh-release@v2
|
||||
with:
|
||||
# A tag with a hyphen is a prerelease (26.9.0-beta.1). Unflagged, it
|
||||
# would answer /releases/latest — which is what install.sh resolves
|
||||
# with no MATCHA_VERSION — so the first stable release would be
|
||||
# displaced by the next beta published after it.
|
||||
prerelease: ${{ contains(github.ref_name, '-') }}
|
||||
files: |
|
||||
matcha-${{ matrix.target }}.tar.gz
|
||||
matcha-${{ matrix.target }}.tar.gz.sha256
|
||||
|
||||
@@ -104,6 +104,24 @@ is pinned to is `CORE_VERSION` in `src/template.rs`, and each entry below says w
|
||||
was `TS2868: Cannot find name 'Bun'` — meaning `tsc --noEmit`, and therefore
|
||||
`matcha create --check`, failed on every bun project the CLI has ever scaffolded.
|
||||
|
||||
- **`install.sh` resolves `latest` without the release API.** The API is rate-limited to
|
||||
60 requests an hour per IP unauthenticated — an office behind one NAT or a CI runner
|
||||
burns through it — and a throttled response carries no `tag_name`, so the installer
|
||||
failed with "could not resolve latest release tag" and no hint of the cause. It now
|
||||
follows the `/releases/latest` redirect, which has no such limit and which Gitea
|
||||
implements the same way, keeping the API as the fallback for the wget path. The error
|
||||
that remains names the rate limit and points at `MATCHA_VERSION`.
|
||||
|
||||
- **A beta release is flagged as a prerelease.** Nothing set the flag, so every beta
|
||||
answered `/releases/latest` — which is what `install.sh` resolves when no
|
||||
`MATCHA_VERSION` is given. Harmless while every release is a beta, and wrong the moment
|
||||
a stable one exists: the next beta published after it would displace it for everyone
|
||||
installing with the default.
|
||||
|
||||
- **CI runs `test_install.sh`.** It has existed since the installer landed and no workflow
|
||||
ever ran it. It now runs on Linux and macOS, with `shellcheck` alongside, and covers a
|
||||
third case: an unresolvable `latest` must explain itself and install nothing.
|
||||
|
||||
- **`MIT` is a file, not just a manifest field.** `Cargo.toml` declared `license = "MIT"` and
|
||||
the published crate carried no license text. Added along with the `DCO` the README has been
|
||||
requiring sign-off against, and a `CONTRIBUTING.md` saying how.
|
||||
|
||||
@@ -154,7 +154,8 @@ the alias can go once that is fixed.
|
||||
```bash
|
||||
cargo test # unit + CLI integration
|
||||
scripts/starter-smoke.sh node # scaffold, install, type-check, boot, introspect
|
||||
scripts/starter-smoke.sh deno # (also bun) — needs that runtime installed
|
||||
scripts/starter-smoke.sh deno # (also bun, edge) — needs that runtime installed
|
||||
./test_install.sh # install.sh against a file:// fixture, no network
|
||||
```
|
||||
|
||||
`starter-smoke.sh` is the check that `cargo test` cannot be: `cargo test` proves
|
||||
|
||||
+22
-3
@@ -51,11 +51,30 @@ case "$os" in
|
||||
*) err "unsupported OS: $os — try: cargo install --git $REPO_BASE" ;;
|
||||
esac
|
||||
|
||||
# Resolving "latest" prefers the /releases/latest redirect over the release API.
|
||||
# The API is rate-limited to 60 requests an hour per IP unauthenticated, which an
|
||||
# office behind one NAT or a CI runner burns through — and when it trips, the
|
||||
# response carries no tag_name, so the old code failed with "could not resolve
|
||||
# latest release tag" and no hint of why. The redirect has no such limit and
|
||||
# Gitea implements it the same way. The API stays as the fallback, since that is
|
||||
# the path wget can follow without parsing headers.
|
||||
resolve_latest() {
|
||||
if command -v curl >/dev/null 2>&1; then
|
||||
effective=$(curl -fsSLI -o /dev/null -w '%{url_effective}' "$REPO_BASE/releases/latest" 2>/dev/null || true)
|
||||
case "$effective" in
|
||||
*/releases/tag/*) echo "${effective##*/}"; return 0 ;;
|
||||
esac
|
||||
fi
|
||||
fetch "$API_BASE/releases/latest" 2>/dev/null \
|
||||
| grep -o '"tag_name":[[:space:]]*"[^"]*"' | head -1 | cut -d'"' -f4
|
||||
}
|
||||
|
||||
version="${MATCHA_VERSION:-latest}"
|
||||
if [ "$version" = "latest" ]; then
|
||||
tag=$(fetch "$API_BASE/releases/latest" \
|
||||
| grep -o '"tag_name":[[:space:]]*"[^"]*"' | head -1 | cut -d'"' -f4)
|
||||
[ -n "$tag" ] || err "could not resolve latest release tag"
|
||||
tag=$(resolve_latest)
|
||||
[ -n "$tag" ] || err "could not resolve the latest release tag.
|
||||
The release API may be rate-limited (60/hour per IP without a token).
|
||||
Pin a version instead: curl -fsSL <raw>/install.sh | MATCHA_VERSION=v26.8.0-beta.0 sh"
|
||||
else
|
||||
tag="$version"
|
||||
fi
|
||||
|
||||
@@ -43,4 +43,19 @@ if MATCHA_REPO_BASE="file://$work/fixture" MATCHA_VERSION="$tag" MATCHA_INSTALL_
|
||||
fi
|
||||
[ -e "$bin2/matcha" ] && fail "matcha must NOT be installed on checksum mismatch"
|
||||
|
||||
# --- case 3: an unresolvable "latest" explains itself and installs nothing ---
|
||||
# Both bases point at a path that does not exist, so the redirect and the API
|
||||
# fallback each come back empty. The branch is worth a test because its failure
|
||||
# mode is a message: the old one said only "could not resolve latest release
|
||||
# tag", which is also what a rate-limited API produces.
|
||||
bin3="$work/bin3"
|
||||
out=$(MATCHA_REPO_BASE="file://$work/nowhere" MATCHA_API_BASE="file://$work/nowhere" \
|
||||
MATCHA_INSTALL_DIR="$bin3" sh "$here/install.sh" 2>&1) && \
|
||||
fail "install.sh should have failed with no resolvable latest"
|
||||
case "$out" in
|
||||
*MATCHA_VERSION*) ;;
|
||||
*) fail "the unresolvable-latest error must point at MATCHA_VERSION; got: $out" ;;
|
||||
esac
|
||||
[ -e "$bin3/matcha" ] && fail "matcha must NOT be installed when latest cannot resolve"
|
||||
|
||||
echo "PASS: test_install.sh"
|
||||
Reference in new issue
Block a user