Update backend-ci.yml #49
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
name: Backend CI Pipeline | |
on: | |
push: | |
branches: [main, develop] | |
pull_request: | |
branches: [main, develop] | |
jobs: | |
lint: | |
runs-on: self-hosted | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v2 | |
with: | |
submodules: false # 🚫 Don't check submodules to avoid .gitmodules error | |
- name: Set up Python | |
uses: actions/setup-python@v2 | |
with: | |
python-version: '3.11' | |
- name: Install dependencies | |
run: | | |
python -m venv venv | |
source venv/bin/activate | |
pip install -r backend/requirements.txt | |
- name: Run pylint on backend only | |
run: | | |
source venv/bin/activate | |
pylint ./backend/**/*.py | |
test: | |
runs-on: self-hosted | |
needs: lint | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v2 | |
with: | |
submodules: false | |
- name: Set up Python | |
uses: actions/setup-python@v2 | |
with: | |
python-version: '3.11' | |
- name: Install dependencies | |
run: | | |
python -m venv venv | |
source venv/bin/activate | |
pip install -r backend/requirements.txt | |
pip install pytest-html | |
- name: Run pylint with score check | |
run: | | |
source venv/bin/activate | |
pylint backend/main.py backend/db.py backend/init_db.py --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)" | |
- 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 3 | |
done | |
- name: Run backend tests with pytest | |
env: | |
BASE_URL: http://127.0.0.1:5000 | |
run: | | |
source venv/bin/activate | |
pytest ./backend/tests --html=backend/test-report.html --self-contained-html | |
- name: Upload test report | |
uses: actions/upload-artifact@v3 | |
with: | |
name: backend-test-report | |
path: backend/test-report.html | |
- name: Kill Flask server | |
run: | | |
pkill -f "python backend/main.py" || echo "Flask already exited" | |
build-frontend: | |
runs-on: self-hosted | |
needs: lint | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v2 | |
with: | |
submodules: false | |
- name: Set up Node.js | |
uses: actions/setup-node@v3 | |
with: | |
node-version: '20' | |
- name: Install frontend dependencies | |
working-directory: frontend | |
run: npm install | |
- name: Build frontend app | |
working-directory: frontend | |
run: npm run build |