Skip to content

Commit c8b412a

Browse files
authored
Create python-package.yml Github workflow (#1)
* Create python-package.yml Github workflow WIP: no testing yet (depends on MySQL Docker container) * WIP: trying to get yoyo migrations and unittests running in Github workflow * WIP: Trying to fix testing in Github action by providing .env.github configuration * WIP: Trying to fix DB connection in Github action * override .env.test for Github actions * fixing some tests in Github action * mark Github workflow as completed in README
1 parent 08e49d5 commit c8b412a

File tree

5 files changed

+77
-4
lines changed

5 files changed

+77
-4
lines changed

.env.docker

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,3 @@ LOG_LEVEL=DEBUG
1414
# LOG_FILE=/tmp/policyd-rate-guard.log
1515
LOG_CONSOLE=True
1616
# SYSLOG=True
17-
# SENTRY_DSN=https://**********.ingest.sentry.io/XXXXXXXXXXXXXXXX
18-
# SENTRY_ENVIRONMENT=docker

.env.github

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
2+
## Database configuration
3+
DB_DRIVER=pymysql
4+
DB_HOST=127.0.0.1
5+
DB_PORT=3306
6+
DB_USER=root
7+
DB_PASSWORD=test
8+
DB_DATABASE=test
9+
10+
## PolicydRateGuard configuration
11+
SOCKET="127.0.0.1,10033"
12+
# SOCKET=/tmp/test.sock
13+
LOG_LEVEL=ERROR
14+
# LOG_FILE=/tmp/policyd-rate-guard.log
15+
LOG_CONSOLE=True
16+
# SYSLOG=True
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# This workflow will install Python dependencies, run tests and lint with a variety of Python versions
2+
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python
3+
4+
name: Python package
5+
6+
on:
7+
push:
8+
branches: [ "main" ]
9+
pull_request:
10+
branches: [ "main" ]
11+
12+
jobs:
13+
build:
14+
15+
runs-on: ubuntu-latest
16+
strategy:
17+
fail-fast: false
18+
matrix:
19+
python-version: ["3.9", "3.10", "3.11"]
20+
21+
services:
22+
db:
23+
image: mysql:8.0
24+
env:
25+
MYSQL_ROOT_PASSWORD: test
26+
MYSQL_DATABASE: test
27+
ports:
28+
- 3306:3306
29+
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3
30+
31+
steps:
32+
- uses: actions/checkout@v3
33+
- name: Set up Python ${{ matrix.python-version }}
34+
uses: actions/setup-python@v3
35+
with:
36+
python-version: ${{ matrix.python-version }}
37+
- name: Install dependencies
38+
run: |
39+
python -m pip install --upgrade pip
40+
python -m pip install flake8
41+
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
42+
- name: Lint with flake8
43+
run: |
44+
# stop the build if there are Python syntax errors or undefined names
45+
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
46+
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
47+
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
48+
- name: Run migrations
49+
run: |
50+
yoyo -c yoyo.ini.github apply
51+
- name: Run tests
52+
run: |
53+
cp .env.github .env.test
54+
python -m unittest tests/test_*.py

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -377,9 +377,9 @@ Planned features (coming soon):
377377
- [x] Define **Syslog facility** `LOG_MAIL`, **ident** `policyd-rate-guard`, and additionally log to `/var/log/policyd-rate-guard.log`
378378
- [x] **Sentry** integration for exception reporting
379379
- [x] **Ansible role** for easy production deployment
380+
- [x] **Github workflow** for CI/testing
381+
- [ ] **Publish package** to [PyPI](https://pypi.org/)
380382
- [ ] Implement a **configurable webhook API** call for notification to sender on reaching quota limit (on first block) to external service.
381-
- [ ] CI: **Github action** for testing
382-
- [ ] Publish to PyPI
383383

384384
## Credits 🙏
385385

yoyo.ini.github

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[DEFAULT]
2+
sources = database/migrations
3+
database = mysql://root:test@localhost:3306/test
4+
batch_mode = on
5+
verbosity = 2

0 commit comments

Comments
 (0)