diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..c997f7d --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,108 @@ +name: CI + +on: + pull_request: + branches: [main] + push: + branches: [main] + +permissions: + contents: read + pull-requests: read + +jobs: + commitlint: + name: PR Title (Conventional Commits) + runs-on: ubuntu-latest + if: github.event_name == 'pull_request' + steps: + - name: Validate PR title + uses: amannn/action-semantic-pull-request@v5 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + types: | + feat + fix + docs + style + refactor + perf + test + build + ci + chore + revert + + lint: + name: Lint & Format + runs-on: ubuntu-latest + defaults: + run: + working-directory: backend + steps: + - uses: actions/checkout@v4 + + - name: Install uv + uses: astral-sh/setup-uv@v5 + with: + enable-cache: true + + - name: Set up Python + run: uv python install 3.12 + + - name: Install dependencies + run: uv sync --dev + + - name: Ruff lint + run: uv run ruff check src/ + + - name: Ruff format check + run: uv run ruff format --check src/ + + test: + name: Tests + runs-on: ubuntu-latest + defaults: + run: + working-directory: backend + services: + db: + image: postgres:16-alpine + env: + POSTGRES_USER: foresight + POSTGRES_PASSWORD: foresight + POSTGRES_DB: foresight_db + ports: + - 5432:5432 + options: >- + --health-cmd "pg_isready -U foresight -d foresight_db" + --health-interval 5s + --health-timeout 5s + --health-retries 5 + env: + DATABASE_URL: postgresql+asyncpg://foresight:foresight@localhost:5432/foresight_db + steps: + - uses: actions/checkout@v4 + + - name: Install uv + uses: astral-sh/setup-uv@v5 + with: + enable-cache: true + + - name: Set up Python + run: uv python install 3.12 + + - name: Install dependencies + run: uv sync --dev + + - name: Run migrations + run: uv run alembic upgrade head + + - name: Pytest + # exit code 5 = no tests collected; treat as success until tests exist + run: | + code=0 + uv run pytest -q || code=$? + if [ "$code" -eq 5 ]; then echo "No tests collected yet."; exit 0; fi + exit $code