Files
lotusgen/.gitea/workflows/deploy.yaml
T
Sylphian 693a470ace
Build, Test & Deploy LotusGen / Build & Deploy Container (push) Canceled after 0s
Build, Test & Deploy LotusGen / Run Pytest & Frontend Build Test (push) Canceled after 13m32s
chore: add CI/CD for Gitea
2026-09-21 21:51:57 +07:00

90 lines
2.8 KiB
YAML

name: Build, Test & Deploy LotusGen
on:
push:
branches:
- main
- master
pull_request:
branches:
- main
- master
jobs:
# -------------------------------------------------------------
# 1. Automated Testing (Backend Pytest + Frontend Typecheck)
# -------------------------------------------------------------
test:
name: Run Pytest & Frontend Build Test
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout@v4
- name: Set up Python 3.11
uses: actions/setup-python@v5
with:
python-version: '3.11'
cache: 'pip'
- name: Install Dependencies & Run Tests
run: |
python -m pip install --upgrade pip
pip install -r backend/requirements.txt pytest
python -m pytest backend/tests/ -v
- name: Set up Node.js 20
uses: actions/setup-node@v4
with:
node-version: 20
cache: 'npm'
cache-dependency-path: frontend/package-lock.json
- name: Verify Frontend Compilation
run: |
cd frontend
npm ci
npm run build
# -------------------------------------------------------------
# 2. Continuous Deployment (Build & Recreate Container)
# -------------------------------------------------------------
deploy:
name: Build & Deploy Container
needs: test
runs-on: ubuntu-latest
# Security: Deploy ONLY on pushes to main by the repository owner
if: github.event_name == 'push' && (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master') && github.repository == 'Sylphian/lotusgen'
steps:
- name: Checkout Code
uses: actions/checkout@v4
- name: Build and Start Production Container
env:
CONTAINER_NAME: ${{ secrets.CONTAINER_NAME }}
HOST_PORT: ${{ secrets.HOST_PORT }}
DATA_DIR: ${{ secrets.DATA_DIR }}
ARTIFACTS_DIR: ${{ secrets.ARTIFACTS_DIR }}
run: |
# Create host storage directories if they don't exist
mkdir -p "$DATA_DIR" "$ARTIFACTS_DIR"
# Build the production image from repo checkout
docker build -t lotusgen-app:latest .
# Gracefully recreate container
docker stop "$CONTAINER_NAME" 2>/dev/null || true
docker rm "$CONTAINER_NAME" 2>/dev/null || true
docker run -d \
--name "$CONTAINER_NAME" \
--restart unless-stopped \
-p 127.0.0.1:${HOST_PORT}:8000 \
-v "${DATA_DIR}:/app/data" \
-v "${ARTIFACTS_DIR}:/app/artifacts" \
-e LOTUSGEN_DB_PATH=/app/data/lotusgen.db \
-e LOTUSGEN_ARTIFACTS_DIR=/app/artifacts \
lotusgen-app:latest
echo "LotusGen successfully deployed to 127.0.0.1:${HOST_PORT}"