Skip to content

Commit 6827492

Browse files
authored
Merge pull request #5 from spuerta10/feat/improve-docs
docs: Improved pipeline or tests docs
2 parents cde4f27 + 0d963a5 commit 6827492

8 files changed

Lines changed: 173 additions & 6 deletions

File tree

.github/workflows/cd-base.yml

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
# ===============================================
2+
# CI/CD Pipeline: Pull GHCR image -> Re-tag -> Push to DockerHub -> Deploy with Terraform
3+
# ===============================================
4+
# Description:
5+
# This workflow takes a Docker image from GHCR (GitHub Container Registry) generated by a PR or push,
6+
# retags it with the DockerHub username, pushes it to DockerHub, and then deploys the latest image
7+
# to Cloud Run using Terraform. It also handles initial database table creation if necessary.
8+
#
9+
# Inputs:
10+
# - deployment_env: Deployment environment (e.g., staging, production)
11+
# - image_uri: URI of the image in GHCR (e.g., ghcr.io/org/repo:tag)
12+
#
13+
# Outputs:
14+
# - dockerhub_image: URI of the retagged image pushed to DockerHub
15+
# ===============================================
16+
117
on:
218
workflow_call:
319
inputs:
@@ -9,6 +25,9 @@ on:
925
type: string
1026

1127
jobs:
28+
# -----------------------------------------------
29+
# Job: Pull image from GHCR, retag, and push to DockerHub
30+
# -----------------------------------------------
1231
pull-tag-push:
1332
runs-on: ubuntu-latest
1433
outputs:
@@ -48,8 +67,11 @@ jobs:
4867
4968
docker push ${DOCKERHUB_IMAGE}
5069
51-
echo "image_uri=${PUBLIC_IMAGE}" >> $GITHUB_OUTPUT
70+
echo "image_uri=${PUBLIC_IMAGE}" >> $GITHUB_OUTPUT # <-- output this way given that github actions will censor secrets
5271
72+
# -----------------------------------------------
73+
# Job: Deploy application to GCP using Terraform
74+
# -----------------------------------------------
5375
deploy:
5476
needs: pull-tag-push
5577
runs-on: ubuntu-latest

.github/workflows/cd-stg.yml

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,15 @@
1-
# CD pipeline for staging environment runs when PR gets merged with main branch
1+
# =====================================================
2+
# CD Pipeline: Staging Environment
3+
# =====================================================
4+
# Description:
5+
# This workflow deploys the latest register-ticket-api image
6+
# to the staging environment whenever a PR is merged into main
7+
# or when triggered manually via workflow_dispatch.
8+
#
9+
# Jobs:
10+
# - deploy-to-stg: Deploys the application using the reusable cd-base workflow
11+
# - promote-to-stg-passed: Tags the image as stg-passed after successful deployment
12+
# =====================================================
213

314
name: CD pipeline for staging environment
415

.github/workflows/ci-dev-branches.yml

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,21 @@
1-
# Static Code Analysis, runs when push to feature/**, feat/**, fix/** branches.
1+
# ===============================================
2+
# CI Workflow: Dev Branch Validations
3+
# ===============================================
4+
# Description:
5+
# This workflow runs static code analysis on development branches
6+
# to enforce code quality and style before merging into main.
7+
#
8+
# Triggers:
9+
# - Push to any branch matching feature/**, feat/**, or fix/**
10+
#
11+
# Jobs:
12+
# - static-code-analysis: Delegates to the shared workflow
13+
# ./.github/workflows/static-code-analysis.yml
14+
#
15+
# Inputs:
16+
# - coverage_artifact: Boolean flag to enable/disable coverage artifact
17+
# generation. Here set to false.
18+
# ===============================================
219

320
name: Dev branch validations
421

.github/workflows/integration-tests.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,24 @@
1+
# =====================================================
2+
# CI/CD Workflow: Run Integration Tests
3+
# =====================================================
4+
# Description:
5+
# This workflow executes integration tests for the project.
6+
# It can run in different deployment environments (local, staging, production)
7+
# and conditionally starts/stops local services using Docker Compose.
8+
#
9+
# Triggered via:
10+
# - workflow_call (called from other workflows)
11+
#
12+
# Inputs:
13+
# deployment_env: Deployment environment (e.g., local, staging, prod)
14+
#
15+
# Jobs:
16+
# - run-integration-tests:
17+
# Checks out code, installs dependencies, loads environment variables,
18+
# optionally spins up Docker Compose services for local testing,
19+
# executes integration tests, and cleans up resources.
20+
# =====================================================
21+
122
name: Run integration tests
223
on:
324
workflow_call:

.github/workflows/pr-validations.yml

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,25 @@
1-
# Static Code Analysis and test validation workflow. Runs only on pull requests targeting the main branch.
1+
# =====================================================
2+
# CI/CD Workflow: Pull Request Validations
3+
# =====================================================
4+
# Description:
5+
# This workflow runs validations on pull requests targeting the main branch.
6+
# It includes static code analysis, (optionally SonarQube analysis), integration tests,
7+
# and building & pushing Docker images to GitHub Container Registry (GHCR).
8+
#
9+
# Triggered via:
10+
# - pull_request events on the main branch
11+
#
12+
# Jobs:
13+
# - static-code-analysis:
14+
# Runs static code checks and optionally generates coverage artifacts.
15+
#
16+
# - run-integration-tests:
17+
# Executes integration tests in a specified environment. Depends on static code analysis.
18+
#
19+
# - build-and-push-register-ticket-api:
20+
# Builds the Docker image for the register-ticket-api service and pushes it to GHCR.
21+
# Depends on integration tests to ensure only tested code is pushed.
22+
# =====================================================
223

324
name: Pull Requests Validations
425

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

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,23 @@
1-
# Static Code Analysis, called when PR to main or push to feature/**, feat/**, fix/** branches.
1+
# =====================================================
2+
# CI Workflow: Static Code Analysis
3+
# =====================================================
4+
# Description:
5+
# This workflow performs static code analysis, lints, and unit tests
6+
# for Python projects. It supports generating coverage reports optionally.
7+
#
8+
# Triggered via:
9+
# - workflow_call: Can be invoked by other workflows
10+
#
11+
# Inputs:
12+
# - coverage_artifact (boolean, required):
13+
# If true, generates coverage reports and uploads them as artifacts.
14+
# If false, runs tests with console-only coverage output.
15+
#
16+
# Jobs:
17+
# - static-code-analysis:
18+
# Runs pre-commit checks, installs dependencies, executes unit tests,
19+
# and optionally uploads coverage reports.
20+
# =====================================================
221

322
name: Static Code Analysis
423
on:

.github/workflows/teardown.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,23 @@
1+
# =====================================================
2+
# CI/CD Workflow: PANIC - Destroy Infrastructure
3+
# =====================================================
4+
# Description:
5+
# This workflow is used to destroy all infrastructure for a given environment.
6+
# It is intended for emergency or complete teardown scenarios.
7+
#
8+
# Triggered via:
9+
# - workflow_dispatch: Manual trigger from GitHub UI
10+
#
11+
# Inputs:
12+
# - deployment_env (choice, required): The target environment to destroy. Options: stg, prd
13+
# - confirmation (string, required): Must be exactly "DESTROY" to confirm execution.
14+
#
15+
# Jobs:
16+
# - destroy-infrastructure:
17+
# Validates the confirmation input, initializes Terraform, selects the
18+
# appropriate workspace, and destroys all resources.
19+
# =====================================================
20+
121
name: PANIC - destroy infrastructure
222

323
on:

tests/integration/test_tickets_registration.py

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
"""
2+
Integration tests for the ticket registration API and database flow.
3+
"""
4+
15
from typing import Any
26

37
import requests
@@ -12,7 +16,17 @@ def test_register_ticket_flow(
1216
base_url: str, db_connection: connection, test_username: str = "spuertaf"
1317
) -> None:
1418
"""
15-
Tests whole ticket registration flow works as expected.
19+
Test the full ticket registration flow for a user.
20+
21+
Sends a POST request to register a ticket for the specified user, then
22+
verifies that the ticket is correctly stored in the database with
23+
expected values.
24+
25+
Args:
26+
base_url (str): Base URL of the ticket registration API.
27+
db_connection (connection): Active PostgreSQL database connection.
28+
test_username (str, optional): Username for which the ticket is registered.
29+
Defaults to "spuertaf".
1630
"""
1731
headers: dict[str, str] = {"Content-Type": "application/json"}
1832
payload: dict[str, str] = {"seat": "A12", "gate": "G1"}
@@ -59,6 +73,17 @@ def test_register_ticket_fails_when_already_registered(
5973
base_url: str,
6074
test_username: str = "juanperez", # different user so tests don't collide
6175
) -> None:
76+
"""
77+
Test that registering the same ticket twice fails.
78+
79+
Sends a POST request to register a ticket for the user, then attempts
80+
to register the same ticket again and expects an error.
81+
82+
Args:
83+
base_url (str): Base URL of the ticket registration API.
84+
test_username (str, optional): Username for which the ticket is registered.
85+
Defaults to "juanperez".
86+
"""
6287
headers: dict[str, str] = {"Content-Type": "application/json"}
6388
payload: dict[str, str] = {
6489
"seat": "B05",
@@ -78,6 +103,17 @@ def test_register_ticket_fails_when_already_registered(
78103

79104

80105
def test_invalid_ticket_registration_error(base_url: str, test_username: str = "spuertaf") -> None:
106+
"""
107+
Test that registering a ticket with invalid data returns an error.
108+
109+
Sends a POST request with invalid seat/gate values and expects the API
110+
to return an error code.
111+
112+
Args:
113+
base_url (str): Base URL of the ticket registration API.
114+
test_username (str, optional): Username for which the ticket is registered.
115+
Defaults to "spuertaf".
116+
"""
81117
headers: dict[str, str] = {"Content-Type": "application/json"}
82118
payload: dict[str, str] = {"seat": "B05", "gate": "G12"}
83119
endpoint: str = f"/api/users/{test_username}/tickets"

0 commit comments

Comments
 (0)