From 8873728a4faed5e4b69bd7a7787ad8d02f9aaed2 Mon Sep 17 00:00:00 2001 From: Francisco Penedo Alvarez Date: Tue, 31 Mar 2026 17:26:11 +0200 Subject: [PATCH] Add CI and deployment workflows for Gitea --- .gitea/workflows/ci.yml | 35 +++++++++++++++++++++++ .gitea/workflows/deploy.yml | 57 +++++++++++++++++++++++++++++++++++++ 2 files changed, 92 insertions(+) create mode 100644 .gitea/workflows/ci.yml create mode 100644 .gitea/workflows/deploy.yml diff --git a/.gitea/workflows/ci.yml b/.gitea/workflows/ci.yml new file mode 100644 index 0000000..f1ebee0 --- /dev/null +++ b/.gitea/workflows/ci.yml @@ -0,0 +1,35 @@ +name: CI + +on: + push: + branches: ["*"] + pull_request: + branches: ["*"] + +jobs: + quality-checks: + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Set up Python + uses: actions/setup-python@v4 + with: + python-version: "3.14" + + - name: Install uv + uses: astral-sh/setup-uv@v4 + with: + version: "0.11.1" + enable-cache: true + + - name: Run pre-commit hooks + run: uv run pre-commit run --all-files + + - name: Run type checking with ty + run: uv run ty + + - name: Run tests with pytest + run: uv run pytest diff --git a/.gitea/workflows/deploy.yml b/.gitea/workflows/deploy.yml new file mode 100644 index 0000000..75e727f --- /dev/null +++ b/.gitea/workflows/deploy.yml @@ -0,0 +1,57 @@ +name: Deploy + +on: + push: + branches: ["main"] + workflow_run: + workflows: ["CI"] + types: + - completed + branches: ["main"] + +jobs: + deploy: + runs-on: ubuntu-latest + # Only deploy if CI workflow succeeded + if: ${{ github.event.workflow_run.conclusion == 'success' || github.event_name == 'push' }} + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Stop existing containers + run: | + # Stop and remove existing containers if they exist + docker compose down --remove-orphans || true + + - name: Build and deploy with Docker Compose + run: | + # Build images + docker compose build + + # Deploy the stack in detached mode + export GOOGLE_BOOKS_API_KEY="${{ secrets.GOOGLE_BOOKS_API_KEY }}" + docker compose up -d + + # Wait for health checks to pass + echo "Waiting for application to be healthy..." + timeout 300 sh -c 'until docker compose ps | grep -q "healthy"; do sleep 5; done' + + - name: Verify deployment + run: | + # Check if all services are running + docker compose ps + + # Test if the application responds + sleep 10 + curl -f http://localhost:5123 || exit 1 + + echo "Deployment successful!" + + - name: Cleanup old images + run: | + # Remove dangling images to save space + docker image prune -f