Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DOP-11675] - add test workflow #5

Merged
merged 1 commit into from
Feb 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
140 changes: 140 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
name: Tests
on:
push:
branches:
- develop
pull_request:
branches-ignore:
- master
workflow_dispatch:

concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.ref }}
cancel-in-progress: true

env:
DEFAULT_PYTHON: '3.12'

jobs:
tests:
name: Run ${{ matrix.mark }} tests (Python ${{ matrix.python-version }} on ${{ matrix.os }})
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
python-version: ['3.7', '3.12']
os: [ubuntu-latest]

steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Start Backend Container
run: |
docker compose down -v --remove-orphans
docker compose up --wait-timeout 5 -d
env:
COMPOSE_PROJECT_NAME: ${{ github.run_id }}-backend

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

- name: Cache pip
uses: actions/cache@v4
with:
path: ~/.cache/pip
key: ${{ runner.os }}-python-${{ matrix.python-version }}-tests-${{ hashFiles('requirements*.txt') }}
restore-keys: |
${{ runner.os }}-python-${{ matrix.python-version }}-tests-${{ hashFiles('requirements*.txt') }}
${{ runner.os }}-python-${{ matrix.python-version }}-tests-
${{ runner.os }}-python
${{ runner.os }}-

- name: Upgrade pip
run: python -m pip install --upgrade pip setuptools wheel

- name: Install dependencies
run: pip install -I -r requirements.txt -r requirements-test.txt

- name: Build package
run: |
python setup.py --version
python setup.py bdist_wheel sdist

- name: Run tests
run: |
mkdir reports/ || echo "Directory exists"
pip install -e . --no-build-isolation
source .env.local
./run_tests.sh

- name: Upload coverage results
uses: actions/upload-artifact@v4
with:
name: coverage-${{ matrix.python-version }}-os-${{ matrix.os }}
path: reports/*

- name: Shutdown Backend Container
if: always()
run: |
docker compose down -v --remove-orphans
env:
COMPOSE_PROJECT_NAME: ${{ github.run_id }}-backend

all_done:
name: Tests done
runs-on: ubuntu-latest
needs: [tests]

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Python ${{ env.DEFAULT_PYTHON }}
uses: actions/setup-python@v5
with:
python-version: ${{ env.DEFAULT_PYTHON }}

- name: Cache pip
uses: actions/cache@v4
with:
path: ~/.cache/pip
key: ${{ runner.os }}-python-${{ env.DEFAULT_PYTHON }}-coverage-${{ hashFiles('requirements*.txt') }}
restore-keys: |
${{ runner.os }}-python-${{ env.DEFAULT_PYTHON }}-coverage-${{ hashFiles('requirements*.txt') }}
${{ runner.os }}-python-${{ env.DEFAULT_PYTHON }}-coverage-
${{ runner.os }}-python
${{ runner.os }}-

- name: Upgrade pip
run: python -m pip install --upgrade pip setuptools wheel

- name: Install dependencies
run: pip install -I -r requirements-test.txt

- name: Download all coverage reports
uses: actions/download-artifact@v4
with:
path: reports

- name: Move coverage data to the root folder
run: find reports -type f -exec mv '{}' reports \;

- name: Generate coverate reports
run: ./combine_coverage.sh

- name: Check coverage
uses: codecov/codecov-action@v4
with:
token: ${{ secrets.CODECOV_TOKEN }}
file: ./reports/coverage.xml
fail_ci_if_error: true
# TODO: remove after fixing https://github.com/codecov/codecov-cli/issues/367
plugin: gcov

- name: All done
run: echo 1
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ services:
retries: 3

backend:
image: mtsrus/horizon-backend
image: mtsrus/horizon-backend:latest
restart: unless-stopped
env_file: .env.docker
ports:
Expand Down