Skip to content

Feature/covid analysis #1

Feature/covid analysis

Feature/covid analysis #1

name: Combined Pre-commit and Verify DuckDB Output
on:
pull_request:
branches:
- main
push:
branches:
- main
jobs:
# Pre-commit job
pre-commit:
name: Run Pre-commit Hooks
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
with:
fetch-depth: 0 # Ensure full history is fetched
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: 3.11
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install pre-commit
- name: Fetch main branch
run: git fetch origin main
- name: Run pre-commit hooks
run: |
pre-commit --version
- name: Run pre-commit on all changed files
run: |
files=$(git diff --name-only origin/main)
if [ -n "$files" ]; then
pre-commit run --files $files
else
echo "No modified files to check."
fi
# DuckDB verification job
verify-duckdb:
name: Verify DuckDB Output
runs-on: ubuntu-latest
needs: pre-commit # Ensures this runs after pre-commit job
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Build Docker Image
run: |
docker build -t duckdb-data-analysis -f .docker/Dockerfile .
- name: Run Docker Container
id: run-container
run: |
docker run --rm duckdb-data-analysis > output.txt
cat output.txt
- name: Verify DuckDB Output
run: |
expected_output="│ total_locations │ earliest_date │ latest_date │
│ int64 │ date │ date │
├─────────────────┼───────────────┼─────────────┤
│ 243 │ 2020-01-01 │ 2024-08-14 │
└─────────────────┴───────────────┴─────────────┘"
actual_output=$(cat output.txt | grep -A4 "total_locations")
if [ "$actual_output" = "$expected_output" ]; then
echo "Output matches expected values."
else
echo "Output does not match expected values!"
echo "Actual output:"
echo "$actual_output"
echo "Expected output:"
echo "$expected_output"
exit 1
fi