feat: remove deprecated sh

This commit is contained in:
kite 2026-05-13 14:23:16 +08:00
parent f40872f26e
commit 0ec83ae226
2 changed files with 0 additions and 320 deletions

View file

@ -1,198 +0,0 @@
#!/usr/bin/env sh
# install.sh — Install or upgrade OpenCodeReview CLI
#
# Usage (pipelined):
# curl -fsSL https://git.cn-hangzhou.oss-cdn.aliyun-inc.com/opencodereview-cli/install.sh | sh
# OCR_VERSION=v0.1.0 curl -fsSL ... | sh
#
# Usage (standalone):
# sh install.sh
# OCR_VERSION=v0.1.0 sh install.sh
#
# Environment variables:
# OCR_VERSION Pin a specific version (e.g., v0.1.0). Defaults to "latest".
# INSTALL_DIR Override install destination (default: /usr/local/bin).
set -eu
# ── Configuration ────────────────────────────────────────────────────────────
BASE_URL="https://code.alibaba-inc.com/lizhengfeng.lzf/opencodereview-cli/raw/master/dist"
BINARY_NAME="opencodereview"
INSTALL_DIR="${INSTALL_DIR:-/usr/local/bin}"
# ── Logging ──────────────────────────────────────────────────────────────────
info() { printf "[INFO] %s\n" "$*" >&2; }
warn() { printf "[WARN] %s\n" "$*" >&2; }
error() { printf "[ERROR] %s\n" "$*" >&2; }
die() { error "$@"; exit 1; }
# ── Cleanup trap ─────────────────────────────────────────────────────────────
TMPDIR_WORK=""
cleanup() {
if [ -n "$TMPDIR_WORK" ] && [ -d "$TMPDIR_WORK" ]; then
rm -rf "$TMPDIR_WORK"
fi
}
trap cleanup EXIT INT TERM
# ── Detect OS & Arch ─────────────────────────────────────────────────────────
detect_platform() {
OS="$(uname -s | tr '[:upper:]' '[:lower:]')"
ARCH="$(uname -m)"
case "$ARCH" in
x86_64|amd64|x64) ARCH="amd64" ;;
aarch64|arm64) ARCH="arm64" ;;
*) die "Unsupported architecture: $ARCH (need amd64 or arm64)" ;;
esac
case "$OS" in
linux|darwin) ;;
*) die "Unsupported operating system: $OS (need linux or darwin)" ;;
esac
info "Detected platform: ${OS}/${ARCH}"
}
# ── Resolve version ──────────────────────────────────────────────────────────
resolve_version() {
if [ -n "${OCR_VERSION:-}" ]; then
VERSION="$OCR_VERSION"
VERSION="v$(echo "$VERSION" | sed 's/^v//')"
info "Using pinned version: ${VERSION}"
return
fi
# Try fetching latest version from remote
info "Fetching latest version..."
VERSION=$(curl -fsSL --retry 3 --retry-delay 2 "${BASE_URL}/VERSION" 2>/dev/null || true)
if [ -n "$VERSION" ]; then
info "Latest version: ${VERSION}"
return
fi
# Fallback: detect locally built binary in dist/
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
PROJECT_ROOT="$(cd "$SCRIPT_DIR/.." 2>/dev/null && pwd || true)"
if [ -n "$PROJECT_ROOT" ] && [ -d "${PROJECT_ROOT}/dist" ]; then
LOCAL_BIN=""
# Prefer platform-specific binary, fall back to generic one
for pattern in \
"${BINARY_NAME}-${VERSION:-*}-${OS}-${ARCH}" \
"${BINARY_NAME}-${VERSION:-*}-${OS}-*" \
"${BINARY_NAME}"; do
LOCAL_BIN=$(ls "${PROJECT_ROOT}/dist/${pattern}" 2>/dev/null | head -1 || true)
if [ -n "$LOCAL_BIN" ] && [ -f "$LOCAL_BIN" ]; then
break
fi
done
if [ -n "$LOCAL_BIN" ] && [ -f "$LOCAL_BIN" ]; then
VERSION=$("$LOCAL_BIN" version 2>/dev/null | awk '{print $NF}' || echo "local")
VERSION="v$(echo "$VERSION" | sed 's/^v//')"
LOCAL_BINARY="$LOCAL_BIN"
warn "Remote unavailable, using local build: ${VERSION}"
warn " Source: ${LOCAL_BINARY}"
return
fi
fi
die "Cannot determine version. Set OCR_VERSION explicitly, or build locally with 'make build'."
}
# ── Download / locate binary ─────────────────────────────────────────────────
locate_or_download_binary() {
# If a local binary was already resolved during version detection, use it directly
if [ -n "${LOCAL_BINARY:-}" ]; then
DEST="$LOCAL_BINARY"
info "Using local binary: ${DEST}"
return
fi
BINARY_FILE="${BINARY_NAME}-${VERSION}-${OS}-${ARCH}"
DOWNLOAD_URL="${BASE_URL}/${BINARY_FILE}"
TMPDIR_WORK=$(mktemp -d)
DEST="${TMPDIR_WORK}/${BINARY_NAME}"
info "Downloading ${DOWNLOAD_URL} ..."
if ! curl -fsSL --retry 3 --retry-delay 2 -o "$DEST" "$DOWNLOAD_URL"; then
die "Download failed. Check that version '${VERSION}' exists for ${OS}/${ARCH}."
fi
chmod +x "$DEST"
# Verify checksum if available
CHECKSUM_URL="${BASE_URL}/sha256sum-${VERSION}.txt"
EXPECTED_CHECKSUM=$(curl -fsSL --retry 2 "$CHECKSUM_URL" 2>/dev/null | grep "$BINARY_FILE" | awk '{print $1}' || true)
if [ -n "$EXPECTED_CHECKSUM" ]; then
ACTUAL_CHECKSUM=$(shasum -a 256 "$DEST" | awk '{print $1}')
if [ "$ACTUAL_CHECKSUM" != "$EXPECTED_CHECKSUM" ]; then
die "Checksum mismatch! Expected: ${EXPECTED_CHECKSUM}, Got: ${ACTUAL_CHECKSUM}"
fi
info "Checksum verified."
else
warn "Checksum file not found at ${CHECKSUM_URL}; skipping integrity check."
fi
}
# ── Install ──────────────────────────────────────────────────────────────────
install_binary() {
TARGET="${INSTALL_DIR}/${BINARY_NAME}"
# Ensure install directory exists
if [ ! -d "$INSTALL_DIR" ]; then
if command -v sudo >/dev/null 2>&1; then
info "Creating install directory: ${INSTALL_DIR}"
sudo mkdir -p "$INSTALL_DIR"
else
die "Install directory does not exist and sudo is unavailable: ${INSTALL_DIR}"
fi
fi
if [ -f "$TARGET" ]; then
CURRENT_VER=$("$TARGET" version 2>/dev/null | head -1 || echo "unknown")
warn "Existing installation found (${CURRENT_VER}), replacing with ${VERSION}."
fi
if [ ! -w "$INSTALL_DIR" ] && ! [ "$(id -u)" = "0" ]; then
info "Installing to ${INSTALL_DIR} (sudo required)..."
sudo cp "$DEST" "$TARGET"
else
cp "$DEST" "$TARGET"
fi
info "Installed: ${TARGET}"
}
# ── Verify installation ──────────────────────────────────────────────────────
verify_install() {
if command -v "${INSTALL_DIR}/${BINARY_NAME}" >/dev/null 2>&1; then
INSTALLED_VER=$("${INSTALL_DIR}/${BINARY_NAME}" version 2>/dev/null || echo "?")
info ""
info "OpenCodeReview ${INSTALLED_VER} is ready!"
info ""
info "Quick start:"
info " ocr version Show version info"
info " ocr config set Configure your LLM provider"
info " ocr review Start a code review"
else
warn ""
warn "Installation completed but '${BINARY_NAME}' is not on PATH."
warn "Add ${INSTALL_DIR} to your PATH, or run directly:"
warn " ${TARGET} version"
fi
}
# ── Main ─────────────────────────────────────────────────────────────────────
main() {
info "OpenCodeReview CLI Installer"
info "==================="
detect_platform
resolve_version
locate_or_download_binary
install_binary
verify_install
}
main

View file

@ -1,122 +0,0 @@
#!/usr/bin/env bash
#
# release.sh — Build all platform binaries and publish to internal-release repo
#
# Usage:
# ./scripts/release.sh # Builds using latest git tag as version
# ./scripts/release.sh v0.1.0 # Explicit version tag
#
# Prerequisites:
# - Git tag exists for the version (or pass version explicitly)
# - Go 1.25+ installed
# - ~/internal-release repo exists with a writable bin/ directory
#
# Environment variables:
# OCR_INTERNAL_RELEASE Override the default path to internal-release repo
# (default: $HOME/internal-release)
#
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
info() { echo "[INFO] $*"; }
warn() { echo "[WARN] $*"; }
error() { echo "[ERROR] $*"; }
die() { error "$*"; exit 1; }
VERSION="${1:-}"
if [ -z "$VERSION" ]; then
VERSION=$(git -C "$PROJECT_ROOT" describe --tags --abbrev=0 2>/dev/null || true)
if [ -z "$VERSION" ]; then
die "No git tag found. Pass a version explicitly or create a tag first."
fi
info "Using latest git tag: ${VERSION}"
else
[[ "$VERSION" != v* ]] && VERSION="v${VERSION}"
fi
info "=== OpenCodeReview Release: ${VERSION} ==="
# ── Pre-flight checks ────────────────────────────────────────────────────────
command -v go >/dev/null 2>&1 || die "'go' is required but not installed."
cd "$PROJECT_ROOT"
if [ -n "$(git status --porcelain)" ]; then
warn "Working tree has uncommitted changes. Proceeding anyway..."
fi
# ── Build all platforms ──────────────────────────────────────────────────────
DIST_DIR="${PROJECT_ROOT}/dist"
mkdir -p "$DIST_DIR"
rm -f "${DIST_DIR}/opencodereview-${VERSION}-"*
GIT_COMMIT="$(git rev-parse --short HEAD)"
BUILD_DATE="$(date -u +"%Y-%m-%dT%H:%M:%SZ")"
LD_FLAGS="-s -w -X main.Version=${VERSION} -X main.GitCommit=${GIT_COMMIT} -X main.BuildDate=${BUILD_DATE}"
TARGETS=(
"linux/amd64"
"linux/arm64"
"darwin/amd64"
"darwin/arm64"
)
for pair in "${TARGETS[@]}"; do
GOOS="${pair%/*}"
GOARCH="${pair#*/}"
OS_ARCH="${GOOS}-${GOARCH}"
OUTPUT_NAME="opencodereview-${VERSION}-${OS_ARCH}"
info "Building ${GOOS}/${GOARCH}${OUTPUT_NAME}"
CGO_ENABLED=0 GOOS="$GOOS" GOARCH="$GOARCH" \
go build -ldflags "${LD_FLAGS}" \
-o "${DIST_DIR}/${OUTPUT_NAME}" \
./cmd/opencodereview
done
# ── Publish to internal release repo ────────────────────────────────────────
INTERNAL_ROOT="${OCR_INTERNAL_RELEASE:-$HOME/internal-release}"
[ -d "$INTERNAL_ROOT" ] || die "internal-release repo not found at ${INTERNAL_ROOT}"
BIN_DIR="${INTERNAL_ROOT}/bin"
VERSION_DIR="${BIN_DIR}/${VERSION}"
info ""
info "Publishing to ${INTERNAL_ROOT} ..."
# Create versioned directory, clean old files if re-publishing same version
mkdir -p "$VERSION_DIR"
rm -f "$VERSION_DIR"/*
for f in "${DIST_DIR}"/opencodereview-"${VERSION}"-*; do
SRC_BASENAME="$(basename "$f")"
# Strip version prefix to get canonical name: opencodereview-v0.1.0-darwin-arm64 → opencodereview-darwin-arm64
TARGET_NAME="${SRC_BASENAME/opencodereview-${VERSION}-/opencodereview-}"
info " ${TARGET_NAME}"
cp "$f" "$VERSION_DIR/${TARGET_NAME}"
done
# Generate checksum using final filenames (without version in filename)
(cd "$VERSION_DIR" && shasum -a 256 opencodereview-* | sort > sha256sum.txt)
info " sha256sum.txt written"
# Append version to VERSION file (last line = latest)
printf "%s\n" "$VERSION" >> "${INTERNAL_ROOT}/VERSION"
info " VERSION entry appended"
# ── Commit and push ──────────────────────────────────────────────────────────
cd "$INTERNAL_ROOT"
git add -A
if [ -n "$(git status --porcelain)" ]; then
git commit -m "release: opencodereview ${VERSION}"
git push
info ""
info "=== Release ${VERSION} published ==="
else
info "No new changes to commit — binaries unchanged."
fi