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
4 changes: 4 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@
# 会话密钥
# SESSION_SECRET=random_string

# Cookie 设置(前后端跨域部署时需要配置)
# COOKIE_SAME_SITE=none # 可选值: strict(默认), lax, none(跨域部署必须设为 none)
# COOKIE_SECURE=true # SameSite=none 时会自动开启,HTTPS 环境建议开启

# 其他配置
# 生成默认token
# GENERATE_DEFAULT_TOKEN=false
Expand Down
116 changes: 116 additions & 0 deletions .github/workflows/deploy-backend.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
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'
VITE_REACT_APP_SERVER_URL: 'https://api.4aicode.com'

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

- name: Setup Bun
uses: oven-sh/setup-bun@v2

- name: 构建前端(Go embed 依赖)
working-directory: ./web
run: bun install --frozen-lockfile && bun run build

- 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
Comment on lines +46 to +48

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

🧩 Analysis chain

🏁 Script executed:

find . -name "deploy-backend.yml" -type f

Repository: QuantumNous/new-api

Length of output: 101


🏁 Script executed:

cat -n .github/workflows/deploy-backend.yml

Repository: QuantumNous/new-api

Length of output: 3993


Don't let failed tests still deploy to main.

Line 48 turns the test step into a soft failure, so the build-and-deploy job at line 61 can still publish a backend after go test fails. That removes the only deployment gate in this workflow.

Suggested fix
       - name: Run tests
         run: go test ./... -v
-        continue-on-error: true
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
- name: Run tests
run: go test ./... -v
continue-on-error: true
- name: Run tests
run: go test ./... -v
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In @.github/workflows/deploy-backend.yml around lines 46 - 48, The test step
named "Run tests" currently uses "continue-on-error: true", which allows
downstream "build-and-deploy" to run despite failing tests; remove
"continue-on-error: true" (or set it to false) so the workflow fails on test
failures and ensure the deploy job explicitly depends on the test job (add
"needs: <test_job_id>" to the "build-and-deploy" job) so deployment only runs
when the test job succeeds.


- name: Slack 通知
if: always()
continue-on-error: true
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: Setup Bun
uses: oven-sh/setup-bun@v2

- name: 构建前端(Go embed 依赖)
working-directory: ./web
run: bun install --frozen-lockfile && bun run build

- 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()
continue-on-error: true
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: 后端部署
91 changes: 91 additions & 0 deletions .github/workflows/deploy-web.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
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_URL: 'https://api.4aicode.com'

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

- name: Setup Bun
uses: oven-sh/setup-bun@v2

- name: 安装依赖
working-directory: ./web
run: bun install --frozen-lockfile

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

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

- name: Slack 通知
if: always()
continue-on-error: true
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 Bun
uses: oven-sh/setup-bun@v2

- name: 安装依赖
working-directory: ./web
run: bun install --frozen-lockfile

- name: 构建
working-directory: ./web
run: bun 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()
continue-on-error: true
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