Skip to content

Commit 748f7f0

Browse files
committed
Enhance CI workflow with failure detection and update README for CI/CD integration
1 parent 97de4c9 commit 748f7f0

4 files changed

Lines changed: 25 additions & 6 deletions

File tree

.github/workflows/ci.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,12 @@ jobs:
3737
- name: Verify health check detects failures
3838
run: |
3939
# This should fail and return exit code 1
40+
set +e # Temporarily allow failures
4041
bash projects/01_api_health_check/bash/run.sh https://httpbin.org/status/500 || exit_code=$?
42+
set -e # Re-enable exit on error
43+
4144
if [ "$exit_code" != "1" ]; then
42-
echo "Health check should exit with code 1 on failure"
45+
echo "Health check should exit with code 1 on failure, got: $exit_code"
4346
exit 1
4447
fi
4548
echo "✓ Health check correctly exits non-zero on failure"

projects/01_api_health_check/README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,11 @@ output/sample_output.json
5454
```
5555
---
5656

57+
## CI/CD
58+
59+
This repository uses GitHub Actions for continuous integration.
60+
All automation scripts are tested on push to ensure reliability.
61+
5762
## Notes
5863

5964
The script exits with a non-zero status when a health check fails, making it
Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,38 @@
11
#!/usr/bin/env bash
22
set -euo pipefail
33

4-
# Run from the project directory or repo root.
4+
# Resolve directories
55
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
66
PROJECT_DIR="$(cd "${SCRIPT_DIR}/.." && pwd)"
77
REPO_ROOT="$(cd "${PROJECT_DIR}/../.." && pwd)"
88

99
OUTPUT_DIR="${PROJECT_DIR}/output"
1010
mkdir -p "${OUTPUT_DIR}"
1111

12+
# Arguments with defaults
1213
URL="${1:-https://httpbin.org/status/200}"
1314
TIMEOUT="${2:-10}"
1415

15-
# Timestamp safe for filenames
16+
# Timestamp for output file
1617
TS="$(date +"%Y%m%d_%H%M%S")"
1718
OUT_FILE="${OUTPUT_DIR}/healthcheck_${TS}.json"
1819

19-
source "${REPO_ROOT}/.venv/Scripts/activate"
20+
# Activate virtual environment (cross-platform)
21+
if [ -f "${REPO_ROOT}/.venv/Scripts/activate" ]; then
22+
# Windows (Git Bash)
23+
source "${REPO_ROOT}/.venv/Scripts/activate"
24+
elif [ -f "${REPO_ROOT}/.venv/bin/activate" ]; then
25+
# Linux/macOS
26+
source "${REPO_ROOT}/.venv/bin/activate"
27+
else
28+
echo "Error: Virtual environment not found at ${REPO_ROOT}/.venv"
29+
exit 1
30+
fi
2031

32+
# Run health check
2133
python "${PROJECT_DIR}/src/health_check.py" \
2234
--url "${URL}" \
2335
--timeout "${TIMEOUT}" \
2436
--out "${OUT_FILE}"
2537

26-
echo "Saved: ${OUT_FILE}"
38+
echo "Saved: ${OUT_FILE}"

projects/01_api_health_check/src/health_check.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
from datetime import datetime, timezone
55
from pathlib import Path
66
from typing import Any, Dict, Optional
7-
from unittest import result
87

98
import requests
109

0 commit comments

Comments
 (0)