From 22b60c1716e755f182545904c05f0c41b5f63200 Mon Sep 17 00:00:00 2001 From: Hera Zhao Date: Mon, 6 Apr 2026 21:22:51 +0000 Subject: [PATCH] Split CI: tests on hera, deploy on oci MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - test.yml: unit + e2e + build on 'test' runner (hera) - Vitest results + Cypress videos/screenshots as artifacts - Auto starts/stops backend + frontend for E2E - preview.yml: test on hera → deploy on oci (sequential) - deploy.yml: test on hera → deploy-prod on oci Co-Authored-By: Claude Opus 4.6 (1M context) --- .gitea/workflows/deploy.yml | 16 +++++--- .gitea/workflows/preview.yml | 16 ++++---- .gitea/workflows/test.yml | 77 +++++++++++++++++++++++++++++++++--- 3 files changed, 91 insertions(+), 18 deletions(-) diff --git a/.gitea/workflows/deploy.yml b/.gitea/workflows/deploy.yml index ba270ec..bed5e47 100644 --- a/.gitea/workflows/deploy.yml +++ b/.gitea/workflows/deploy.yml @@ -4,13 +4,19 @@ on: branches: [main] jobs: + test: + runs-on: test + steps: + - uses: actions/checkout@v4 + - name: Unit tests + run: cd frontend && npm ci && npx vitest run + - name: Build check + run: cd frontend && npm run build + deploy: + needs: test runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - - - name: Unit tests - run: cd frontend && npm ci && npm run test:unit - - - name: Deploy + - name: Deploy Production run: python3 scripts/deploy-preview.py deploy-prod diff --git a/.gitea/workflows/preview.yml b/.gitea/workflows/preview.yml index 534e05d..3bec4cd 100644 --- a/.gitea/workflows/preview.yml +++ b/.gitea/workflows/preview.yml @@ -4,18 +4,22 @@ on: types: [opened, synchronize, reopened, closed] jobs: + test: + if: github.event.action != 'closed' + runs-on: test + steps: + - uses: actions/checkout@v4 + - name: Unit tests + run: cd frontend && npm ci && npx vitest run + deploy-preview: if: github.event.action != 'closed' + needs: test runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - - - name: Unit tests - run: cd frontend && npm ci && npm run test:unit - - name: Deploy Preview run: python3 scripts/deploy-preview.py deploy ${{ github.event.pull_request.number }} - - name: Comment PR env: GIT_TOKEN: ${{ secrets.GIT_TOKEN }} @@ -32,10 +36,8 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - - name: Teardown run: python3 scripts/deploy-preview.py teardown ${{ github.event.pull_request.number }} - - name: Comment PR env: GIT_TOKEN: ${{ secrets.GIT_TOKEN }} diff --git a/.gitea/workflows/test.yml b/.gitea/workflows/test.yml index 2c0dd9c..8be6ab6 100644 --- a/.gitea/workflows/test.yml +++ b/.gitea/workflows/test.yml @@ -2,16 +2,81 @@ name: Test on: [push] jobs: - test: - runs-on: ubuntu-latest + unit-test: + runs-on: test steps: - uses: actions/checkout@v4 - name: Install dependencies run: cd frontend && npm ci - - name: Unit tests - run: cd frontend && npm run test:unit + - name: Run unit tests + run: cd frontend && npx vitest run --reporter=verbose --reporter=json --outputFile=test-results/vitest.json 2>&1 | tee test-results/vitest.log + shell: bash - - name: Build check - run: cd frontend && npm run build + - name: Upload unit test results + if: always() + uses: actions/upload-artifact@v4 + with: + name: unit-test-results + path: frontend/test-results/ + retention-days: 14 + + e2e-test: + runs-on: test + needs: unit-test + steps: + - uses: actions/checkout@v4 + + - name: Install frontend dependencies + run: cd frontend && npm ci + + - name: Install backend dependencies + run: python3 -m venv .venv && . .venv/bin/activate && pip install -q -r backend/requirements.txt + + - name: Start backend + run: | + . .venv/bin/activate + DB_PATH=/tmp/ci_oil_test_$$.db FRONTEND_DIR=/dev/null \ + nohup uvicorn backend.main:app --port 8000 > /tmp/backend.log 2>&1 & + sleep 3 + curl -sf http://localhost:8000/api/version + + - name: Start frontend + run: | + cd frontend && nohup npx vite --port 5173 > /tmp/frontend.log 2>&1 & + sleep 3 + curl -sf -o /dev/null http://localhost:5173/ + + - name: Run E2E tests + run: | + cd frontend + npx cypress run \ + --spec "$(ls cypress/e2e/*.cy.js | grep -v demo | grep -v visual | grep -v check | tr '\n' ',')" \ + --config video=true,screenshotOnRunFailure=true \ + 2>&1 | tee cypress/test-results.log + + - name: Upload E2E results + if: always() + uses: actions/upload-artifact@v4 + with: + name: e2e-test-results + path: | + frontend/cypress/videos/ + frontend/cypress/screenshots/ + frontend/cypress/test-results.log + retention-days: 14 + + - name: Cleanup + if: always() + run: | + pkill -f "uvicorn backend" || true + pkill -f "node.*vite" || true + rm -f /tmp/ci_oil_test_*.db + + build-check: + runs-on: test + steps: + - uses: actions/checkout@v4 + - name: Build frontend + run: cd frontend && npm ci && npm run build