Skip to content

Commit

Permalink
Merge pull request #443 from VitalinaMykoliuk/feature/create-generic-…
Browse files Browse the repository at this point in the history
…workflow

Added files pylint, integration tests, CI, workflow
  • Loading branch information
iamnovichek authored Dec 29, 2024
2 parents bfa0a61 + 12895cd commit 345eeea
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 45 deletions.
25 changes: 11 additions & 14 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,15 @@ on:
- main

jobs:
shared:
uses: ./.github/workflows/shared_workflow.yml
with:
python-version: "3.12"
env-vars: |
ENV_VERSION=DEV
test:
runs-on: ubuntu-latest

services:
postgres:
image: postgres:16
Expand All @@ -24,33 +30,24 @@ jobs:
--health-interval 10s
--health-timeout 5s
--health-retries 5
steps:
- name: Checkout repository
uses: actions/checkout@v3

- 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
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
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
docker compose exec backend poetry run pytest --cov=web_app/tests --cov-fail-under=90
- name: Tear down
run: |
docker-compose down
docker compose down
38 changes: 16 additions & 22 deletions .github/workflows/integration-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,33 +8,28 @@ 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:
shared:
uses: ./.github/workflows/shared_workflow.yml
with:
python-version: "3.x"
env-vars: |
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
integration-tests:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.x"

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

- name: Create .env file
run: |
cat << EOF > /home/runner/work/spotnet/spotnet/.env
Expand All @@ -51,7 +46,7 @@ jobs:
- 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
Expand Down Expand Up @@ -90,7 +85,6 @@ jobs:
run: |
docker compose exec backend bash -c "cd /app && python -m pytest web_app/test_integration/ -v"
- name: Clean Up
if: always()
run: |
Expand Down
19 changes: 10 additions & 9 deletions .github/workflows/pylint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,22 @@ on:
branches: [main]

jobs:
shared:
uses: ./.github/workflows/shared_workflow.yml
with:
python-version: "3.12"

build:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.12"]
steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python-version }}
- name: Checkout repository
uses: actions/checkout@v3

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install pylint
- name: Analysing the code with pylint
run: |
pylint $(git ls-files '*.py') --disable=all --enable=C0114,C0115,C0116,C0301
39 changes: 39 additions & 0 deletions .github/workflows/shared_workflow.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: Shared Setup Workflow

on:
workflow_call:
inputs:
python-version:
description: "The Python version to set up"
required: true
type: string
env-vars:
description: "Environment variables as a multi-line string"
required: false
type: string

jobs:
shared-setup:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Set up Python
uses: actions/setup-python@v3
with:
python-version: ${{ inputs.python-version }}

- name: Set up Docker Buildx
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
if: ${{ inputs.env-vars != '' }}
run: |
echo "${{ inputs.env-vars }}" > .env

0 comments on commit 345eeea

Please sign in to comment.