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
0 commit comments