Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*.sh text eol=lf
*.yml text eol=lf
*.yaml text eol=lf
110 changes: 110 additions & 0 deletions .github/workflows/c1-baseline.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
name: C1 - Baseline Pipeline

on:
workflow_dispatch:
push:
branches:
- feature/c1-baseline-pipeline

env:
SCENARIO: C1-baseline
RESULTS_FILE: analysis/raw/c1_baseline_run.csv
IMAGE_NAME: tcc-devsecops-api:local
CLUSTER_NAME: tcc-devsecops

jobs:
c1-baseline:
name: C1 baseline
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v5

- name: Prepare results CSV
run: |
mkdir -p analysis/raw
echo "WORKFLOW_START_SECONDS=$(date +%s)" >> "$GITHUB_ENV"
echo "WORKFLOW_START_TIMESTAMP=$(date -u +"%Y-%m-%dT%H:%M:%SZ")" >> "$GITHUB_ENV"
echo "scenario,run_id,run_number,commit_sha,step_name,start_timestamp,end_timestamp,duration_seconds,status" > "$RESULTS_FILE"

- name: Setup Python
uses: actions/setup-python@v6
with:
python-version: "3.12"

- name: Make measurement script executable
run: chmod +x ci/scripts/measure_step.sh

- name: Install Python dependencies
run: |
./ci/scripts/measure_step.sh "install_dependencies" "$RESULTS_FILE" \
python -m pip install -r app/requirements.txt

- name: Run unit tests
run: |
./ci/scripts/measure_step.sh "unit_tests" "$RESULTS_FILE" \
python -m pytest app -v

- name: Build Docker image
run: |
./ci/scripts/measure_step.sh "docker_build" "$RESULTS_FILE" \
docker build -t "$IMAGE_NAME" ./app

- name: Install kind
run: |
curl -Lo ./kind https://kind.sigs.k8s.io/dl/v0.30.0/kind-linux-amd64
chmod +x ./kind
sudo mv ./kind /usr/local/bin/kind
kind version

- name: Create local Kubernetes cluster
run: |
kind create cluster --name "$CLUSTER_NAME" --config infra/kind/kind-cluster.yaml
kubectl cluster-info
kubectl get nodes

- name: Deploy to Kubernetes
run: |
./ci/scripts/measure_step.sh "kubernetes_deploy" "$RESULTS_FILE" \
bash -c 'kind load docker-image "$IMAGE_NAME" --name "$CLUSTER_NAME" && kubectl apply -f infra/k8s/namespace.yaml && kubectl apply -f infra/k8s/deployment.yaml && kubectl apply -f infra/k8s/service.yaml && kubectl rollout status deployment/tcc-api -n app --timeout=120s'

- name: Smoke test Kubernetes deployment
run: |
./ci/scripts/measure_step.sh "kubernetes_smoke_test" "$RESULTS_FILE" \
bash -c 'kubectl port-forward svc/tcc-api 8000:80 -n app > /tmp/port-forward.log 2>&1 & PF_PID=$!; sleep 5; curl -fsS http://localhost:8000/health; kill $PF_PID'

- name: Append workflow total duration
if: always()
run: |
WORKFLOW_END_TIMESTAMP="$(date -u +"%Y-%m-%dT%H:%M:%SZ")"
WORKFLOW_END_SECONDS="$(date +%s)"
WORKFLOW_DURATION_SECONDS=$((WORKFLOW_END_SECONDS - WORKFLOW_START_SECONDS))
echo "${SCENARIO},${GITHUB_RUN_ID},${GITHUB_RUN_NUMBER},${GITHUB_SHA},workflow_total,${WORKFLOW_START_TIMESTAMP},${WORKFLOW_END_TIMESTAMP},${WORKFLOW_DURATION_SECONDS},success" >> "$RESULTS_FILE"

- name: Show collected metrics
if: always()
run: |
echo "Collected C1 baseline metrics:"
cat "$RESULTS_FILE"

- name: Write GitHub Actions summary
if: always()
run: |
echo "## C1 - Baseline Pipeline" >> "$GITHUB_STEP_SUMMARY"
echo "" >> "$GITHUB_STEP_SUMMARY"
echo "Scenario: $SCENARIO" >> "$GITHUB_STEP_SUMMARY"
echo "" >> "$GITHUB_STEP_SUMMARY"
echo "### Collected metrics" >> "$GITHUB_STEP_SUMMARY"
echo "" >> "$GITHUB_STEP_SUMMARY"
echo '```csv' >> "$GITHUB_STEP_SUMMARY"
cat "$RESULTS_FILE" >> "$GITHUB_STEP_SUMMARY"
echo '```' >> "$GITHUB_STEP_SUMMARY"

- name: Upload C1 metrics artifact
if: always()
uses: actions/upload-artifact@v6
with:
name: c1-baseline-metrics
path: analysis/raw/c1_baseline_run.csv

1 change: 1 addition & 0 deletions analysis/raw/c1_baseline.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
scenario,run_id,run_number,commit_sha,step_name,start_timestamp,end_timestamp,duration_seconds,status
32 changes: 32 additions & 0 deletions ci/scripts/measure_step.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/usr/bin/env bash
set -euo pipefail

STEP_NAME="$1"
OUTPUT_CSV="$2"
shift 2

START_TIMESTAMP="$(date -u +"%Y-%m-%dT%H:%M:%SZ")"
START_SECONDS="$(date +%s)"

STATUS="success"

if "$@"; then
STATUS="success"
else
STATUS="failed"
fi

END_TIMESTAMP="$(date -u +"%Y-%m-%dT%H:%M:%SZ")"
END_SECONDS="$(date +%s)"
DURATION_SECONDS=$((END_SECONDS - START_SECONDS))

SCENARIO="${SCENARIO:-C1-baseline}"
RUN_ID="${GITHUB_RUN_ID:-local}"
RUN_NUMBER="${GITHUB_RUN_NUMBER:-local}"
COMMIT_SHA="${GITHUB_SHA:-local}"

echo "${SCENARIO},${RUN_ID},${RUN_NUMBER},${COMMIT_SHA},${STEP_NAME},${START_TIMESTAMP},${END_TIMESTAMP},${DURATION_SECONDS},${STATUS}" >> "${OUTPUT_CSV}"

if [ "${STATUS}" = "failed" ]; then
exit 1
fi
Loading