mirror of
https://github.com/wisdgod/cursor-api.git
synced 2025-12-24 13:38:01 +08:00
first commit
This commit is contained in:
263
.github/workflows/build.yml
vendored
Normal file
263
.github/workflows/build.yml
vendored
Normal file
@@ -0,0 +1,263 @@
|
||||
name: Build
|
||||
|
||||
on:
|
||||
push:
|
||||
tags:
|
||||
- 'v*'
|
||||
|
||||
jobs:
|
||||
build:
|
||||
name: Build ${{ matrix.os }}
|
||||
runs-on: ${{ matrix.os }}
|
||||
strategy:
|
||||
matrix:
|
||||
os: [ubuntu-latest, windows-latest, macos-latest]
|
||||
include:
|
||||
- os: ubuntu-latest
|
||||
targets: x86_64-unknown-linux-gnu
|
||||
- os: windows-latest
|
||||
targets: x86_64-pc-windows-msvc
|
||||
- os: macos-latest
|
||||
targets: x86_64-apple-darwin,aarch64-apple-darwin
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v4.2.2
|
||||
|
||||
- name: Setup Node.js
|
||||
uses: actions/setup-node@v4.1.0
|
||||
with:
|
||||
node-version: '20'
|
||||
cache: 'npm'
|
||||
cache-dependency-path: 'scripts/package.json'
|
||||
|
||||
- name: Install Rust
|
||||
uses: dtolnay/rust-toolchain@stable
|
||||
with:
|
||||
targets: ${{ matrix.targets }}
|
||||
|
||||
- name: Install Linux dependencies (x86_64)
|
||||
if: runner.os == 'Linux'
|
||||
run: |
|
||||
sudo apt-get update
|
||||
sudo apt-get install -y \
|
||||
build-essential \
|
||||
protobuf-compiler \
|
||||
pkg-config \
|
||||
libssl-dev \
|
||||
openssl
|
||||
|
||||
# 安装 npm 依赖
|
||||
cd scripts && npm install && cd ..
|
||||
|
||||
# 设置 OpenSSL 环境变量
|
||||
echo "OPENSSL_DIR=/usr" >> $GITHUB_ENV
|
||||
echo "OPENSSL_LIB_DIR=/usr/lib/x86_64-linux-gnu" >> $GITHUB_ENV
|
||||
echo "OPENSSL_INCLUDE_DIR=/usr/include/openssl" >> $GITHUB_ENV
|
||||
echo "PKG_CONFIG_PATH=/usr/lib/x86_64-linux-gnu/pkgconfig" >> $GITHUB_ENV
|
||||
|
||||
# - name: Set up Docker Buildx
|
||||
# if: runner.os == 'Linux'
|
||||
# uses: docker/setup-buildx-action@v3.8.0
|
||||
|
||||
# - name: Build Linux arm64
|
||||
# if: runner.os == 'Linux'
|
||||
# run: |
|
||||
# # 启用 QEMU 支持
|
||||
# docker run --rm --privileged multiarch/qemu-user-static --reset -p yes
|
||||
|
||||
# # 创建 Dockerfile
|
||||
# cat > Dockerfile.arm64 << 'EOF'
|
||||
# FROM arm64v8/ubuntu:22.04
|
||||
|
||||
# ENV DEBIAN_FRONTEND=noninteractive
|
||||
|
||||
# RUN apt-get update && apt-get install -y \
|
||||
# build-essential \
|
||||
# curl \
|
||||
# pkg-config \
|
||||
# libssl-dev \
|
||||
# protobuf-compiler \
|
||||
# nodejs \
|
||||
# npm \
|
||||
# git \
|
||||
# && rm -rf /var/lib/apt/lists/*
|
||||
|
||||
# # 安装 Rust
|
||||
# RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
|
||||
# ENV PATH="/root/.cargo/bin:${PATH}"
|
||||
|
||||
# WORKDIR /build
|
||||
# COPY . .
|
||||
|
||||
# # 安装 npm 依赖
|
||||
# RUN cd scripts && npm install && cd ..
|
||||
|
||||
# # 构建动态链接版本
|
||||
# RUN cargo build --release
|
||||
|
||||
# # 构建静态链接版本
|
||||
# RUN RUSTFLAGS="-C target-feature=+crt-static" cargo build --release
|
||||
# EOF
|
||||
|
||||
# # 构建 arm64 版本
|
||||
# docker buildx build --platform linux/arm64 -f Dockerfile.arm64 -t builder-arm64 .
|
||||
|
||||
# # 创建临时容器
|
||||
# docker create --name temp-container builder-arm64 sh
|
||||
|
||||
# # 复制动态链接版本
|
||||
# docker cp temp-container:/build/target/release/cursor-api ./release/cursor-api-aarch64-unknown-linux-gnu
|
||||
|
||||
# # 复制静态链接版本
|
||||
# docker cp temp-container:/build/target/release/cursor-api ./release/cursor-api-static-aarch64-unknown-linux-gnu
|
||||
|
||||
# # 清理临时容器
|
||||
# docker rm temp-container
|
||||
|
||||
- name: Build Linux x86_64 (Dynamic)
|
||||
if: runner.os == 'Linux'
|
||||
run: bash scripts/build.sh
|
||||
|
||||
- name: Build Linux x86_64 (Static)
|
||||
if: runner.os == 'Linux'
|
||||
run: bash scripts/build.sh --static
|
||||
|
||||
- name: Install macOS dependencies
|
||||
if: runner.os == 'macOS'
|
||||
run: |
|
||||
brew install \
|
||||
protobuf \
|
||||
pkg-config \
|
||||
openssl@3
|
||||
echo "OPENSSL_DIR=$(brew --prefix openssl@3)" >> $GITHUB_ENV
|
||||
echo "PKG_CONFIG_PATH=$(brew --prefix openssl@3)/lib/pkgconfig" >> $GITHUB_ENV
|
||||
|
||||
- name: Install Windows dependencies
|
||||
if: runner.os == 'Windows'
|
||||
run: |
|
||||
choco install -y protoc
|
||||
choco install -y openssl
|
||||
echo "OPENSSL_DIR=C:/Program Files/OpenSSL-Win64" >> $GITHUB_ENV
|
||||
echo "PKG_CONFIG_PATH=C:/Program Files/OpenSSL-Win64/lib/pkgconfig" >> $GITHUB_ENV
|
||||
cd scripts && npm install && cd ..
|
||||
|
||||
- name: Build (Dynamic)
|
||||
if: runner.os != 'Linux' && runner.os != 'FreeBSD'
|
||||
run: bash scripts/build.sh
|
||||
|
||||
- name: Build (Static)
|
||||
if: runner.os != 'Linux' && runner.os != 'FreeBSD'
|
||||
run: bash scripts/build.sh --static
|
||||
|
||||
- name: Upload artifacts
|
||||
uses: actions/upload-artifact@v4.5.0
|
||||
with:
|
||||
name: binaries-${{ matrix.os }}
|
||||
path: release/*
|
||||
retention-days: 1
|
||||
|
||||
build-freebsd:
|
||||
name: Build FreeBSD
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v4.2.2
|
||||
|
||||
- name: Build on FreeBSD
|
||||
uses: vmactions/freebsd-vm@v1.1.5
|
||||
with:
|
||||
usesh: true
|
||||
prepare: |
|
||||
# 设置持久化的环境变量
|
||||
echo 'export SSL_CERT_FILE=/etc/ssl/cert.pem' >> /root/.profile
|
||||
echo 'export PATH="/usr/local/bin:$PATH"' >> /root/.profile
|
||||
|
||||
# 安装基础依赖
|
||||
pkg update
|
||||
pkg install -y \
|
||||
git \
|
||||
curl \
|
||||
node20 \
|
||||
www/npm \
|
||||
protobuf \
|
||||
ca_root_nss \
|
||||
bash \
|
||||
gmake \
|
||||
pkgconf \
|
||||
openssl
|
||||
|
||||
export SSL_CERT_FILE=/etc/ssl/cert.pem
|
||||
|
||||
# 克隆代码(确保在正确的目录)
|
||||
cd /root
|
||||
git clone $GITHUB_SERVER_URL/$GITHUB_REPOSITORY .
|
||||
|
||||
# 然后再进入 scripts 目录
|
||||
cd scripts && npm install && cd ..
|
||||
|
||||
# 安装 rustup 和 Rust
|
||||
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --profile minimal --default-toolchain stable
|
||||
|
||||
# 设置持久化的 Rust 环境变量
|
||||
echo '. "$HOME/.cargo/env"' >> /root/.profile
|
||||
|
||||
# 添加所需的目标支持
|
||||
. /root/.profile
|
||||
rustup target add x86_64-unknown-freebsd
|
||||
rustup component add rust-src
|
||||
|
||||
run: |
|
||||
# 加载环境变量
|
||||
. /root/.profile
|
||||
|
||||
# 构建
|
||||
echo "构建动态链接版本..."
|
||||
/usr/local/bin/bash scripts/build.sh
|
||||
|
||||
echo "构建静态链接版本..."
|
||||
/usr/local/bin/bash scripts/build.sh --static
|
||||
|
||||
- name: Upload artifacts
|
||||
uses: actions/upload-artifact@v4.5.0
|
||||
with:
|
||||
name: binaries-freebsd
|
||||
path: release/*
|
||||
retention-days: 1
|
||||
|
||||
release:
|
||||
name: Create Release
|
||||
needs: [build, build-freebsd]
|
||||
runs-on: ubuntu-latest
|
||||
permissions:
|
||||
contents: write
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v4.2.2
|
||||
|
||||
- name: Download all artifacts
|
||||
uses: actions/download-artifact@v4.1.8
|
||||
with:
|
||||
path: artifacts
|
||||
|
||||
- name: Prepare release assets
|
||||
run: |
|
||||
mkdir release
|
||||
cd artifacts
|
||||
for dir in binaries-*; do
|
||||
cp -r "$dir"/* ../release/
|
||||
done
|
||||
|
||||
- name: Generate checksums
|
||||
run: |
|
||||
cd release
|
||||
sha256sum * > SHA256SUMS.txt
|
||||
|
||||
- name: Create Release
|
||||
uses: softprops/action-gh-release@v2.2.0
|
||||
with:
|
||||
files: |
|
||||
release/*
|
||||
draft: false
|
||||
prerelease: false
|
||||
generate_release_notes: true
|
||||
fail_on_unmatched_files: true
|
||||
56
.github/workflows/docker.yml
vendored
Normal file
56
.github/workflows/docker.yml
vendored
Normal file
@@ -0,0 +1,56 @@
|
||||
name: Docker Build and Push
|
||||
|
||||
on:
|
||||
workflow_dispatch:
|
||||
# push:
|
||||
# tags:
|
||||
# - 'v*'
|
||||
|
||||
env:
|
||||
IMAGE_NAME: ${{ github.repository_owner }}/cursor-api
|
||||
|
||||
jobs:
|
||||
build-and-push:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v4.2.2
|
||||
|
||||
- name: Get version from Cargo.toml
|
||||
if: github.event_name == 'workflow_dispatch'
|
||||
id: cargo_version
|
||||
run: |
|
||||
VERSION=$(grep '^version = ' Cargo.toml | cut -d '"' -f2)
|
||||
echo "version=v${VERSION}" >> $GITHUB_OUTPUT
|
||||
|
||||
- name: Log in to Docker Hub
|
||||
uses: docker/login-action@v3.3.0
|
||||
with:
|
||||
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
||||
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
||||
|
||||
- name: Extract metadata for Docker
|
||||
id: meta
|
||||
uses: docker/metadata-action@v5.6.1
|
||||
with:
|
||||
images: ${{ env.IMAGE_NAME }}
|
||||
tags: |
|
||||
type=raw,value=${{ steps.cargo_version.outputs.version }},enable=${{ github.event_name == 'workflow_dispatch' }}
|
||||
type=ref,event=tag,enable=${{ github.event_name == 'push' }}
|
||||
|
||||
- name: Set up Docker Buildx
|
||||
uses: docker/setup-buildx-action@v3.8.0
|
||||
with:
|
||||
driver-opts: |
|
||||
image=moby/buildkit:latest
|
||||
|
||||
- name: Build and push Docker image
|
||||
uses: docker/build-push-action@v6.10.0
|
||||
with:
|
||||
context: .
|
||||
push: true
|
||||
tags: ${{ steps.meta.outputs.tags }}
|
||||
labels: ${{ steps.meta.outputs.labels }}
|
||||
cache-from: type=gha
|
||||
cache-to: type=gha,mode=max
|
||||
Reference in New Issue
Block a user