Skip to content

Commit d7eebe0

Browse files
authored
Merge pull request #6 from ChingEnLin/build/add_workflow
Build/add workflow
2 parents e3917e9 + 5232f6e commit d7eebe0

3 files changed

Lines changed: 199 additions & 38 deletions

File tree

.github/README.md

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
# QueryPal CI/CD Pipeline
2+
3+
This directory contains the GitHub Actions CI/CD workflows for the QueryPal project.
4+
5+
## Workflows
6+
7+
### `ci.yml` - Continuous Integration
8+
9+
This workflow runs on pushes and pull requests to the `main`, `dev`, and `develop` branches.
10+
11+
**Jobs:**
12+
13+
1. **Backend Tests (Python)**
14+
- Sets up Python 3.12
15+
- Installs dependencies with pip caching
16+
- Runs syntax checks with flake8
17+
- Runs full linting with flake8 (non-blocking warnings)
18+
- Checks code formatting with black
19+
- Runs tests with pytest and coverage
20+
- Uploads coverage to Codecov
21+
22+
2. **Frontend Tests (Node.js)**
23+
- Sets up Node.js 20
24+
- Installs dependencies with npm caching
25+
- Runs tests with coverage using Vitest
26+
- Uploads coverage to Codecov
27+
28+
3. **Build Verification**
29+
- Runs after both test jobs pass
30+
- Builds the frontend application
31+
- Verifies build artifacts are created
32+
33+
**Coverage Reports:**
34+
- Backend and frontend coverage reports are uploaded to Codecov with separate flags
35+
- Coverage failures are non-blocking to allow builds to continue
36+
37+
**Key Features:**
38+
- Parallel execution of frontend and backend tests
39+
- Dependency caching for faster builds
40+
- Comprehensive code quality checks
41+
- Build verification to catch integration issues
42+
43+
## Running Tests Locally
44+
45+
### Backend
46+
```bash
47+
cd backend
48+
pip install -r requirements.txt
49+
flake8 . --statistics
50+
black --check .
51+
PYTHONPATH=. pytest --cov=. --cov-report=term-missing --verbose
52+
```
53+
54+
### Frontend
55+
```bash
56+
cd frontend
57+
npm install
58+
npm run test:coverage
59+
npm run build
60+
```
61+
62+
## Coverage Requirements
63+
64+
The CI pipeline generates coverage reports but does not enforce minimum coverage thresholds. This allows for flexible development while still providing visibility into test coverage.
65+
66+
- Backend: Currently ~49% coverage
67+
- Frontend: Currently ~13% coverage (mainly utilities and tested components)
68+
69+
Coverage reports are available in:
70+
- Backend: `backend/htmlcov/index.html`
71+
- Frontend: `frontend/coverage/index.html`

.github/workflows/ci.yml

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
name: CI - Test Frontend and Backend
2+
3+
on:
4+
push:
5+
branches: [ main, dev, develop ]
6+
pull_request:
7+
branches: [ main, dev, develop ]
8+
workflow_dispatch:
9+
10+
jobs:
11+
backend-tests:
12+
name: Backend Tests (Python)
13+
runs-on: ubuntu-latest
14+
15+
steps:
16+
- name: Checkout code
17+
uses: actions/checkout@v4
18+
19+
- name: Set up Python 3.12
20+
uses: actions/setup-python@v4
21+
with:
22+
python-version: '3.12'
23+
24+
- name: Cache pip dependencies
25+
uses: actions/cache@v3
26+
with:
27+
path: ~/.cache/pip
28+
key: ${{ runner.os }}-pip-${{ hashFiles('backend/requirements.txt') }}
29+
restore-keys: |
30+
${{ runner.os }}-pip-
31+
32+
- name: Install dependencies
33+
working-directory: ./backend
34+
run: |
35+
python -m pip install --upgrade pip
36+
pip install -r requirements.txt
37+
38+
- name: Lint with flake8
39+
working-directory: ./backend
40+
run: |
41+
# Stop the build if there are Python syntax errors or undefined names
42+
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
43+
# Exit-zero treats all errors as warnings
44+
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=88 --statistics
45+
46+
- name: Check code formatting with black
47+
working-directory: ./backend
48+
run: |
49+
black --check .
50+
51+
- name: Run tests with pytest
52+
working-directory: ./backend
53+
run: |
54+
PYTHONPATH=. pytest --cov=. --cov-report=term-missing --cov-report=xml --verbose
55+
56+
- name: Upload coverage to Codecov
57+
uses: codecov/codecov-action@v3
58+
with:
59+
file: ./backend/coverage.xml
60+
flags: backend
61+
name: backend-coverage
62+
fail_ci_if_error: false
63+
64+
frontend-tests:
65+
name: Frontend Tests (Node.js)
66+
runs-on: ubuntu-latest
67+
68+
steps:
69+
- name: Checkout code
70+
uses: actions/checkout@v4
71+
72+
- name: Set up Node.js 20
73+
uses: actions/setup-node@v4
74+
with:
75+
node-version: '20'
76+
cache: 'npm'
77+
cache-dependency-path: frontend/package-lock.json
78+
79+
- name: Install dependencies
80+
working-directory: ./frontend
81+
run: npm ci
82+
83+
- name: Run tests with coverage
84+
working-directory: ./frontend
85+
run: npm run test:coverage
86+
87+
- name: Upload coverage to Codecov
88+
uses: codecov/codecov-action@v3
89+
with:
90+
file: ./frontend/coverage/coverage-final.json
91+
flags: frontend
92+
name: frontend-coverage
93+
fail_ci_if_error: false
94+
95+
# Optional: Build verification job
96+
build-verification:
97+
name: Build Verification
98+
runs-on: ubuntu-latest
99+
needs: [backend-tests, frontend-tests]
100+
101+
steps:
102+
- name: Checkout code
103+
uses: actions/checkout@v4
104+
105+
- name: Set up Node.js 20
106+
uses: actions/setup-node@v4
107+
with:
108+
node-version: '20'
109+
cache: 'npm'
110+
cache-dependency-path: frontend/package-lock.json
111+
112+
- name: Install frontend dependencies
113+
working-directory: ./frontend
114+
run: npm ci
115+
116+
- name: Build frontend
117+
working-directory: ./frontend
118+
run: npm run build
119+
120+
- name: Verify frontend build artifacts
121+
working-directory: ./frontend
122+
run: |
123+
if [ ! -d "dist" ]; then
124+
echo "Frontend build failed - no dist directory found"
125+
exit 1
126+
fi
127+
echo "Frontend build successful - dist directory exists"
128+
ls -la dist/

.github/workflows/docker-build-push.yml

Lines changed: 0 additions & 38 deletions
This file was deleted.

0 commit comments

Comments
 (0)