fix: 移除 artifact 传递,合并 build+deploy jobs 兼容 Gitea Actions
Some checks failed
CI/CD Pipeline / Code Quality (push) Successful in 16s
CI/CD Pipeline / Unit Tests (push) Successful in 11s
CI/CD Pipeline / Build & Deploy Test (push) Has been skipped
CI/CD Pipeline / Build & Deploy Production (push) Failing after 8s

This commit is contained in:
Wang Zhuoxuan 2026-04-17 18:13:21 +08:00
parent 567613aa6b
commit d8f30e8362

View File

@ -2,8 +2,10 @@
# Duoqi API - 双分支工作流develop → main
#
# 工作流:
# develop push → quality → test → build → 自动部署测试环境
# main push → quality → test → build → 手动确认部署生产环境
# develop push → quality → test → 构建并自动部署测试环境
# main push → quality → test → 构建并手动确认部署生产环境
#
# 注意:单服务器架构,构建后直接部署,无需 artifact 传递
name: CI/CD Pipeline
@ -44,70 +46,21 @@ jobs:
- name: Run tests
run: bun run test
# ==================== 构建测试镜像 ====================
build-test:
name: Build Test Image
# ==================== 构建并部署测试环境develop 自动触发)====================
build-and-deploy-test:
name: Build & Deploy Test
runs-on: ubuntu-latest
needs: [quality, test]
if: github.ref == 'refs/heads/develop'
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Build test image
run: |
docker build --build-arg NODE_ENV=test -t duoqi-api:test .
mkdir -p /tmp/images
docker save duoqi-api:test -o /tmp/images/duoqi-api-test.tar
- name: Upload image artifact
uses: actions/upload-artifact@v4
with:
name: docker-images-test
path: /tmp/images/
retention-days: 1
# ==================== 构建生产镜像 ====================
build-prod:
name: Build Production Image
runs-on: ubuntu-latest
needs: [quality, test]
if: github.ref == 'refs/heads/main'
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Build production image
run: |
docker build -t duoqi-api:prod .
mkdir -p /tmp/images
docker save duoqi-api:prod -o /tmp/images/duoqi-api-prod.tar
- name: Upload image artifact
uses: actions/upload-artifact@v4
with:
name: docker-images-prod
path: /tmp/images/
retention-days: 1
# ==================== 部署到测试环境develop push 自动触发) ====================
deploy-test:
name: Deploy to Test
runs-on: ubuntu-latest
needs: build-test
if: github.ref == 'refs/heads/develop'
environment:
name: test
url: http://test-api.duoqi.me
steps:
- name: Download image artifact
uses: actions/download-artifact@v4
with:
name: docker-images-test
path: /tmp/images/
- name: Checkout code
uses: actions/checkout@v4
- name: Load Docker image
run: docker load -i /tmp/images/duoqi-api-test.tar
- name: Build test image
run: docker build --build-arg NODE_ENV=test -t duoqi-api:test .
- name: Deploy test environment
run: |
@ -128,24 +81,21 @@ jobs:
echo "Test environment health check failed"
exit 1
# ==================== 部署生产环境main push手动确认) ====================
deploy-prod:
name: Deploy to Production
# ==================== 构建并部署生产环境main 手动确认)====================
build-and-deploy-prod:
name: Build & Deploy Production
runs-on: ubuntu-latest
needs: build-prod
needs: [quality, test]
if: github.ref == 'refs/heads/main'
environment:
name: production
url: https://api.duoqi.me
steps:
- name: Download image artifact
uses: actions/download-artifact@v4
with:
name: docker-images-prod
path: /tmp/images/
- name: Checkout code
uses: actions/checkout@v4
- name: Load Docker image
run: docker load -i /tmp/images/duoqi-api-prod.tar
- name: Build production image
run: docker build -t duoqi-api:prod .
- name: Deploy production
run: |
@ -178,6 +128,4 @@ jobs:
- name: Cleanup
if: always()
run: |
docker image prune -f
rm -rf /tmp/images
run: docker image prune -f