Skip to content

Commit

Permalink
Add GitHub workflows: integration-tests, CI
Browse files Browse the repository at this point in the history
  • Loading branch information
VitalinaMykoliuk committed Dec 28, 2024
1 parent 55d951f commit 5fdcf36
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 124 deletions.
49 changes: 6 additions & 43 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ jobs:
uses: ./.github/workflows/shared_workflow.yml
with:
python-version: "3.12"
env:
ENV_VERSION: ${{ secrets.ENV_VERSION }}
env-vars: |
ENV_VERSION=DEV
test:
runs-on: ubuntu-latest
Expand All @@ -34,57 +34,20 @@ jobs:
- name: Checkout repository
uses: actions/checkout@v3

- name: Copy .env file
run: cp /home/runner/work/spotnet/spotnet/.env .env

- name: Start services
run: docker compose -f docker-compose.dev.yaml up -d --build
env:
DB_PORT: ${{ secrets.DB_PORT }}
DB_NAME: ${{ secrets.DB_NAME }}
DB_USER: ${{ secrets.DB_USER }}
DB_PASSWORD: ${{ secrets.DB_PASSWORD }}
DB_HOST: ${{ secrets.DB_HOST }}
STARKNET_NODE_URL: ${{ secrets.STARKNET_NODE_URL }}
REDIS_HOST: ${{ secrets.REDIS_HOST }}
REDIS_PORT: ${{ secrets.REDIS_PORT }}
ENV_VERSION: ${{ secrets.ENV_VERSION }}
run: docker compose -f docker-compose.dev.yaml --env-file .env up -d --build

- name: Run tests
run: |
docker compose exec backend poetry run pytest web_app/tests
env:
DB_PORT: ${{ secrets.DB_PORT }}
DB_NAME: ${{ secrets.DB_NAME }}
DB_USER: ${{ secrets.DB_USER }}
DB_PASSWORD: ${{ secrets.DB_PASSWORD }}
DB_HOST: ${{ secrets.DB_HOST }}
STARKNET_NODE_URL: ${{ secrets.STARKNET_NODE_URL }}
REDIS_HOST: ${{ secrets.REDIS_HOST }}
REDIS_PORT: ${{ secrets.REDIS_PORT }}
ENV_VERSION: ${{ secrets.ENV_VERSION }}
- name: Run tests coverage
run: |
docker compose exec backend poetry run pytest --cov=web_app/tests --cov-fail-under=90
env:
DB_PORT: ${{ secrets.DB_PORT }}
DB_NAME: ${{ secrets.DB_NAME }}
DB_USER: ${{ secrets.DB_USER }}
DB_PASSWORD: ${{ secrets.DB_PASSWORD }}
DB_HOST: ${{ secrets.DB_HOST }}
STARKNET_NODE_URL: ${{ secrets.STARKNET_NODE_URL }}
REDIS_HOST: ${{ secrets.REDIS_HOST }}
REDIS_PORT: ${{ secrets.REDIS_PORT }}
ENV_VERSION: ${{ secrets.ENV_VERSION }}
- name: Tear down
run: |
docker compose down
env:
DB_PORT: ${{ secrets.DB_PORT }}
DB_NAME: ${{ secrets.DB_NAME }}
DB_USER: ${{ secrets.DB_USER }}
DB_PASSWORD: ${{ secrets.DB_PASSWORD }}
DB_HOST: ${{ secrets.DB_HOST }}
STARKNET_NODE_URL: ${{ secrets.STARKNET_NODE_URL }}
REDIS_HOST: ${{ secrets.REDIS_HOST }}
REDIS_PORT: ${{ secrets.REDIS_PORT }}
ENV_VERSION: ${{ secrets.ENV_VERSION }}
85 changes: 4 additions & 81 deletions .github/workflows/integration-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,53 +13,26 @@ jobs:
uses: ./.github/workflows/shared_workflow.yml
with:
python-version: "3.x"
env:
DB_PORT: ${{ secrets.DB_PORT }}
DB_NAME: ${{ secrets.DB_NAME }}
DB_USER: ${{ secrets.DB_USER }}
DB_PASSWORD: ${{ secrets.DB_PASSWORD }}
DB_HOST: ${{ secrets.DB_HOST }}
STARKNET_NODE_URL: ${{ secrets.STARKNET_NODE_URL }}
REDIS_HOST: ${{ secrets.REDIS_HOST }}
REDIS_PORT: ${{ secrets.REDIS_PORT }}
ENV_VERSION: ${{ secrets.ENV_VERSION }}

integration-tests:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Copy .env file
run: cp /home/runner/work/spotnet/spotnet/.env .env

- name: Build and Start Containers
run: |
docker compose -f docker-compose.dev.yaml up -d --build
docker compose -f docker-compose.dev.yaml --env-file .env up -d --build
echo "Waiting for containers to be ready..."
sleep 30
env:
DB_PORT: ${{ secrets.DB_PORT }}
DB_NAME: ${{ secrets.DB_NAME }}
DB_USER: ${{ secrets.DB_USER }}
DB_PASSWORD: ${{ secrets.DB_PASSWORD }}
DB_HOST: ${{ secrets.DB_HOST }}
STARKNET_NODE_URL: ${{ secrets.STARKNET_NODE_URL }}
REDIS_HOST: ${{ secrets.REDIS_HOST }}
REDIS_PORT: ${{ secrets.REDIS_PORT }}
ENV_VERSION: ${{ secrets.ENV_VERSION }}
- 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
env:
DB_PORT: ${{ secrets.DB_PORT }}
DB_NAME: ${{ secrets.DB_NAME }}
DB_USER: ${{ secrets.DB_USER }}
DB_PASSWORD: ${{ secrets.DB_PASSWORD }}
DB_HOST: ${{ secrets.DB_HOST }}
STARKNET_NODE_URL: ${{ secrets.STARKNET_NODE_URL }}
REDIS_HOST: ${{ secrets.REDIS_HOST }}
REDIS_PORT: ${{ secrets.REDIS_PORT }}
ENV_VERSION: ${{ secrets.ENV_VERSION }}
- name: Wait for Backend Service
timeout-minutes: 5
Expand All @@ -78,16 +51,6 @@ jobs:
# Log the backend service status for debugging purposes.
docker compose -f docker-compose.dev.yaml logs backend || true
done
env:
DB_PORT: ${{ secrets.DB_PORT }}
DB_NAME: ${{ secrets.DB_NAME }}
DB_USER: ${{ secrets.DB_USER }}
DB_PASSWORD: ${{ secrets.DB_PASSWORD }}
DB_HOST: ${{ secrets.DB_HOST }}
STARKNET_NODE_URL: ${{ secrets.STARKNET_NODE_URL }}
REDIS_HOST: ${{ secrets.REDIS_HOST }}
REDIS_PORT: ${{ secrets.REDIS_PORT }}
ENV_VERSION: ${{ secrets.ENV_VERSION }}
- name: Apply Migrations
run: |
Expand All @@ -96,60 +59,20 @@ jobs:
docker compose -f docker-compose.dev.yaml logs backend || true
exit 1
}
env:
DB_PORT: ${{ secrets.DB_PORT }}
DB_NAME: ${{ secrets.DB_NAME }}
DB_USER: ${{ secrets.DB_USER }}
DB_PASSWORD: ${{ secrets.DB_PASSWORD }}
DB_HOST: ${{ secrets.DB_HOST }}
STARKNET_NODE_URL: ${{ secrets.STARKNET_NODE_URL }}
REDIS_HOST: ${{ secrets.REDIS_HOST }}
REDIS_PORT: ${{ secrets.REDIS_PORT }}
ENV_VERSION: ${{ secrets.ENV_VERSION }}
- name: Run Integration Tests with Coverage
run: |
docker compose exec backend bash -c "cd /app && python -m pytest web_app/test_integration/ -v"
env:
DB_PORT: ${{ secrets.DB_PORT }}
DB_NAME: ${{ secrets.DB_NAME }}
DB_USER: ${{ secrets.DB_USER }}
DB_PASSWORD: ${{ secrets.DB_PASSWORD }}
DB_HOST: ${{ secrets.DB_HOST }}
STARKNET_NODE_URL: ${{ secrets.STARKNET_NODE_URL }}
REDIS_HOST: ${{ secrets.REDIS_HOST }}
REDIS_PORT: ${{ secrets.REDIS_PORT }}
ENV_VERSION: ${{ secrets.ENV_VERSION }}
- 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
env:
DB_PORT: ${{ secrets.DB_PORT }}
DB_NAME: ${{ secrets.DB_NAME }}
DB_USER: ${{ secrets.DB_USER }}
DB_PASSWORD: ${{ secrets.DB_PASSWORD }}
DB_HOST: ${{ secrets.DB_HOST }}
STARKNET_NODE_URL: ${{ secrets.STARKNET_NODE_URL }}
REDIS_HOST: ${{ secrets.REDIS_HOST }}
REDIS_PORT: ${{ secrets.REDIS_PORT }}
ENV_VERSION: ${{ secrets.ENV_VERSION }}
- name: Upload Docker Logs on Failure
if: failure()
uses: actions/upload-artifact@v3
with:
name: docker-logs
path: docker-logs.txt
env:
DB_PORT: ${{ secrets.DB_PORT }}
DB_NAME: ${{ secrets.DB_NAME }}
DB_USER: ${{ secrets.DB_USER }}
DB_PASSWORD: ${{ secrets.DB_PASSWORD }}
DB_HOST: ${{ secrets.DB_HOST }}
STARKNET_NODE_URL: ${{ secrets.STARKNET_NODE_URL }}
REDIS_HOST: ${{ secrets.REDIS_HOST }}
REDIS_PORT: ${{ secrets.REDIS_PORT }}
ENV_VERSION: ${{ secrets.ENV_VERSION }}

0 comments on commit 5fdcf36

Please sign in to comment.