96 lines
2.9 KiB
YAML
96 lines
2.9 KiB
YAML
# 与 .github/workflows/build-deploy.yml 保持一致,供参考或复制到 .github/workflows/
|
|
# 推送 main 时:测试后端 → 构建并推送 backend/admin 镜像到 ghcr.io
|
|
name: Build and Deploy
|
|
|
|
on:
|
|
push:
|
|
branches: [main]
|
|
|
|
env:
|
|
REGISTRY: ghcr.io
|
|
|
|
jobs:
|
|
build-backend:
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
- name: Set up Docker Buildx
|
|
uses: docker/setup-buildx-action@v3
|
|
- name: Log in to Container Registry
|
|
uses: docker/login-action@v3
|
|
with:
|
|
registry: ${{ env.REGISTRY }}
|
|
username: ${{ github.actor }}
|
|
password: ${{ secrets.GITHUB_TOKEN }}
|
|
- name: Build and push backend
|
|
uses: docker/build-push-action@v6
|
|
with:
|
|
context: ./backend
|
|
file: ./backend/Dockerfile
|
|
push: true
|
|
tags: |
|
|
${{ env.REGISTRY }}/${{ github.repository_owner }}/wecom-ai-backend:latest
|
|
${{ env.REGISTRY }}/${{ github.repository_owner }}/wecom-ai-backend:${{ github.sha }}
|
|
|
|
build-admin:
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
- name: Set up Docker Buildx
|
|
uses: docker/setup-buildx-action@v3
|
|
- name: Log in to Container Registry
|
|
uses: docker/login-action@v3
|
|
with:
|
|
registry: ${{ env.REGISTRY }}
|
|
username: ${{ github.actor }}
|
|
password: ${{ secrets.GITHUB_TOKEN }}
|
|
- name: Build and push admin
|
|
uses: docker/build-push-action@v6
|
|
with:
|
|
context: ./admin
|
|
file: ./admin/Dockerfile
|
|
push: true
|
|
tags: |
|
|
${{ env.REGISTRY }}/${{ github.repository_owner }}/wecom-ai-admin:latest
|
|
${{ env.REGISTRY }}/${{ github.repository_owner }}/wecom-ai-admin:${{ github.sha }}
|
|
|
|
test-backend:
|
|
runs-on: ubuntu-latest
|
|
services:
|
|
postgres:
|
|
image: postgres:16-alpine
|
|
env:
|
|
POSTGRES_USER: wecom
|
|
POSTGRES_PASSWORD: wecom_secret
|
|
POSTGRES_DB: wecom_ai
|
|
ports:
|
|
- 5432:5432
|
|
options: >-
|
|
--health-cmd pg_isready
|
|
--health-interval 10s
|
|
--health-timeout 5s
|
|
--health-retries 5
|
|
env:
|
|
DATABASE_URL: postgresql+asyncpg://wecom:wecom_secret@localhost:5432/wecom_ai
|
|
DATABASE_URL_SYNC: postgresql://wecom:wecom_secret@localhost:5432/wecom_ai
|
|
JWT_SECRET: test-secret
|
|
WECOM_TOKEN: test
|
|
WECOM_ENCODING_AES_KEY: abcdefghijklmnopqrstuvwxyz0123456789ABCDEFG
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
- uses: actions/setup-python@v5
|
|
with:
|
|
python-version: "3.12"
|
|
- name: Install dependencies
|
|
run: |
|
|
cd backend
|
|
pip install -r requirements.txt
|
|
- name: Run migrations
|
|
run: |
|
|
cd backend
|
|
alembic upgrade head
|
|
- name: Pytest
|
|
run: |
|
|
cd backend
|
|
pytest tests/ -v --tb=short
|