-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #27 from CSE2102-Spring25/main
Making sure develop branch is up-to-date with main
- Loading branch information
Showing
45 changed files
with
1,325 additions
and
522 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,60 +1,100 @@ | ||
name: Backend CI Pipeline | ||
name: CI Backend + Frontend Workflow | ||
|
||
# Trigger workflow on push or pull request to develop and main branches | ||
on: | ||
push: | ||
branches: | ||
- develop | ||
- main | ||
branches: [ "main" ] | ||
pull_request: | ||
branches: | ||
- develop | ||
- main | ||
branches: [ "main" ] | ||
|
||
jobs: | ||
lint: | ||
runs-on: ubuntu-latest | ||
backend-ci: | ||
runs-on: self-hosted | ||
defaults: | ||
run: | ||
working-directory: ./backend | ||
|
||
services: | ||
postgres: | ||
image: postgres:13 | ||
env: | ||
POSTGRES_USER: testuser | ||
POSTGRES_PASSWORD: testpassword | ||
POSTGRES_DB: testdb | ||
ports: | ||
- 5432:5432 | ||
options: >- | ||
--health-cmd "pg_isready" | ||
--health-interval 10s | ||
--health-timeout 5s | ||
--health-retries 5 | ||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v2 | ||
- name: Checkout code | ||
uses: actions/checkout@v4 | ||
with: | ||
fetch-depth: 0 | ||
|
||
- name: Set up Python | ||
uses: actions/setup-python@v2 | ||
- name: Set up Python 3.11 | ||
uses: actions/setup-python@v5 | ||
with: | ||
python-version: '3.11' # Adjust Python version if needed | ||
python-version: '3.11' | ||
|
||
- name: Install dependencies | ||
- name: Install backend dependencies | ||
run: | | ||
python -m venv venv | ||
source venv/bin/activate | ||
sudo apt-get update | ||
sudo apt-get install -y jq | ||
python -m pip install --upgrade pip | ||
pip install -r requirements.txt | ||
pip install pylint pytest requests | ||
- name: Run pylint on Python code | ||
- name: Run pylint on backend | ||
run: | | ||
source venv/bin/activate | ||
pylint backend/main.py backend/db.py backend/init_db.py # Add more files as needed | ||
git fetch origin main | ||
changed_files=$(git diff --name-only origin/main...HEAD | grep '\.py$' || true) | ||
if [ -n "$changed_files" ]; then | ||
pylint $changed_files --exit-zero | tee pylint.log | ||
SCORE=$(tail -n 2 pylint.log | grep -oP '[0-9]+\.[0-9]+(?=/10)') | ||
echo "Pylint score: $SCORE" | ||
python -c "import sys; sys.exit(0 if float('$SCORE') >= 8.0 else 1)" | ||
else | ||
echo "No Python files changed, skipping pylint." | ||
exit 0 | ||
fi | ||
test: | ||
runs-on: ubuntu-latest | ||
needs: lint # Ensure this job runs after linting | ||
- name: Start backend server (background) | ||
run: | | ||
python main.py & | ||
for i in {1..10}; do | ||
curl -s http://localhost:5000/api/pets && break || sleep 2 | ||
done | ||
- name: Initialize database | ||
run: | | ||
python init_db.py | ||
- name: Run pytest on backend (HTTP API tests) | ||
run: | | ||
pytest tests/ | ||
frontend-build: | ||
runs-on: self-hosted | ||
defaults: | ||
run: | ||
working-directory: ./frontend | ||
|
||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v2 | ||
- name: Checkout code | ||
uses: actions/checkout@v4 | ||
|
||
- name: Set up Python | ||
uses: actions/setup-python@v2 | ||
- name: Set up Node.js | ||
uses: actions/setup-node@v4 | ||
with: | ||
python-version: '3.11' | ||
node-version: '20' | ||
|
||
- name: Install dependencies | ||
- name: Install frontend dependencies | ||
run: | | ||
python -m venv venv | ||
source venv/bin/activate | ||
pip install -r requirements.txt | ||
npm install | ||
- name: Run tests with pytest | ||
- name: Build frontend | ||
run: | | ||
source venv/bin/activate | ||
pytest backend/tests --maxfail=1 --disable-warnings -q | ||
npm run build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,144 @@ | ||
name: Backend CI | ||
name: Backend CI Pipeline | ||
|
||
on: | ||
push: | ||
paths: | ||
- 'backend/**' | ||
branches: [main, develop] | ||
pull_request: | ||
paths: | ||
- 'backend/**' | ||
branches: [main, develop] | ||
|
||
jobs: | ||
backend-ci: | ||
runs-on: ubuntu-latest | ||
lint: | ||
runs-on: self-hosted | ||
defaults: | ||
run: | ||
working-directory: backend | ||
|
||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v3 | ||
- name: Checkout code without submodules | ||
uses: actions/checkout@v2 # Using v2 for actions/checkout | ||
with: | ||
submodules: false # Skips submodule initialization | ||
|
||
- name: Set up Python | ||
uses: actions/setup-python@v2 # Using v2 for setup-python | ||
with: | ||
python-version: '3.11' | ||
|
||
- name: Install dependencies | ||
run: | | ||
python -m venv venv | ||
source venv/bin/activate | ||
pip install -r requirements.txt # Ensure all dependencies are installed, including requests | ||
- name: Cache Python dependencies | ||
uses: actions/cache@v2 # Using v2 for actions/cache | ||
with: | ||
path: venv | ||
key: ${{ runner.os }}-python-${{ hashFiles('**/requirements.txt') }} | ||
restore-keys: | | ||
${{ runner.os }}-python- | ||
- name: Run pylint (backend only on changed files) | ||
run: | | ||
source venv/bin/activate | ||
changed_files=$(git diff --name-only origin/main...HEAD | grep '\.py$' || true) | ||
if [ -n "$changed_files" ]; then | ||
pylint $changed_files --exit-zero | tee pylint.log | ||
SCORE=$(tail -n 2 pylint.log | grep -oP '[0-9]+\.[0-9]+(?=/10)') | ||
echo "Pylint score: $SCORE" | ||
python -c "import sys; sys.exit(0 if float('$SCORE') >= 8.0 else 1)" | ||
else | ||
echo "No Python files changed, skipping pylint." | ||
exit 0 # Exit with status 0 (success) if no Python files changed | ||
fi | ||
test: | ||
runs-on: self-hosted | ||
needs: lint | ||
|
||
steps: | ||
- name: Checkout code without submodules | ||
uses: actions/checkout@v2 # Using v2 for actions/checkout | ||
with: | ||
submodules: false # Skips submodule initialization | ||
|
||
- name: Set up Python | ||
uses: actions/setup-python@v4 | ||
uses: actions/setup-python@v2 # Using v2 for setup-python | ||
with: | ||
python-version: '3.11' | ||
|
||
- name: Install dependencies | ||
working-directory: ./backend | ||
run: | | ||
pip install -r requirements.txt | ||
python -m venv venv | ||
source venv/bin/activate | ||
pip install -r backend/requirements.txt # Ensure all dependencies are installed, including requests | ||
pip install pytest-html | ||
- name: Run pylint on backend | ||
working-directory: ./backend | ||
- name: Cache Python dependencies | ||
uses: actions/cache@v2 # Using v2 for actions/cache | ||
with: | ||
path: venv | ||
key: ${{ runner.os }}-python-${{ hashFiles('backend/requirements.txt') }} | ||
restore-keys: | | ||
${{ runner.os }}-python- | ||
- name: Start Flask API server | ||
run: | | ||
nohup python backend/main.py > flask.log 2>&1 & | ||
for i in {1..10}; do | ||
if curl --silent --fail http://127.0.0.1:5000/; then | ||
echo "Flask is ready" | ||
break | ||
fi | ||
echo "Waiting for Flask... Attempt $i/10" | ||
sleep 5 | ||
done | ||
- name: Run backend tests with pytest | ||
env: | ||
BASE_URL: http://127.0.0.1:5000 | ||
run: | | ||
pylint main.py db.py init_db.py | ||
source venv/bin/activate # Activate the virtual environment before running tests | ||
pytest backend/tests --html=backend/test-report.html --self-contained-html | ||
- name: Run Pytest | ||
working-directory: ./backend | ||
- name: Upload test report | ||
uses: actions/upload-artifact@v2 # Using v2 for actions/upload-artifact | ||
with: | ||
name: backend-test-report | ||
path: backend/test-report.html | ||
|
||
- name: Kill Flask server | ||
run: | | ||
python main.py & # Run server | ||
sleep 5 # Give it time to start | ||
pytest tests/ | ||
pkill -f "python backend/main.py" || echo "Flask already exited" | ||
build-frontend: | ||
runs-on: self-hosted | ||
needs: [lint, test] | ||
|
||
steps: | ||
- name: Checkout repository without submodules | ||
uses: actions/checkout@v2 # Using v2 for actions/checkout | ||
with: | ||
submodules: false # Skips submodule initialization | ||
|
||
- name: Set up Node.js | ||
uses: actions/setup-node@v3 # Using the latest stable version for Node.js | ||
with: | ||
node-version: '20' | ||
|
||
- name: Cache node modules | ||
uses: actions/cache@v2 # Using v2 for actions/cache | ||
with: | ||
path: frontend/node_modules | ||
key: ${{ runner.os }}-node-${{ hashFiles('frontend/package-lock.json') }} | ||
restore-keys: | | ||
${{ runner.os }}-node- | ||
- name: Install frontend dependencies | ||
working-directory: frontend | ||
run: npm install | ||
|
||
- name: Build frontend app | ||
working-directory: frontend | ||
run: npm run build |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.