Skip to content

Commit 700c5bd

Browse files
committed
ci: добавить GitHub Actions для CI и CD
- CI: lint, tests с coverage и проверка сборки Docker - CD: публикация Docker-образа в GHCR по тегам и вручную
1 parent f3270b2 commit 700c5bd

File tree

2 files changed

+167
-0
lines changed

2 files changed

+167
-0
lines changed

.github/workflows/cd.yml

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
name: CD
2+
3+
on:
4+
push:
5+
tags:
6+
- "v*.*.*"
7+
workflow_dispatch:
8+
9+
permissions:
10+
contents: read
11+
packages: write
12+
13+
env:
14+
REGISTRY: ghcr.io
15+
IMAGE_NAME: ${{ github.repository }}
16+
17+
jobs:
18+
publish-image:
19+
name: Publish Docker image to GHCR
20+
runs-on: ubuntu-latest
21+
steps:
22+
- name: Checkout
23+
uses: actions/checkout@v4
24+
25+
- name: Set up Docker Buildx
26+
uses: docker/setup-buildx-action@v3
27+
28+
- name: Log in to GHCR
29+
uses: docker/login-action@v3
30+
with:
31+
registry: ${{ env.REGISTRY }}
32+
username: ${{ github.actor }}
33+
password: ${{ secrets.GITHUB_TOKEN }}
34+
35+
- name: Extract metadata
36+
id: meta
37+
uses: docker/metadata-action@v5
38+
with:
39+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
40+
tags: |
41+
type=ref,event=tag
42+
type=raw,value=latest
43+
44+
- name: Build and push image
45+
uses: docker/build-push-action@v6
46+
with:
47+
context: .
48+
push: true
49+
tags: ${{ steps.meta.outputs.tags }}
50+
labels: ${{ steps.meta.outputs.labels }}
51+
cache-from: type=gha
52+
cache-to: type=gha,mode=max

.github/workflows/ci.yml

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
branches: [main]
8+
9+
concurrency:
10+
group: ci-${{ github.workflow }}-${{ github.ref }}
11+
cancel-in-progress: true
12+
13+
env:
14+
PYTHON_VERSION: "3.12"
15+
SECRET_KEY: test-secret-key-minimum-32-bytes-value
16+
DATABASE_URL: postgresql+asyncpg://test_user:test_password@localhost:5432/test_db
17+
INTEGRATION_DATABASE_URL: postgresql+asyncpg://test_user:test_password@localhost:5432/test_db
18+
REDIS_URL: redis://localhost:6379/0
19+
20+
jobs:
21+
lint:
22+
name: Ruff Lint
23+
runs-on: ubuntu-latest
24+
steps:
25+
- name: Checkout
26+
uses: actions/checkout@v4
27+
28+
- name: Setup Python
29+
uses: actions/setup-python@v5
30+
with:
31+
python-version: ${{ env.PYTHON_VERSION }}
32+
33+
- name: Setup uv
34+
uses: astral-sh/setup-uv@v6
35+
with:
36+
enable-cache: true
37+
38+
- name: Install dependencies
39+
run: uv sync --frozen --dev
40+
41+
- name: Ruff check
42+
run: uv run ruff check .
43+
44+
- name: Ruff format check
45+
run: uv run ruff format --check .
46+
47+
test:
48+
name: Tests
49+
runs-on: ubuntu-latest
50+
services:
51+
postgres:
52+
image: postgres:16-alpine
53+
env:
54+
POSTGRES_DB: test_db
55+
POSTGRES_USER: test_user
56+
POSTGRES_PASSWORD: test_password
57+
ports:
58+
- 5432:5432
59+
options: >-
60+
--health-cmd "pg_isready -U test_user -d test_db"
61+
--health-interval 10s
62+
--health-timeout 5s
63+
--health-retries 10
64+
65+
steps:
66+
- name: Checkout
67+
uses: actions/checkout@v4
68+
69+
- name: Setup Python
70+
uses: actions/setup-python@v5
71+
with:
72+
python-version: ${{ env.PYTHON_VERSION }}
73+
74+
- name: Setup uv
75+
uses: astral-sh/setup-uv@v6
76+
with:
77+
enable-cache: true
78+
79+
- name: Install dependencies
80+
run: uv sync --frozen --dev
81+
82+
- name: Run tests with coverage
83+
run: uv run pytest -q --cov=app --cov-report=term-missing --cov-report=xml --junitxml=pytest.xml
84+
85+
- name: Upload coverage report
86+
uses: actions/upload-artifact@v4
87+
with:
88+
name: coverage-xml
89+
path: coverage.xml
90+
91+
- name: Upload junit report
92+
uses: actions/upload-artifact@v4
93+
with:
94+
name: pytest-report
95+
path: pytest.xml
96+
97+
docker-build:
98+
name: Docker Build Check
99+
runs-on: ubuntu-latest
100+
needs: [lint, test]
101+
steps:
102+
- name: Checkout
103+
uses: actions/checkout@v4
104+
105+
- name: Set up Docker Buildx
106+
uses: docker/setup-buildx-action@v3
107+
108+
- name: Build image
109+
uses: docker/build-push-action@v6
110+
with:
111+
context: .
112+
push: false
113+
tags: task-manager-fastapi:ci
114+
cache-from: type=gha
115+
cache-to: type=gha,mode=max

0 commit comments

Comments
 (0)