Initial commit: FunConnect project with server, relay, client and admin panel

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-02-24 20:56:36 +08:00
parent eb6e901440
commit b6891483ae
167 changed files with 16147 additions and 106 deletions

235
.github/workflows/ci.yml vendored Normal file
View File

@@ -0,0 +1,235 @@
name: CI
on:
push:
branches: [main, develop]
pull_request:
branches: [main]
env:
CARGO_TERM_COLOR: always
RUST_BACKTRACE: 1
jobs:
# 检查代码格式和 lint
check:
name: Check & Lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
with:
components: rustfmt, clippy
- name: Cache cargo
uses: Swatinem/rust-cache@v2
- name: Check format
run: cargo fmt --all -- --check
- name: Clippy
run: cargo clippy --all-targets --all-features -- -D warnings
# 测试服务端
test-server:
name: Test Server
runs-on: ubuntu-latest
services:
postgres:
image: postgres:15
env:
POSTGRES_USER: funmc
POSTGRES_PASSWORD: test_password
POSTGRES_DB: funmc_test
ports:
- 5432:5432
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
steps:
- uses: actions/checkout@v4
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
- name: Cache cargo
uses: Swatinem/rust-cache@v2
- name: Install sqlx-cli
run: cargo install sqlx-cli --no-default-features --features postgres
- name: Run migrations
run: sqlx database create && sqlx migrate run
working-directory: server
env:
DATABASE_URL: postgres://funmc:test_password@localhost/funmc_test
- name: Run tests
run: cargo test -p funmc-server
env:
DATABASE_URL: postgres://funmc:test_password@localhost/funmc_test
JWT_SECRET: test_secret_key_for_ci
# 构建服务端
build-server:
name: Build Server
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
- name: Cache cargo
uses: Swatinem/rust-cache@v2
- name: Build server
run: cargo build --release -p funmc-server
- name: Build relay
run: cargo build --release -p funmc-relay-server
- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
name: server-linux
path: |
target/release/funmc-server
target/release/funmc-relay-server
# 构建客户端 (多平台)
build-client:
name: Build Client (${{ matrix.platform }})
needs: [check]
strategy:
fail-fast: false
matrix:
include:
- platform: ubuntu-22.04
target: x86_64-unknown-linux-gnu
name: linux
- platform: windows-latest
target: x86_64-pc-windows-msvc
name: windows
- platform: macos-latest
target: aarch64-apple-darwin
name: macos-arm64
- platform: macos-latest
target: x86_64-apple-darwin
name: macos-x64
runs-on: ${{ matrix.platform }}
steps:
- uses: actions/checkout@v4
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ matrix.target }}
- name: Install Node.js
uses: actions/setup-node@v4
with:
node-version: 20
- name: Install dependencies (Ubuntu)
if: matrix.platform == 'ubuntu-22.04'
run: |
sudo apt-get update
sudo apt-get install -y libwebkit2gtk-4.1-dev libappindicator3-dev librsvg2-dev patchelf
- name: Cache cargo
uses: Swatinem/rust-cache@v2
- name: Install frontend dependencies
run: npm install
working-directory: client/ui
- name: Build frontend
run: npm run build
working-directory: client/ui
- name: Build client
run: cargo build --release --target ${{ matrix.target }}
working-directory: client
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: client-${{ matrix.name }}
path: client/target/${{ matrix.target }}/release/funmc-client*
# 构建 Docker 镜像
build-docker:
name: Build Docker Image
runs-on: ubuntu-latest
needs: [test-server]
if: github.ref == 'refs/heads/main'
steps:
- uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build and push server
uses: docker/build-push-action@v5
with:
context: .
file: ./Dockerfile.server
push: true
tags: |
mofangfang/funmc-server:latest
mofangfang/funmc-server:${{ github.sha }}
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Build and push relay
uses: docker/build-push-action@v5
with:
context: .
file: ./Dockerfile.relay
push: true
tags: |
mofangfang/funmc-relay:latest
mofangfang/funmc-relay:${{ github.sha }}
cache-from: type=gha
cache-to: type=gha,mode=max
# 发布 Release
release:
name: Create Release
runs-on: ubuntu-latest
needs: [build-server, build-client, build-docker]
if: startsWith(github.ref, 'refs/tags/v')
steps:
- uses: actions/checkout@v4
- name: Download all artifacts
uses: actions/download-artifact@v4
with:
path: artifacts
- name: Create Release
uses: softprops/action-gh-release@v1
with:
files: |
artifacts/**/*
draft: false
prerelease: false
generate_release_notes: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}