Skip to content

Commit 86fe8f7

Browse files
authored
Merge pull request #3 from spuerta10/feat/ci-pipelines
Feat/ci pipelines
2 parents a0c4af4 + eae84d3 commit 86fe8f7

13 files changed

Lines changed: 245 additions & 5 deletions

.env.test

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# --- Postgres Config ---
2+
DB_HOST=postgres
3+
DB_PORT=5432
4+
DB_USER=test
5+
DB_PASSWORD=TEST # pragma: allowlist secret
6+
DB_NAME=event_access
7+
8+
# --- Integration tests config ---
9+
POSTGRES_HOST=localhost
10+
BASE_URL=http://localhost:8000
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
name: Run integration tests
2+
on:
3+
workflow_call:
4+
inputs:
5+
deployment_env:
6+
required: true
7+
type: string
8+
description: "Deployment environment (e.g., pr, staging, prod)"
9+
10+
jobs:
11+
run-integration-tests:
12+
runs-on: ubuntu-latest
13+
steps:
14+
- uses: actions/checkout@v4
15+
16+
- name: Install uv
17+
uses: astral-sh/setup-uv@v5
18+
19+
- name: Install dependencies
20+
run: |
21+
uv venv
22+
uv pip install -r requirements.txt
23+
24+
- name: Load env vars from .env.test file
25+
uses: xom9ikk/dotenv@v2
26+
with:
27+
path: . # project's root folder
28+
mode: ${{ inputs.deployment_env == 'local' && 'test' || inputs.env_filename }} # .env.deployment_env
29+
30+
- name: Start services (docker-compose)
31+
if: ${{ inputs.deployment_env == 'local' }}
32+
run: docker compose -f docker/docker-compose.yml up --build -d
33+
34+
- name: Wait for pSQL to be ready
35+
if: ${{ inputs.deployment_env == 'local' }}
36+
run: sleep 30
37+
38+
- name: Execute base integration tests
39+
run: uv run pytest tests/integration
40+
41+
- name: Destroy Docker resources
42+
if: ${{ inputs.deployment_env == 'local' }}
43+
run: docker compose -f docker/docker-compose.yml down

.github/workflows/pr-validations.yml

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,56 @@ jobs:
1212
uses: ./.github/workflows/static-code-analysis.yml
1313
with:
1414
coverage_artifact: true
15+
16+
#sonarqube-analysis:
17+
#needs: static-code-analysis
18+
#runs-on: ubuntu-latest
19+
#steps:
20+
#- uses: actions/checkout@v4
21+
22+
#- name: Download coverage report
23+
#uses: actions/download-artifact@v4
24+
#with:
25+
#name: coverage-report
26+
#path: coverage-artifacts # cov artifacts will be on coverage-artifacts/ folder
27+
28+
#- name: Run SonarQube Scan
29+
#uses: SonarSource/sonarqube-scan-action@v5.0.0
30+
#env:
31+
#GITHUB_TOKEN: ${{ }}
32+
#SONAR_TOKEN: ${{ }}
33+
#with:
34+
#args: >
35+
#-Dsonar.python.coverage.reportPaths=coverage-artifacts/coverage.xml
36+
37+
run-integration-tests:
38+
needs: static-code-analysis # TODO: need sonarqube
39+
uses: ./.github/workflows/integration-tests.yml
40+
with:
41+
deployment_env: 'local'
42+
43+
build-and-push-register-ticket-api:
44+
needs: run-integration-tests
45+
runs-on: ubuntu-latest
46+
permissions:
47+
contents: read
48+
packages: write # lets write Docker image to GHCR
49+
steps:
50+
- uses: actions/checkout@v4
51+
52+
- name: Log in Github container registry
53+
uses: docker/login-action@v3
54+
with:
55+
registry: ghcr.io
56+
username: ${{ github.actor }}
57+
password: ${{ secrets.GITHUB_TOKEN }}
58+
59+
- name: Build and push Docker image to GHCR
60+
uses: docker/build-push-action@v5
61+
with:
62+
context: .
63+
file: docker/Dockerfile.register-ticket-api
64+
push: true
65+
tags: |
66+
ghcr.io/${{ github.repository_owner }}/register-ticket-api:latest
67+
ghcr.io/${{ github.repository_owner }}/register-ticket-api:${{ github.sha }}

.github/workflows/static-code-analysis.yml

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,19 @@ jobs:
2727
2828
- name: Run unit tests (with coverage report)
2929
if: ${{ inputs.coverage_artifact }}
30-
run: uv run pytest --cov=./src --cov-report=xml --cov-report=term
30+
run: uv run pytest tests/unit --cov=./src --cov-report=xml --cov-report=term
31+
32+
- name: Upload coverage report
33+
uses: actions/upload-artifact@v4
34+
if: ${{ inputs.coverage_artifact }}
35+
with:
36+
name: coverage-report
37+
path:
38+
coverage.xml
39+
.coverage
40+
htmlcov/
3141

3242
- name: Run unit tests (console-only coverage)
3343
if: ${{ !inputs.coverage_artifact }}
34-
run: uv run pytest --cov=./src --cov-report=term-missing
44+
run: uv run pytest tests/unit --cov=./src --cov-report=term-missing
3545

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
__pycache__*
2-
*.env*
2+
*.env
33
.mypy_cache/
44
.pytest_cache/
55
.ruff_cache/

.pre-commit-config.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ repos:
3232
- id: mypy
3333
args:
3434
- --config-file=.code_quality/mypy.ini
35+
additional_dependencies:
36+
- types-requests
3537

3638
- repo: https://github.com/Yelp/detect-secrets
3739
rev: v1.5.0

docker/Dockerfile.register-ticket-api

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ FROM python:3.11-slim
22

33
WORKDIR /app
44

5-
COPY .env .
65
COPY requirements.txt .
76

87
RUN pip install --no-cache-dir -r requirements.txt

docker/docker-compose.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,12 @@ services:
1919
build:
2020
context: .. # root folder
2121
dockerfile: docker/Dockerfile.register-ticket-api
22+
environment:
23+
DB_HOST: ${DB_HOST}
24+
DB_PORT: ${DB_PORT}
25+
DB_USER: ${DB_USER}
26+
DB_PASSWORD: ${DB_PASSWORD}
27+
DB_NAME: ${DB_NAME}
2228
ports:
2329
- "8000:8000"
2430
depends_on:

pytest.ini

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
[pytest]
22
pythonpath = src
3-
testpaths = tests
3+
testpaths =
4+
tests/unit
5+
tests/integration
46
# avoid marking each async test
57
asyncio_mode = auto

requirements.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ anyio==4.11.0
33
asyncpg==0.30.0
44
certifi==2025.8.3
55
cfgv==3.4.0
6+
charset-normalizer==3.4.4
67
click==8.3.0
78
coverage==7.10.7
89
distlib==0.4.0
@@ -21,6 +22,7 @@ packaging==25.0
2122
platformdirs==4.5.0
2223
pluggy==1.6.0
2324
pre-commit==4.3.0
25+
psycopg2-binary==2.9.11
2426
pydantic==2.11.9
2527
pydantic-core==2.33.2
2628
pydantic-settings==2.10.1
@@ -32,6 +34,7 @@ pytest-cov==7.0.0
3234
python-dateutil==2.9.0.post0
3335
python-dotenv==1.1.1
3436
pyyaml==6.0.3
37+
requests==2.32.5
3538
six==1.17.0
3639
sniffio==1.3.1
3740
starlette==0.48.0

0 commit comments

Comments
 (0)