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 .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# 强制 scripts 目录下的 Shell 脚本始终使用 LF 换行符
scripts/*.sh text eol=lf
3 changes: 1 addition & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,4 @@ jobs:
version: '~> v2'
args: release --clean
env:
# GitHub Actions 自动注入的 Token,用于发布 Release
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
TAP_GITHUB_TOKEN: ${{ secrets.TAP_GITHUB_TOKEN }}
4 changes: 3 additions & 1 deletion .goreleaser.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# .goreleaser.yaml
project_name: neocode
version: 2 # 必须声明为 v2 语法

before:
Expand Down Expand Up @@ -44,4 +45,5 @@ changelog:
filters:
exclude:
- '^docs:'
- '^test:'
- '^test:'

69 changes: 69 additions & 0 deletions scripts/install.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
$ErrorActionPreference = "Stop"

# 配置仓库信息
$Repo = "pionxe/neo-code"
$ProjectName = "neo-code"
$BinaryName = "neocode.exe"

Write-Host "🚀 开始安装 $BinaryName..." -ForegroundColor Cyan

# 1. 获取系统架构
$Arch = $env:PROCESSOR_ARCHITECTURE
if ($Arch -eq "AMD64") {
$ArchName = "x86_64"
} elseif ($Arch -eq "ARM64") {
$ArchName = "arm64"
} else {
Write-Error "❌ 不支持的系统架构: $Arch"
exit
}

# 2. 从 GitHub API 获取最新 Release 版本号
Write-Host "🔍 正在获取最新版本信息..."
$ApiUrl = "https://api.github.com/repos/$Repo/releases/latest"
try {
$LatestRelease = Invoke-RestMethod -Uri $ApiUrl
$LatestTag = $LatestRelease.tag_name
} catch {
Write-Error "❌ 无法获取最新版本,请检查网络或 GitHub 访问权限。"
exit
}
Write-Host "📦 发现最新版本: $LatestTag"

# 3. 拼接下载链接
$ZipFile = "${ProjectName}_Windows_${ArchName}.zip"
$DownloadUrl = "https://github.com/$Repo/releases/download/$LatestTag/$ZipFile"

# 4. 下载并解压到临时目录
$TempDir = Join-Path $env:TEMP "neocode_install"
if (Test-Path $TempDir) { Remove-Item -Recurse -Force $TempDir }
New-Item -ItemType Directory -Force -Path $TempDir | Out-Null
$ZipPath = Join-Path $TempDir $ZipFile

Write-Host "⬇️ 正在下载压缩包..."
Invoke-WebRequest -Uri $DownloadUrl -OutFile $ZipPath

Write-Host "📦 正在解压..."
Expand-Archive -Path $ZipPath -DestinationPath $TempDir -Force

# 5. 部署到用户目录
$InstallDir = Join-Path $env:LOCALAPPDATA "NeoCode"
if (!(Test-Path $InstallDir)) {
New-Item -ItemType Directory -Force -Path $InstallDir | Out-Null
}
Write-Host "⚙️ 正在将可执行文件部署到 $InstallDir..."
Copy-Item -Path (Join-Path $TempDir $BinaryName) -Destination $InstallDir -Force

# 6. 配置环境变量 PATH
$UserPath = [Environment]::GetEnvironmentVariable("PATH", "User")
if ($UserPath -notmatch [regex]::Escape($InstallDir)) {
Write-Host "🔧 正在配置环境变量..."
$NewPath = "$UserPath;$InstallDir"
[Environment]::SetEnvironmentVariable("PATH", $NewPath, "User")
Write-Host "⚠️ 环境变量已更新!安装完成后,请重启终端(PowerShell/CMD)以使命令生效。" -ForegroundColor Yellow
}

# 7. 清理临时文件
Remove-Item -Recurse -Force $TempDir

Write-Host "✅ 安装成功!" -ForegroundColor Green
61 changes: 61 additions & 0 deletions scripts/install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#!/bin/bash
set -e

# 配置仓库信息
REPO="pionxe/neo-code"
PROJECT_NAME="neo-code"
BINARY_NAME="neocode"

echo "🚀 开始安装 $BINARY_NAME..."

# 1. 获取系统和架构信息
OS="$(uname -s)"
ARCH="$(uname -m)"

if [ "$OS" = "Linux" ]; then
OS_NAME="Linux"
elif [ "$OS" = "Darwin" ]; then
OS_NAME="Darwin"
else
echo "❌ 不支持的操作系统: $OS"
exit 1
fi

if [ "$ARCH" = "x86_64" ] || [ "$ARCH" = "amd64" ]; then
ARCH_NAME="x86_64"
elif [ "$ARCH" = "aarch64" ] || [ "$ARCH" = "arm64" ]; then
ARCH_NAME="arm64"
else
echo "❌ 不支持的系统架构: $ARCH"
exit 1
fi

# 2. 从 GitHub API 获取最新 Release 版本号
echo "🔍 正在获取最新版本信息..."
LATEST_TAG=$(curl -s "https://api.github.com/repos/$REPO/releases/latest" | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/')

if [ -z "$LATEST_TAG" ]; then
echo "❌ 无法获取最新版本,请检查网络或 GitHub 访问权限。"
exit 1
fi
echo "📦 发现最新版本: $LATEST_TAG"

# 3. 拼接下载链接 (匹配 GoReleaser 默认命名)
TAR_FILE="${PROJECT_NAME}_${OS_NAME}_${ARCH_NAME}.tar.gz"
DOWNLOAD_URL="https://github.com/$REPO/releases/download/$LATEST_TAG/$TAR_FILE"

# 4. 下载并解压
echo "⬇️ 正在下载: $DOWNLOAD_URL"
curl -L -o "$TAR_FILE" "$DOWNLOAD_URL"

echo "📦 正在解压..."
tar -xzf "$TAR_FILE" "$BINARY_NAME"

# 5. 安装到全局 PATH
echo "⚙️ 正在安装到 /usr/local/bin (此步可能需要输入密码以获取 sudo 权限)..."
sudo mv "$BINARY_NAME" /usr/local/bin/

# 6. 清理临时文件
rm "$TAR_FILE"

echo "✅ 安装成功!请在终端运行 '$BINARY_NAME --help' 开始使用。"
Loading