Skip to content

Making sure develop branch is up-to-date with main #27

Merged
merged 78 commits into from
Apr 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
78 commits
Select commit Hold shift + click to select a range
571de93
Merge pull request #24 from CSE2102-Spring25/develop
ris20010 Apr 18, 2025
b1928a2
Update backend-ci.yml
pdr21001 Apr 23, 2025
651708c
Update backend-ci.yml
pdr21001 Apr 23, 2025
6d217bc
Fix Flask version for CI compatibility
pdr21001 Apr 23, 2025
f3e2db9
Fixing requirements.txt CI compatabilities
pdr21001 Apr 23, 2025
5915be0
Update requirements.txt
pdr21001 Apr 23, 2025
ef0303b
Update main.py
pdr21001 Apr 23, 2025
3f06c25
Update init_db.py
pdr21001 Apr 23, 2025
7f0ae19
Update db.py
pdr21001 Apr 23, 2025
c2c78ac
Update main.py
pdr21001 Apr 23, 2025
650c2f6
Update init_db.py
pdr21001 Apr 23, 2025
abe3e8f
Update db.py
pdr21001 Apr 23, 2025
c7b51af
Update init_db.py
pdr21001 Apr 23, 2025
8385162
Update main.py
pdr21001 Apr 23, 2025
4ff028d
Update db.py
pdr21001 Apr 23, 2025
825bc46
Update db.py
pdr21001 Apr 23, 2025
0f3388d
Update init_db.py
pdr21001 Apr 23, 2025
d6277a1
Update init_db.py
pdr21001 Apr 23, 2025
767c8d9
Update db.py
pdr21001 Apr 23, 2025
852c901
Update db.py
pdr21001 Apr 23, 2025
bff7b58
Update init_db.py
pdr21001 Apr 23, 2025
604d71e
utils.py for refactoring
pdr21001 Apr 23, 2025
e007e4f
Update init_db.py
pdr21001 Apr 23, 2025
4cd6929
Update main.py
pdr21001 Apr 23, 2025
1c1bdb2
Update db.py
pdr21001 Apr 23, 2025
a00fa21
Update main.py
pdr21001 Apr 23, 2025
fd5a569
Update db.py
pdr21001 Apr 23, 2025
e90d151
Update init_db.py
pdr21001 Apr 23, 2025
bfa39c4
Update main.py
pdr21001 Apr 23, 2025
ef20f8e
Update init_db.py
pdr21001 Apr 23, 2025
03cf790
Update backend-ci.yml
pdr21001 Apr 23, 2025
824bc9c
Update backend-ci.yml
pdr21001 Apr 23, 2025
1d94711
Update backend-ci.yml
pdr21001 Apr 24, 2025
8294fba
Update backend-ci.yml
pdr21001 Apr 24, 2025
237b43a
Merge pull request #25 from CSE2102-Spring25/develop
ris20010 Apr 25, 2025
885057c
Final frontend updates: profile page, full-width layout, pet details
ris20010 Apr 25, 2025
2ec1f74
Finish merge from origin/main
ris20010 Apr 25, 2025
ab163b5
milestone 7
pdr21001 Apr 25, 2025
48e2fc1
remove nested folder
pdr21001 Apr 25, 2025
9650fe9
Trigger workflow re-run after submodule cleanup
pdr21001 Apr 25, 2025
13e1c4b
Update backend-ci.yml
pdr21001 Apr 25, 2025
9b9877a
Update backend-ci.yml
pdr21001 Apr 25, 2025
a1a0c45
Update backend-ci.yml
pdr21001 Apr 25, 2025
3fbf17f
Update backend-ci.yml
pdr21001 Apr 25, 2025
c97ae37
Update backend-ci.yml
pdr21001 Apr 25, 2025
0b93b96
Update backend-ci.yml
pdr21001 Apr 25, 2025
38b5385
Update backend-ci.yml
pdr21001 Apr 25, 2025
dc0a095
Update backend-ci.yml
pdr21001 Apr 25, 2025
796a8ff
Committing local changes before pulling
pdr21001 Apr 26, 2025
1524e60
Update backend-ci.yml
pdr21001 Apr 26, 2025
896d9c1
Update backend-ci.yml
pdr21001 Apr 26, 2025
631be25
Update backend-ci.yml
pdr21001 Apr 26, 2025
0a1f1f1
Update backend-ci.yml
pdr21001 Apr 26, 2025
376b322
Update backend-ci.yml
pdr21001 Apr 26, 2025
f5d3b5c
Update backend-ci.yml
pdr21001 Apr 26, 2025
5b7dfaa
Update backend-ci.yml
pdr21001 Apr 26, 2025
0c16e1a
Update backend-ci.yml
pdr21001 Apr 26, 2025
c0f06a2
Update backend-ci.yml
pdr21001 Apr 26, 2025
43dabd8
Update backend-ci.yml
pdr21001 Apr 26, 2025
6d0ea1a
Update requirements.txt
pdr21001 Apr 26, 2025
4523bcc
Update backend-ci.yml
pdr21001 Apr 26, 2025
60d449c
Update backend-ci.yml
pdr21001 Apr 26, 2025
078c4cb
Update backend-ci.yml
pdr21001 Apr 26, 2025
2674710
Update backend-ci.yml
pdr21001 Apr 26, 2025
e7beee4
Update backend-ci.yml
pdr21001 Apr 26, 2025
ea87f44
Update backend-ci.yml
pdr21001 Apr 28, 2025
713b32d
Update backend-ci.yml
pdr21001 Apr 28, 2025
70be04a
Update backend-ci.yml
pdr21001 Apr 28, 2025
c765579
Update backend-ci.yml
pdr21001 Apr 28, 2025
407d7e2
Update backend-ci.yml
pdr21001 Apr 28, 2025
df4e836
Update backend-ci.yml
pdr21001 Apr 28, 2025
df1a9f1
Update backend-ci.yml
pdr21001 Apr 28, 2025
d73f659
Update backend-ci.yml
pdr21001 Apr 28, 2025
738a3ec
Update backend-ci.yml
pdr21001 Apr 28, 2025
b88a782
Update backend-ci.yml
pdr21001 Apr 28, 2025
9ad01f5
Update main.py
pdr21001 Apr 28, 2025
435fc83
Update backend-ci.yml
pdr21001 Apr 28, 2025
edca506
dockerized frontend with a reference to backend in the docker-compose…
Apr 28, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
112 changes: 76 additions & 36 deletions .github/workflows/backend-ci.yml
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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ https://trello.com/b/1z9zUv2a/cse-2102-project

Figma Prototype
https://www.figma.com/design/ackeSbcEwP2kJQmJknsge5/Milestone3_Figma?node-id=0-1&t=ItY8uyCUknB0nwIz-1
# trigger cleanup
145 changes: 125 additions & 20 deletions backend/.github/workflows/backend-ci.yml
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 added backend/__pycache__/main.cpython-311.pyc
Binary file not shown.
Binary file added backend/__pycache__/pets.cpython-311.pyc
Binary file not shown.
Binary file not shown.
Binary file added backend/__pycache__/utils.cpython-311.pyc
Binary file not shown.
40 changes: 13 additions & 27 deletions backend/db.py
Original file line number Diff line number Diff line change
@@ -1,42 +1,28 @@
"""Database utility functions for managing the pet adoption database."""

import sqlite3
import os
from utils import create_tables


def init_db():
"""Initialize the database, creating tables and inserting initial data."""
db_path = os.path.join(os.path.dirname(__file__), 'animal_shelter.db')
db_path = os.path.join(os.path.dirname(__file__), "animal_shelter.db")

if os.path.exists(db_path):
print("Database already initialized.")
return

# Connect to SQLite database (it will create the file if it doesn't exist)
conn = sqlite3.connect(db_path)
cursor = conn.cursor()
create_tables(conn)

# Create tables
cursor.execute('''CREATE TABLE IF NOT EXISTS animals (
id INTEGER PRIMARY KEY AUTOINCREMENT,
name TEXT NOT NULL,
species TEXT NOT NULL,
breed TEXT,
age INTEGER,
personality TEXT,
image_path TEXT,
adoption_status TEXT DEFAULT 'Available'
)''')

cursor.execute('''CREATE TABLE IF NOT EXISTS adopters (
id INTEGER PRIMARY KEY AUTOINCREMENT,
username TEXT UNIQUE NOT NULL,
password TEXT NOT NULL,
email TEXT UNIQUE,
join_date TEXT DEFAULT CURRENT_TIMESTAMP
)''')

# Insert initial data (e.g., a test animal)
cursor.execute('''INSERT INTO animals (name, species, breed, age, personality, image_path)
VALUES (?, ?, ?, ?, ?, ?)''',
('TestDog', 'Dog', 'Mixed', 2, 'Friendly', '/images/test.jpg'))
cursor = conn.cursor()
cursor.execute(
"""
INSERT INTO animals (name, species, breed, age, personality, image_path)
VALUES (?, ?, ?, ?, ?, ?)""",
("TestDog", "Dog", "Mixed", 2, "Friendly", "/images/test.jpg"),
)

conn.commit()
conn.close()
Expand Down
Binary file added backend/images/bella.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added backend/images/max.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added backend/images/mittens.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added backend/images/oldy.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Loading