|
| 1 | +name: C1 - Baseline Pipeline |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + push: |
| 6 | + branches: |
| 7 | + - feature/c1-baseline-pipeline |
| 8 | + |
| 9 | +env: |
| 10 | + SCENARIO: C1-baseline |
| 11 | + RESULTS_FILE: analysis/raw/c1_baseline_run.csv |
| 12 | + IMAGE_NAME: tcc-devsecops-api:local |
| 13 | + CLUSTER_NAME: tcc-devsecops |
| 14 | + |
| 15 | +jobs: |
| 16 | + c1-baseline: |
| 17 | + name: C1 baseline |
| 18 | + runs-on: ubuntu-latest |
| 19 | + |
| 20 | + steps: |
| 21 | + - name: Checkout repository |
| 22 | + uses: actions/checkout@v5 |
| 23 | + |
| 24 | + - name: Prepare results CSV |
| 25 | + run: | |
| 26 | + mkdir -p analysis/raw |
| 27 | + echo "WORKFLOW_START_SECONDS=$(date +%s)" >> "$GITHUB_ENV" |
| 28 | + echo "WORKFLOW_START_TIMESTAMP=$(date -u +"%Y-%m-%dT%H:%M:%SZ")" >> "$GITHUB_ENV" |
| 29 | + echo "scenario,run_id,run_number,commit_sha,step_name,start_timestamp,end_timestamp,duration_seconds,status" > "$RESULTS_FILE" |
| 30 | +
|
| 31 | + - name: Setup Python |
| 32 | + uses: actions/setup-python@v6 |
| 33 | + with: |
| 34 | + python-version: "3.12" |
| 35 | + |
| 36 | + - name: Make measurement script executable |
| 37 | + run: chmod +x ci/scripts/measure_step.sh |
| 38 | + |
| 39 | + - name: Install Python dependencies |
| 40 | + run: | |
| 41 | + ./ci/scripts/measure_step.sh "install_dependencies" "$RESULTS_FILE" \ |
| 42 | + python -m pip install -r app/requirements.txt |
| 43 | +
|
| 44 | + - name: Run unit tests |
| 45 | + run: | |
| 46 | + ./ci/scripts/measure_step.sh "unit_tests" "$RESULTS_FILE" \ |
| 47 | + python -m pytest app -v |
| 48 | +
|
| 49 | + - name: Build Docker image |
| 50 | + run: | |
| 51 | + ./ci/scripts/measure_step.sh "docker_build" "$RESULTS_FILE" \ |
| 52 | + docker build -t "$IMAGE_NAME" ./app |
| 53 | +
|
| 54 | + - name: Install kind |
| 55 | + run: | |
| 56 | + curl -Lo ./kind https://kind.sigs.k8s.io/dl/v0.30.0/kind-linux-amd64 |
| 57 | + chmod +x ./kind |
| 58 | + sudo mv ./kind /usr/local/bin/kind |
| 59 | + kind version |
| 60 | +
|
| 61 | + - name: Create local Kubernetes cluster |
| 62 | + run: | |
| 63 | + kind create cluster --name "$CLUSTER_NAME" --config infra/kind/kind-cluster.yaml |
| 64 | + kubectl cluster-info |
| 65 | + kubectl get nodes |
| 66 | +
|
| 67 | + - name: Deploy to Kubernetes |
| 68 | + run: | |
| 69 | + ./ci/scripts/measure_step.sh "kubernetes_deploy" "$RESULTS_FILE" \ |
| 70 | + 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' |
| 71 | +
|
| 72 | + - name: Smoke test Kubernetes deployment |
| 73 | + run: | |
| 74 | + ./ci/scripts/measure_step.sh "kubernetes_smoke_test" "$RESULTS_FILE" \ |
| 75 | + 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' |
| 76 | +
|
| 77 | + - name: Append workflow total duration |
| 78 | + if: always() |
| 79 | + run: | |
| 80 | + WORKFLOW_END_TIMESTAMP="$(date -u +"%Y-%m-%dT%H:%M:%SZ")" |
| 81 | + WORKFLOW_END_SECONDS="$(date +%s)" |
| 82 | + WORKFLOW_DURATION_SECONDS=$((WORKFLOW_END_SECONDS - WORKFLOW_START_SECONDS)) |
| 83 | + echo "${SCENARIO},${GITHUB_RUN_ID},${GITHUB_RUN_NUMBER},${GITHUB_SHA},workflow_total,${WORKFLOW_START_TIMESTAMP},${WORKFLOW_END_TIMESTAMP},${WORKFLOW_DURATION_SECONDS},success" >> "$RESULTS_FILE" |
| 84 | +
|
| 85 | + - name: Show collected metrics |
| 86 | + if: always() |
| 87 | + run: | |
| 88 | + echo "Collected C1 baseline metrics:" |
| 89 | + cat "$RESULTS_FILE" |
| 90 | +
|
| 91 | + - name: Write GitHub Actions summary |
| 92 | + if: always() |
| 93 | + run: | |
| 94 | + echo "## C1 - Baseline Pipeline" >> "$GITHUB_STEP_SUMMARY" |
| 95 | + echo "" >> "$GITHUB_STEP_SUMMARY" |
| 96 | + echo "Scenario: $SCENARIO" >> "$GITHUB_STEP_SUMMARY" |
| 97 | + echo "" >> "$GITHUB_STEP_SUMMARY" |
| 98 | + echo "### Collected metrics" >> "$GITHUB_STEP_SUMMARY" |
| 99 | + echo "" >> "$GITHUB_STEP_SUMMARY" |
| 100 | + echo '```csv' >> "$GITHUB_STEP_SUMMARY" |
| 101 | + cat "$RESULTS_FILE" >> "$GITHUB_STEP_SUMMARY" |
| 102 | + echo '```' >> "$GITHUB_STEP_SUMMARY" |
| 103 | +
|
| 104 | + - name: Upload C1 metrics artifact |
| 105 | + if: always() |
| 106 | + uses: actions/upload-artifact@v6 |
| 107 | + with: |
| 108 | + name: c1-baseline-metrics |
| 109 | + path: analysis/raw/c1_baseline_run.csv |
| 110 | + |
0 commit comments