1+ name : CI
2+
3+ on :
4+ push :
5+ branches : [ main, develop ]
6+ pull_request :
7+ branches : [ main ]
8+
9+ jobs :
10+ test :
11+ runs-on : ubuntu-latest
12+ strategy :
13+ matrix :
14+ python-version : [3.12]
15+
16+ services :
17+ postgres :
18+ image : postgres:15
19+ env :
20+ POSTGRES_PASSWORD : postgres
21+ POSTGRES_DB : vpn_bot_test
22+ ports :
23+ - 5432:5432
24+ options : >-
25+ --health-cmd pg_isready
26+ --health-interval 10s
27+ --health-timeout 5s
28+ --health-retries 5
29+
30+ steps :
31+ - uses : actions/checkout@v4
32+
33+ - name : Set up Python ${{ matrix.python-version }}
34+ uses : actions/setup-python@v4
35+ with :
36+ python-version : ${{ matrix.python-version }}
37+
38+ - name : Cache dependencies
39+ uses : actions/cache@v3
40+ with :
41+ path : ~/.cache/pip
42+ key : ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}
43+ restore-keys : |
44+ ${{ runner.os }}-pip-
45+
46+ - name : Install dependencies
47+ run : |
48+ python -m pip install --upgrade pip
49+ pip install -r requirements.txt
50+
51+ - name : Run linting
52+ run : |
53+ # Stop the build if there are Python syntax errors or undefined names
54+ ruff check bot/ --select=E9,F63,F7,F82 --show-source --statistics
55+ # Treat all other issues as warnings
56+ ruff check bot/ --exit-zero --statistics
57+
58+ - name : Check code formatting
59+ run : |
60+ black --check bot/
61+
62+ - name : Type checking
63+ run : |
64+ # Install mypy if not in requirements
65+ pip install mypy types-requests
66+ mypy bot/ --ignore-missing-imports
67+
68+ - name : Run tests
69+ env :
70+ BOT_TOKEN : " test_token"
71+ ADMIN_TG_ID : " 123456789"
72+ DB_URL : " postgresql+asyncpg://postgres:postgres@localhost:5432/vpn_bot_test"
73+ run : |
74+ pytest tests/ -v --cov=bot --cov-report=xml
75+
76+ - name : Upload coverage to Codecov
77+ uses : codecov/codecov-action@v3
78+ with :
79+ file : ./coverage.xml
80+ flags : unittests
81+ name : codecov-umbrella
82+
83+ security :
84+ runs-on : ubuntu-latest
85+ steps :
86+ - uses : actions/checkout@v4
87+
88+ - name : Set up Python
89+ uses : actions/setup-python@v4
90+ with :
91+ python-version : 3.12
92+
93+ - name : Install dependencies
94+ run : |
95+ python -m pip install --upgrade pip
96+ pip install bandit safety
97+
98+ - name : Run security checks
99+ run : |
100+ bandit -r bot/ -f json -o bandit-report.json || true
101+ safety check --json --output safety-report.json || true
102+
103+ - name : Upload security reports
104+ uses : actions/upload-artifact@v3
105+ with :
106+ name : security-reports
107+ path : |
108+ bandit-report.json
109+ safety-report.json
110+
111+ docker :
112+ runs-on : ubuntu-latest
113+ steps :
114+ - uses : actions/checkout@v4
115+
116+ - name : Build Docker image
117+ run : |
118+ docker build -t vpn-bot:test .
119+
120+ - name : Test Docker image
121+ run : |
122+ # Test that the image can be created and basic imports work
123+ docker run --rm vpn-bot:test python -c "import bot; print('Import successful')"
0 commit comments