forked from NOVUS-X/StellArts
-
Notifications
You must be signed in to change notification settings - Fork 0
156 lines (127 loc) · 4.14 KB
/
ci.yml
File metadata and controls
156 lines (127 loc) · 4.14 KB
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
name: CI
on:
push:
branches: [ main, develop ]
paths:
- 'backend/**'
- '.github/workflows/ci.yml'
pull_request:
branches: [ main, develop ]
paths:
- 'backend/**'
- '.github/workflows/ci.yml'
env:
PYTHON_VERSION: 3.11
WORKING_DIR: backend
jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: ${{ env.PYTHON_VERSION }}
cache: 'pip'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install flake8 black ruff
pip install -r ${{ env.WORKING_DIR }}/requirements.txt
- name: Lint with flake8
run: |
flake8 ${{ env.WORKING_DIR }}/app/ --count --select=E9,F63,F7,F82 --show-source --statistics
flake8 ${{ env.WORKING_DIR }}/app/ --count --exit-zero --max-complexity=10 --max-line-length=88 --statistics
- name: Lint with ruff
run: ruff check ${{ env.WORKING_DIR }}/app/
- name: Check formatting with black
run: black --check ${{ env.WORKING_DIR }}/app/
test:
runs-on: ubuntu-latest
services:
postgres:
image: postgres:15-alpine
env:
POSTGRES_USER: stellarts
POSTGRES_PASSWORD: stellarts_test
POSTGRES_DB: stellarts_test_db
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 5432:5432
redis:
image: redis:7-alpine
options: >-
--health-cmd "redis-cli ping"
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 6379:6379
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: ${{ env.PYTHON_VERSION }}
cache: 'pip'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r ${{ env.WORKING_DIR }}/requirements.txt
- name: Run tests
env:
DATABASE_URL: postgresql://stellarts:stellarts_test@localhost:5432/stellarts_test_db
REDIS_URL: redis://localhost:6379/0
REDIS_HOST: localhost
REDIS_PORT: 6379
SECRET_KEY: test-secret-key
DEBUG: True
STELLAR_ESCROW_PUBLIC: "GDUMMY"
run: |
pytest ${{ env.WORKING_DIR }}/app/tests/ -v --cov=${{ env.WORKING_DIR }}/app --cov-report=xml
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3
with:
file: ./coverage.xml
flags: unittests
name: codecov-umbrella
docker:
runs-on: ubuntu-latest
needs: [lint, test]
steps:
- uses: actions/checkout@v4
- name: Build Docker image
run: |
docker build -t stellarts-api:test ./backend
- name: Test Docker image
run: |
docker network create test-network
docker run -d --name test-db --network test-network \
-e POSTGRES_USER=stellarts \
-e POSTGRES_PASSWORD=stellarts_test \
-e POSTGRES_DB=stellarts_test_db \
-e POSTGRES_DB=stellarts_test_db \
postgres:15-alpine
docker run -d --name test-redis --network test-network \
-p 6379:6379 \
redis:7-alpine
sleep 10
docker run -d --name test-api --network test-network \
-e DATABASE_URL=postgresql://stellarts:stellarts_test@test-db:5432/stellarts_test_db \
-e REDIS_URL=redis://test-redis:6379/0 \
-e REDIS_HOST=test-redis \
-e REDIS_PORT=6379 \
-e SECRET_KEY=test-secret-key \
-e STELLAR_ESCROW_PUBLIC=GDUMMY \
-e DEBUG=True \
-p 8000:8000 \
stellarts-api:test
sleep 30
curl -f http://localhost:8000/api/v1/health || (docker logs test-api && exit 1)
docker stop test-api test-db test-redis
docker rm test-api test-db test-redis
docker network rm test-network