95 lines
2.5 KiB
YAML
95 lines
2.5 KiB
YAML
name: CI
|
|
|
|
on:
|
|
pull_request:
|
|
branches: [main]
|
|
push:
|
|
branches: [main]
|
|
|
|
env:
|
|
REGISTRY: ghcr.io
|
|
IMAGE_NAME: ${{ github.repository }}
|
|
|
|
jobs:
|
|
pre-commit:
|
|
name: Static Analysis (pre-commit)
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
- uses: actions/setup-python@v5
|
|
with:
|
|
python-version: "3.12"
|
|
- uses: pre-commit/action@v3.0.1
|
|
tests:
|
|
name: Tests
|
|
runs-on: ubuntu-latest
|
|
needs: pre-commit
|
|
services:
|
|
postgres:
|
|
image: postgres
|
|
env:
|
|
POSTGRES_PASSWORD: postgres
|
|
options: >-
|
|
--health-cmd pg_isready
|
|
--health-interval 10s
|
|
--health-timeout 5s
|
|
--health-retries 5
|
|
ports:
|
|
- 5432:5432
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
- name: Setup Python
|
|
uses: actions/setup-python@v5
|
|
with:
|
|
python-version: "3.12"
|
|
- name: Setup poetry
|
|
uses: abatilo/actions-poetry@v2
|
|
with:
|
|
poetry-version: "1.8.3"
|
|
- name: Install dependencies
|
|
run: poetry install --with=test
|
|
- name: Run pytest
|
|
run: poetry run pytest --cov=teufa tests/
|
|
env:
|
|
DATABASE_URL: postgresql+psycopg://postgres:postgres@localhost:5432/postgres
|
|
- name: Upload coverage reports to Codecov
|
|
uses: codecov/codecov-action@v4.0.1
|
|
with:
|
|
token: ${{ secrets.CODECOV_TOKEN }}
|
|
build:
|
|
name: Build and push image
|
|
runs-on: ubuntu-latest
|
|
permissions:
|
|
packages: write
|
|
needs: tests
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
- name: Login to GitHub Container Registry
|
|
uses: docker/login-action@v3
|
|
with:
|
|
registry: ${{ env.REGISTRY }}
|
|
username: ${{ github.actor }}
|
|
password: ${{ secrets.GITHUB_TOKEN }}
|
|
- name: Generate metadata
|
|
id: meta
|
|
uses: docker/metadata-action@v5
|
|
with:
|
|
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
|
|
tags: |
|
|
type=ref,event=branch
|
|
type=ref,event=pr
|
|
type=sha
|
|
- name: Setup docker buildx
|
|
uses: docker/setup-buildx-action@v3
|
|
- name: Build image
|
|
uses: docker/build-push-action@v5
|
|
if: github.ref == 'refs/heads/main'
|
|
with:
|
|
tags: ${{ steps.meta.outputs.tags }}
|
|
labels: ${{ steps.meta.outputs.labels }}
|
|
target: prod
|
|
load: true
|
|
cache-from: type=gha
|
|
cache-to: type=gha,mode=max
|
|
push: true
|