Skip to content
Closed
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
99 changes: 99 additions & 0 deletions .github/workflows/deploy-backend.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
name: Backend CI/CD

on:
push:
branches: [main]
paths:
- '**.go'
- 'go.mod'
- 'go.sum'
- 'VERSION'
- 'deploy/**'
- '.github/workflows/deploy-backend.yml'
workflow_dispatch:

# 防止同时部署
concurrency:
group: backend-${{ github.ref }}
cancel-in-progress: true

env:
GO_VERSION: '1.23'
API_DOMAIN: 'api.4aicode.com'
BACKEND_PORT: '3002'
BACKEND_HOST: '127.0.0.1'
SSL_EMAIL: 'ceo@richcalls.xyz'

jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: ${{ env.GO_VERSION }}

- name: Run tests
run: go test ./... -v
continue-on-error: true

- name: Slack 通知
if: always()
uses: forecho/slack-deploy-action@v1
with:
slack_bot_token: ${{ secrets.SLACK_BOT_TOKEN }}
slack_channel_id: ${{ secrets.SLACK_CHANNEL_ID }}
language: zh
service_name: 后端测试

build-and-deploy:
needs: test
runs-on: ubuntu-latest
if: github.event_name == 'push' && github.ref == 'refs/heads/main'

steps:
- uses: actions/checkout@v4

- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: ${{ env.GO_VERSION }}

- name: 编译
run: |
VERSION=$(cat VERSION 2>/dev/null || echo "dev")
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build \
-ldflags "-s -w -X 'github.com/QuantumNous/new-api/common.Version=${VERSION}'" \
-o new-api

- name: 上传到服务器
uses: appleboy/scp-action@v0.1.7
with:
host: ${{ secrets.DEPLOY_HOST }}
username: ${{ secrets.DEPLOY_USER }}
key: ${{ secrets.DEPLOY_SSH_KEY }}
source: "new-api,deploy/"
target: "/tmp/new-api-deploy/"
strip_components: 0

- name: 执行部署
uses: appleboy/ssh-action@v1
with:
host: ${{ secrets.DEPLOY_HOST }}
username: ${{ secrets.DEPLOY_USER }}
key: ${{ secrets.DEPLOY_SSH_KEY }}
script: |
cd /tmp/new-api-deploy
chmod +x deploy/deploy.sh
sudo ./deploy/deploy.sh "/tmp/new-api-deploy" "${{ env.API_DOMAIN }}" "${{ env.BACKEND_PORT }}" "${{ env.BACKEND_HOST }}" "${{ env.SSL_EMAIL }}"

- name: Slack 通知
if: always()
uses: forecho/slack-deploy-action@v1
with:
slack_bot_token: ${{ secrets.SLACK_BOT_TOKEN }}
slack_channel_id: ${{ secrets.SLACK_CHANNEL_ID }}
language: zh
service_name: 后端部署
102 changes: 102 additions & 0 deletions .github/workflows/deploy-web.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
name: Frontend CI/CD

on:
push:
branches: [main]
paths:
- 'web/**'
- '.github/workflows/deploy-web.yml'
pull_request:
branches: [main]
paths:
- 'web/**'

permissions:
contents: read
deployments: write
pull-requests: write

env:
VITE_REACT_APP_SERVER: 'https://api.4aicode.com'

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
cache: 'npm'
cache-dependency-path: web/package-lock.json

- name: 安装依赖
working-directory: ./web
run: npm ci

- name: 类型检查
working-directory: ./web
run: npm run type-check 2>/dev/null || true
continue-on-error: true

- name: 构建
working-directory: ./web
run: npm run build

- name: 保存构建产物
uses: actions/upload-artifact@v4
with:
name: web-dist
path: web/dist

- name: Slack 通知
if: always()
uses: forecho/slack-deploy-action@v1
with:
slack_bot_token: ${{ secrets.SLACK_BOT_TOKEN }}
slack_channel_id: ${{ secrets.SLACK_CHANNEL_ID }}
language: zh
service_name: 前端构建

deploy:
needs: build
runs-on: ubuntu-latest
if: github.event_name == 'push' && github.ref == 'refs/heads/main'

steps:
- uses: actions/checkout@v4

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
cache: 'npm'
cache-dependency-path: web/package-lock.json

- name: 安装依赖
working-directory: ./web
run: npm ci

- name: 构建
working-directory: ./web
run: npm run build

- name: 部署到 Cloudflare Pages
uses: cloudflare/pages-action@v1
with:
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
projectName: 4aicode
directory: web/dist
gitHubToken: ${{ secrets.GITHUB_TOKEN }}

- name: Slack 通知
if: always()
uses: forecho/slack-deploy-action@v1
with:
slack_bot_token: ${{ secrets.SLACK_BOT_TOKEN }}
slack_channel_id: ${{ secrets.SLACK_CHANNEL_ID }}
language: zh
service_name: 前端部署
179 changes: 0 additions & 179 deletions .github/workflows/docker-image-alpha.yml

This file was deleted.

Loading