-
Notifications
You must be signed in to change notification settings - Fork 0
109 lines (89 loc) · 3.36 KB
/
upload-test.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
name: CI Workflow
on:
push:
branches:
- main
pull_request:
jobs:
test:
runs-on: ubuntu-latest
name: Host Databases, Run Tests, and Upload Coverage Reports
steps:
- uses: actions/checkout@v4
# Install Docker
- name: Install Docker
run: |
sudo apt-get update
sudo apt-get install -y apt-transport-https ca-certificates curl software-properties-common
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
sudo apt-get update
sudo apt-get install -y docker-ce
# Install Docker Compose
- name: Install Docker Compose
run: |
DOCKER_COMPOSE_VERSION=1.29.2 # Specify the desired version
sudo curl -L "https://github.com/docker/compose/releases/download/$DOCKER_COMPOSE_VERSION/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose
# Verify installations
- name: Verify Docker and Docker Compose Installation
run: |
docker --version
docker-compose --version
- name: Build and Start Docker Containers
run: |
docker-compose -f ./docker-compose.yaml up -d
# Wait for the databases to be healthy
- name: Wait for Databases to be Ready
run: |
for port in 5432 5433; do
until nc -z localhost $port; do
sleep 1 # wait for 1 second before checking again
done
done
- name: Run docker process to check for containers
run: docker ps -a
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.9'
# Install and configure Poetry
- name: Install and configure Poetry
uses: snok/install-poetry@v1
with:
virtualenvs-create: true
virtualenvs-in-project: true
# Load cached venv if cache exists
- name: Load cached venv
id: cached-poetry-dependencies
uses: actions/cache@v4
with:
path: .venv
key: venv-${{ runner.os }}-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('**/poetry.lock') }}
# Install dependencies if cache does not exist
- name: Install dependencies
if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true'
run: poetry install --verbose --no-interaction --no-root
# Install your root project if required
- name: Install project
run: poetry install --verbose --no-interaction
- name: Run docker process to check for containers
run: docker ps -a
- name: Run docker compose logs
run: docker compose logs
# Run tests and generate coverage report
- name: Run Tests with Coverage
run: |
poetry run pytest --cov=pgbase tests/
# Save coverage report to a specific file
mkdir -p coverage-reports
mv .coverage coverage-reports/coverage.xml
# Stop and remove the containers after tests
- name: Stop Docker Containers
run: docker-compose -f docker-compose.yaml down
# Upload Coverage Report to Codecov
- name: Upload Coverage Reports to Codecov
run: |
curl -Os https://uploader.codecov.io/latest/linux/codecov
chmod +x codecov
./codecov -t ${{ secrets.CODECOV_TOKEN }} -f coverage-reports/coverage.xml