-
Notifications
You must be signed in to change notification settings - Fork 2
193 lines (159 loc) · 5.56 KB
/
python3.yml
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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
name: Build, Lint, Test & Scan
on:
push:
pull_request:
jobs:
docs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Setup the environment
run: |
python3 -V
python3 -m pip install --upgrade pip
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
- name: Build docs using Sphinx
working-directory: docs
run: |
pip install -r requirements.txt
make html
- name: Save HTML docs
uses: actions/upload-artifact@v3
with:
name: docs
path: docs/build/html
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Setup the environment
run: |
python3 -V
python3 -m pip install --upgrade pip
pip install flake8 pytest pylint
pip install -r requirements.txt
- name: Lint with flake8
run: |
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
flake8 . --count --exit-zero --max-complexity=12 --max-line-length=120 --statistics
- name: Lint with PyLint
run: pylint matebot_core/ -j 0 && echo "OK" || echo "FAIL"
test-sqlite:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python-version: [ "3.7", "3.8", "3.9", "3.10", "3.11" ]
steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies and setup the environment
run: |
python3 -V
python3 -m pip install --upgrade pip
pip install -r requirements.txt
- name: Run unittests with temporary sqlite3
run: python3 -X tracemalloc=5 -m unittest tests -v
test-mariadb:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11"]
image:
- mariadb:10.5
- mariadb:10.9
- mariadb:10.10
python-lib:
- mysqlclient
- pymysql
services:
database:
image: ${{ matrix.image }}
env:
MARIADB_USER: username
MARIADB_PASSWORD: password
MARIADB_DATABASE: db
MARIADB_ALLOW_EMPTY_ROOT_PASSWORD: yes
ports:
- 127.0.0.1:3306:3306/tcp
options: >-
--health-cmd="mysqladmin ping"
--health-interval 5s
--health-timeout 3s
--health-retries 3
steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python-version }}
- name: Install extra C dependency
run: sudo apt install default-libmysqlclient-dev build-essential -y
if: ${{ matrix.python-lib == 'mysqlclient' }}
- name: Install dependencies and setup the environment
run: |
python3 -V
python3 -m pip install --upgrade pip
pip install ${{ matrix.python-lib }}
pip install -r requirements.txt
- name: Prepare config for pymysql
run: |
python3 -m matebot_core init --database mysql+pymysql://username:password@127.0.0.1/db?charset=utf8mb4 --no-migrations --no-community
echo -e '\nDATABASE_URL = "mysql+pymysql://username:password@127.0.0.1/db?charset=utf8mb4"' >> tests/conf.py
if: ${{ matrix.python-lib == 'pymysql' }}
- name: Prepare config for mysqlclient
run: |
python3 -m matebot_core init --database mysql+mysqldb://username:password@127.0.0.1/db?charset=utf8mb4 --no-migrations --no-community
echo -e '\nDATABASE_URL = "mysql+mysqldb://username:password@127.0.0.1/db?charset=utf8mb4"' >> tests/conf.py
if: ${{ matrix.python-lib == 'mysqlclient' }}
- name: Perform database migrations
run: |
alembic upgrade head
rm -fv config.json
- name: Prepare unittests
run: |
echo 'COMMAND_INITIALIZE_DATABASE = ["/bin/bash", ".github/workflows/test_mysql_setup.sh"]' >> tests/conf.py
echo 'COMMAND_CLEANUP_DATABASE = ["/bin/bash", ".github/workflows/test_mysql_teardown.sh"]' >> tests/conf.py
bash .github/workflows/test_mysql_setup.sh
bash .github/workflows/test_mysql_teardown.sh
sync
- name: Run unittests
run: python3 -X tracemalloc=5 -m unittest tests -v
- name: Read log file
run: |
if [ -f mysql.log ]; then cat mysql.log; fi
rm -fv mysql.log
docker:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Build Docker image
uses: docker/build-push-action@v3
with:
context: .
tags: matebot_core:latest
- name: Run Docker image shortly
run: timeout -v --preserve-status 10s docker run --rm -e DATABASE_CONNECTION=sqlite:///test.db matebot_core:latest
- name: Run the SQLite tests in the image
run: docker run --rm --entrypoint bash -e DATABASE_CONNECTION=sqlite:///test.db matebot_core:latest -c "python3 -m unittest tests -v"
analyze:
runs-on: ubuntu-latest
permissions:
actions: read
contents: read
security-events: write
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Initialize CodeQL
uses: github/codeql-action/init@v2
with:
languages: python
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2
with:
category: "/language:python"