Skip to content

Commit

Permalink
Fix error
Browse files Browse the repository at this point in the history
  • Loading branch information
VitalinaMykoliuk committed Dec 25, 2024
1 parent 41a8f76 commit a96caf0
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 139 deletions.
57 changes: 14 additions & 43 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,46 +9,17 @@ on:
- main

jobs:
call-reusable-workflow:
uses: ./.github/workflows/workflow.yml

services:
postgres:
image: postgres:16
env:
POSTGRES_HOST_AUTH_METHOD: trust
ports:
- 5433:5432
options: >-
--health-cmd "pg_isready -U postgres"
--health-interval 10s
--health-timeout 5s
--health-retries 5
steps:

- name: Set up Docker
uses: docker/setup-buildx-action@v2

- name: Install Docker Compose
run: |
sudo curl -L "https://github.com/docker/compose/releases/download/v2.20.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose
- name: Create .env file
run: cp .env.dev .env

- name: Start services
run: docker compose -f docker-compose.dev.yaml up -d --build

- name: Run tests
run: |
docker-compose exec backend poetry run pytest web_app/tests
- name: Run tests coverage
run: |
docker-compose exec backend poetry run pytest --cov=web_app/tests --cov-fail-under=90
- name: Tear down
run: |
docker-compose down
test:
uses: ./.github/workflows/test_workflow.yml
with:
steps_override: |
- name: Create .env file
run: cp .env.dev .env
- name: Start services
run: docker compose -f docker-compose.dev.yaml up -d --build
- name: Run tests
run: |
docker-compose exec backend poetry run pytest web_app/tests
- name: Run tests coverage
run: |
docker-compose exec backend poetry run pytest --cov=web_app/tests --cov-fail-under=90
101 changes: 13 additions & 88 deletions .github/workflows/integration-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,93 +8,18 @@ on:
branches:
- main

env:
DB_PORT: 5432
DB_NAME: spotnet
DB_USER: postgres
DB_PASSWORD: password
DB_HOST: db
STARKNET_NODE_URL: http://51.195.57.196:6060/v0_7
REDIS_HOST: redis
REDIS_PORT: 6379
ENV_VERSION: DEV

jobs:
call-reusable-workflow:
uses: ./.github/workflows/workflow.yml
integration-tests:
uses: ./.github/workflows/test_workflow.yml
with:
matrix:
python-version: ["3.12"]

steps:
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2

- name: Create .env file
run: |
cat << EOF > /home/runner/work/spotnet/spotnet/.env
ENV_VERSION=DEV
STARKNET_NODE_URL=${{ env.STARKNET_NODE_URL }}
DB_USER=${{ env.DB_USER }}
DB_PASSWORD=${{ env.DB_PASSWORD }}
DB_NAME=${{ env.DB_NAME }}
DB_HOST=${{ env.DB_HOST }}
DB_PORT=${{ env.DB_PORT }}
REDIS_HOST=${{ env.REDIS_HOST }}
REDIS_PORT=${{ env.REDIS_PORT }}
EOF
- name: Build and Start Containers
run: |
docker compose -f docker-compose.dev.yaml up -d --build
echo "Waiting for containers to be ready..."
sleep 30
- name: Install Test Dependencies in Container
run: |
docker exec backend_dev pip install pytest pytest-cov
docker exec backend_dev pip freeze # Debug: show installed packages
- name: Wait for Backend Service
timeout-minutes: 5
run: |
while ! curl -s http://localhost:8000/health > /dev/null; do
echo "Waiting for backend service..."
sleep 30
# Check if the container is still running before logging
if ! docker ps | grep -q backend; then
echo "Backend container is not running!"
docker compose -f docker-compose.dev.yaml logs backend || true
exit 1
fi
# Log the backend service status for debugging purposes.
docker compose -f docker-compose.dev.yaml logs backend || true
done
- name: Apply Migrations
run: |
docker exec backend_dev alembic -c web_app/alembic.ini upgrade head || {
echo "Migration failed. Showing backend logs:"
docker compose -f docker-compose.dev.yaml logs backend || true
exit 1
}
- name: Run Integration Tests with Coverage
run: |
docker compose exec backend bash -c "cd /app && python -m pytest web_app/test_integration/ -v"
- name: Clean Up
if: always()
run: |
docker compose -f docker-compose.dev.yaml logs > docker-logs.txt || true
docker compose -f docker-compose.dev.yaml down -v
- name: Upload Docker Logs on Failure
if: failure()
uses: actions/upload-artifact@v3
with:
name: docker-logs
path: docker-logs.txt
steps_override: |
- name: Create .env file
run: |
cat << EOF > .env
DB_USER=postgres
DB_PASSWORD=password
...
EOF
- name: Run Integration Tests
run: |
docker-compose exec backend pytest tests/integration/
17 changes: 11 additions & 6 deletions .github/workflows/pylint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,18 @@ name: Pylint

on:
push:
branches: [main]
branches:
- main
pull_request:
branches: [main]
branches:
- main

jobs:
call-reusable-workflow:
uses: ./.github/workflows/workflow.yml
pylint:
uses: ./.github/workflows/test_workflow.yml
with:
matrix:
python-version: ["3.12"]
steps_override: |
- name: Install pylint
run: pip install pylint
- name: Run pylint
run: pylint $(git ls-files '*.py') --disable=all --enable=C0114,C0115,C0116,C0301
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ on:
default: ""

jobs:
test:
build:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [${{ inputs.python-version }}]
python-version: ["3.12"]
steps:
- name: Checkout repository
uses: actions/checkout@v3
Expand Down

0 comments on commit a96caf0

Please sign in to comment.