Skip to content

Commit afc99a8

Browse files
author
Peng Ren
committed
Add release workflow
1 parent 40f4110 commit afc99a8

3 files changed

Lines changed: 354 additions & 1 deletion

File tree

.github/workflows/release.yml

Lines changed: 270 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,270 @@
1+
name: Release
2+
3+
on:
4+
push:
5+
tags: [ '*.*.*' ]
6+
7+
env:
8+
PYTHON_VERSION: "3.11"
9+
MONGODB_VERSION: "8.0"
10+
11+
jobs:
12+
lint-and-format:
13+
name: Code Quality Checks
14+
runs-on: ubuntu-latest
15+
16+
steps:
17+
- uses: actions/checkout@v4
18+
19+
- name: Set up Python ${{ env.PYTHON_VERSION }}
20+
uses: actions/setup-python@v4
21+
with:
22+
python-version: ${{ env.PYTHON_VERSION }}
23+
24+
- name: Cache pip dependencies
25+
uses: actions/cache@v3
26+
with:
27+
path: ~/.cache/pip
28+
key: ${{ runner.os }}-pip-lint-${{ hashFiles('**/requirements-test.txt', 'pyproject.toml') }}
29+
restore-keys: |
30+
${{ runner.os }}-pip-lint-
31+
32+
- name: Install dependencies
33+
run: |
34+
python -m pip install --upgrade pip
35+
pip install -r requirements-test.txt
36+
pip install black isort
37+
38+
- name: Check code formatting with Black
39+
run: |
40+
black --check --diff pymongosql/
41+
42+
- name: Check import sorting with isort
43+
run: |
44+
isort --check-only --diff pymongosql/
45+
46+
- name: Lint with flake8
47+
run: |
48+
flake8 pymongosql/ --count --statistics
49+
50+
test:
51+
name: Test Suite
52+
runs-on: ubuntu-latest
53+
strategy:
54+
fail-fast: false
55+
matrix:
56+
python-version: ['3.9', '3.10', '3.11', '3.12', '3.13']
57+
mongodb-version: ['7.0', '8.0']
58+
59+
services:
60+
mongodb:
61+
image: mongo:${{ matrix.mongodb-version }}
62+
env:
63+
MONGO_INITDB_ROOT_USERNAME: admin
64+
MONGO_INITDB_ROOT_PASSWORD: secret
65+
ports:
66+
- 27017:27017
67+
options: >-
68+
--health-cmd "mongosh --eval 'db.runCommand({ping: 1})' --quiet"
69+
--health-interval 30s
70+
--health-timeout 10s
71+
--health-retries 5
72+
73+
steps:
74+
- uses: actions/checkout@v4
75+
76+
- name: Set up Python ${{ matrix.python-version }}
77+
uses: actions/setup-python@v4
78+
with:
79+
python-version: ${{ matrix.python-version }}
80+
81+
- name: Cache pip dependencies
82+
uses: actions/cache@v3
83+
with:
84+
path: ~/.cache/pip
85+
key: ${{ runner.os }}-py${{ matrix.python-version }}-mongo${{ matrix.mongodb-version }}-pip-${{ hashFiles('**/requirements-test.txt', 'pyproject.toml') }}
86+
restore-keys: |
87+
${{ runner.os }}-py${{ matrix.python-version }}-mongo${{ matrix.mongodb-version }}-pip-
88+
89+
- name: Install MongoDB shell
90+
run: |
91+
wget -qO - https://www.mongodb.org/static/pgp/server-7.0.asc | sudo apt-key add -
92+
echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu jammy/mongodb-org/7.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-7.0.list
93+
sudo apt-get update
94+
sudo apt-get install -y mongodb-mongosh
95+
96+
- name: Install dependencies
97+
run: |
98+
python -m pip install --upgrade pip
99+
pip install -r requirements-test.txt
100+
pip install -e .
101+
102+
- name: Wait for MongoDB to be ready
103+
run: |
104+
echo "Waiting for MongoDB to be ready..."
105+
for i in {1..30}; do
106+
if mongosh --host localhost:27017 --username admin --password secret --authenticationDatabase admin --eval "db.runCommand({ping: 1})" --quiet; then
107+
echo "MongoDB is ready!"
108+
break
109+
fi
110+
echo "Attempt $i: MongoDB not ready yet, waiting..."
111+
sleep 2
112+
done
113+
114+
- name: Set up test database
115+
run: |
116+
echo "Setting up test database..."
117+
python tests/run_test_server.py setup || true
118+
119+
- name: Run tests with coverage
120+
run: |
121+
python -m pytest tests/ -v --cov=pymongosql --cov-report=term-missing --cov-report=xml --cov-report=html
122+
123+
- name: Upload coverage to Codecov
124+
uses: codecov/codecov-action@v4
125+
if: matrix.python-version == '3.11' && matrix.mongodb-version == '8.0'
126+
with:
127+
env_vars: OS,PYTHON
128+
token: ${{ secrets.CODECOV_TOKEN }}
129+
files: ./coverage.xml
130+
flags: unittests
131+
fail_ci_if_error: false
132+
133+
- name: Upload coverage artifacts
134+
uses: actions/upload-artifact@v3
135+
if: matrix.python-version == '3.11' && matrix.mongodb-version == '8.0'
136+
with:
137+
name: coverage-report
138+
path: htmlcov/
139+
140+
build:
141+
name: Build Distribution
142+
runs-on: ubuntu-latest
143+
needs: [lint-and-format, test]
144+
145+
steps:
146+
- uses: actions/checkout@v4
147+
with:
148+
# Fetch full history for setuptools_scm
149+
fetch-depth: 0
150+
151+
- name: Set up Python ${{ env.PYTHON_VERSION }}
152+
uses: actions/setup-python@v4
153+
with:
154+
python-version: ${{ env.PYTHON_VERSION }}
155+
156+
- name: Install build dependencies
157+
run: |
158+
python -m pip install --upgrade pip
159+
pip install build twine setuptools_scm[toml]
160+
161+
- name: Build source and wheel distributions
162+
run: |
163+
python -m build
164+
165+
- name: Check distribution
166+
run: |
167+
twine check dist/*
168+
169+
- name: List built packages
170+
run: |
171+
ls -la dist/
172+
173+
- name: Upload build artifacts
174+
uses: actions/upload-artifact@v3
175+
with:
176+
name: dist
177+
path: dist/
178+
179+
pypi-publish:
180+
name: Publish to PyPI
181+
runs-on: ubuntu-latest
182+
needs: build
183+
environment:
184+
name: pypi
185+
url: https://pypi.org/p/pymongosql
186+
187+
steps:
188+
- name: Download build artifacts
189+
uses: actions/download-artifact@v3
190+
with:
191+
name: dist
192+
path: dist/
193+
194+
- name: Publish to PyPI
195+
uses: pypa/gh-action-pypi-publish@release/v1
196+
with:
197+
password: ${{ secrets.PYPI_API_TOKEN }}
198+
199+
create-github-release:
200+
name: Create GitHub Release
201+
runs-on: ubuntu-latest
202+
needs: [build, pypi-publish]
203+
204+
steps:
205+
- uses: actions/checkout@v4
206+
with:
207+
fetch-depth: 0
208+
209+
- name: Download build artifacts
210+
uses: actions/download-artifact@v3
211+
with:
212+
name: dist
213+
path: dist/
214+
215+
- name: Extract version from tag
216+
id: version
217+
run: echo "version=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT
218+
219+
- name: Create GitHub Release
220+
uses: softprops/action-gh-release@v1
221+
with:
222+
files: dist/*
223+
generate_release_notes: true
224+
name: Release ${{ steps.version.outputs.version }}
225+
body: |
226+
## PyMongoSQL ${{ steps.version.outputs.version }}
227+
228+
### Installation
229+
230+
```bash
231+
pip install pymongosql==${{ steps.version.outputs.version }}
232+
```
233+
234+
### What's New
235+
236+
See the automatically generated release notes below for detailed changes.
237+
238+
security-scan:
239+
name: Security Scan
240+
runs-on: ubuntu-latest
241+
needs: build
242+
243+
steps:
244+
- uses: actions/checkout@v4
245+
246+
- name: Set up Python ${{ env.PYTHON_VERSION }}
247+
uses: actions/setup-python@v4
248+
with:
249+
python-version: ${{ env.PYTHON_VERSION }}
250+
251+
- name: Install security tools
252+
run: |
253+
python -m pip install --upgrade pip
254+
pip install safety bandit[toml]
255+
256+
- name: Run safety check
257+
run: |
258+
safety check --json --output safety-report.json || true
259+
260+
- name: Run bandit security scan
261+
run: |
262+
bandit -r pymongosql/ -f json -o bandit-report.json || true
263+
264+
- name: Upload security scan results
265+
uses: actions/upload-artifact@v3
266+
with:
267+
name: security-reports
268+
path: |
269+
safety-report.json
270+
bandit-report.json

MANIFEST.in

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Include the README and LICENSE files
2+
include README.md
3+
include LICENSE
4+
5+
# Include requirements files
6+
include requirements.txt
7+
include requirements-test.txt
8+
9+
# Include configuration files
10+
include pyproject.toml
11+
include .flake8
12+
13+
# Exclude unnecessary files
14+
global-exclude *.pyc
15+
global-exclude *.pyo
16+
global-exclude __pycache__
17+
global-exclude .git*
18+
global-exclude .pytest_cache
19+
global-exclude .coverage
20+
global-exclude htmlcov
21+
global-exclude build
22+
global-exclude dist
23+
global-exclude *.egg-info
24+
25+
# Exclude test files and data
26+
global-exclude tests
27+
recursive-exclude tests *
28+
29+
# Include ANTLR4 generated files
30+
recursive-include pymongosql/sql/partiql *.py

pyproject.toml

Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,56 @@
22
requires = ["setuptools>=45", "wheel", "setuptools_scm[toml]>=6.2"]
33
build-backend = "setuptools.build_meta"
44

5+
[project]
6+
name = "pymongosql"
7+
dynamic = ["version"]
8+
description = "Python DB API 2.0 client for MongoDB with SQL interface"
9+
readme = "README.md"
10+
license = {file = "LICENSE"}
11+
authors = [
12+
{name = "Peng Ren", email = "passren9099@hotmail.com"}
13+
]
14+
maintainers = [
15+
{name = "Peng Ren", email = "passren9099@hotmail.com"}
16+
]
17+
keywords = ["mongodb", "sql", "database", "dbapi", "nosql"]
18+
classifiers = [
19+
"Development Status :: 3 - Alpha",
20+
"Intended Audience :: Developers",
21+
"License :: OSI Approved :: MIT License",
22+
"Operating System :: OS Independent",
23+
"Programming Language :: Python :: 3",
24+
"Programming Language :: Python :: 3.9",
25+
"Programming Language :: Python :: 3.10",
26+
"Programming Language :: Python :: 3.11",
27+
"Programming Language :: Python :: 3.12",
28+
"Programming Language :: Python :: 3.13",
29+
"Topic :: Database",
30+
"Topic :: Database :: Database Engines/Servers",
31+
"Topic :: Software Development :: Libraries :: Python Modules",
32+
]
33+
requires-python = ">=3.9"
34+
dependencies = [
35+
"pymongo>=4.15.0",
36+
"antlr4-python3-runtime>=4.13.0",
37+
]
38+
39+
[project.optional-dependencies]
40+
dev = [
41+
"pytest>=7.0.0",
42+
"pytest-cov>=4.0.0",
43+
"flake8>=6.0.0",
44+
"flake8-pyproject>=1.2.0",
45+
"black>=23.0.0",
46+
"isort>=5.12.0",
47+
]
48+
49+
[project.urls]
50+
Homepage = "https://github.com/passren/PyMongoSQL"
51+
Repository = "https://github.com/passren/PyMongoSQL.git"
52+
Documentation = "https://github.com/passren/PyMongoSQL/wiki"
53+
"Bug Reports" = "https://github.com/passren/PyMongoSQL/issues"
54+
555
[tool.black]
656
line-length = 120
757
target-version = ['py39']
@@ -58,4 +108,7 @@ show_missing = true
58108
precision = 2
59109

60110
[tool.coverage.html]
61-
directory = "htmlcov"
111+
directory = "htmlcov"
112+
113+
[tool.setuptools.dynamic]
114+
version = {attr = "pymongosql.__version__"}

0 commit comments

Comments
 (0)