-
Notifications
You must be signed in to change notification settings - Fork 0
268 lines (232 loc) · 8.17 KB
/
python-package.yml
File metadata and controls
268 lines (232 loc) · 8.17 KB
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
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
# This workflow will install Python dependencies, run tests and lint with a variety of Python versions
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions
name: Python package
on:
push:
branches: [main]
tags: ["*"]
paths:
- .github/**
- src/**
- tests/**
- pyproject.toml
pull_request:
branches: [main]
paths:
- .github/**
- src/**
- tests/**
- pyproject.toml
permissions:
contents: write # Required for GitHub Release creation
id-token: write # Required for Trusted Publishing (only used in publish job)
jobs:
validate-tag:
name: Validate Tag
runs-on: ubuntu-latest
outputs:
version: ${{ steps.check.outputs.version }}
steps:
- uses: actions/checkout@v6
with:
fetch-depth: 0
- name: Check tag format (PEP 440)
id: check
run: |
python3 -m pip install --disable-pip-version-check packaging
python3 .github/scripts/validate_version.py
env:
GITHUB_REF: ${{ github.ref }}
lint:
name: Code style check
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- name: Lint check with ruff
uses: astral-sh/ruff-action@v3
type-check:
name: Type Check (Python ${{ matrix.python-version }})
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.10", "3.11", "3.12", "3.13", "3.14"]
steps:
- uses: actions/checkout@v6
- name: Install uv
uses: astral-sh/setup-uv@v6
with:
enable-cache: true
cache-dependency-glob: "pyproject.toml"
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: uv sync --group typecheck
- name: Static check with mypy
run: uv run --no-dev mypy
test:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.10", "3.11", "3.12", "3.13", "3.14"]
services:
# MSSQL is slowest (start-period 60s), put first
mssql:
image: mcr.microsoft.com/mssql/server:2022-latest
env:
MSSQL_SA_PASSWORD: "YourStrongPassword123"
MSSQL_PID: "Developer"
ACCEPT_EULA: "Y"
options: >-
--health-cmd "/opt/mssql-tools18/bin/sqlcmd -C -S localhost -U sa -P YourStrongPassword123 -Q 'SELECT 1'"
--health-interval 10s
--health-timeout 30s
--health-retries 5
--health-start-period 60s
ports:
- 1433:1433
mysql:
image: mysql
env:
MYSQL_RANDOM_ROOT_PASSWORD: "1"
MYSQL_DATABASE: test
MYSQL_USER: test
MYSQL_PASSWORD: test
options: >-
--health-cmd "mysqladmin ping -h 127.0.0.1 -u $$MYSQL_USER --password=$$MYSQL_PASSWORD"
ports:
- 3306:3306
# PostgreSQL alpine is fastest, put last
postgres:
image: postgres:alpine
env:
POSTGRES_PASSWORD: test
options: >-
--health-cmd "pg_isready -U postgres -h 127.0.0.1"
ports:
- 5432:5432
# NOTE: Oracle is set up via gvenzl/setup-oracle-free@v1 action
# instead of service container, for better reliability
steps:
- uses: actions/checkout@v6
- name: Install MSSQL ODBC driver
run: |
# Download and install Microsoft package repository
wget -qO- https://packages.microsoft.com/config/ubuntu/$(lsb_release -rs)/packages-microsoft-prod.deb -O packages-microsoft-prod.deb
sudo dpkg -i packages-microsoft-prod.deb
# Update and install ODBC driver
sudo apt-get update
sudo ACCEPT_EULA=Y apt-get install -y msodbcsql18
- name: Install uv
uses: astral-sh/setup-uv@v6
with:
enable-cache: true
python-version: ${{ matrix.python-version }}
# NOTE: Oracle testing requires full Oracle Database installation
# Oracle Database Free (23c/23ai) does NOT support DBMS_LOCK.REQUEST
# which is required for distributed lock functionality. This is a known
# limitation of the Free/Express edition. CI cannot test Oracle; use
# local testing with a full Oracle Database installation.
#
# For local Oracle testing:
# docker compose -f db.docker-compose.yml up
# OR use a self-hosted runner with access to Oracle Enterprise/Standard
#
# Reference: https://github.com/gvenzl/oci-oracle-free
# The "slim" and "full" flavors of gvenzl/oracle-free both lack
# DBMS_LOCK.REQUEST support as it's not included in Oracle Free edition.
- name: Install the project
env:
SETUPTOOLS_SCM_PRETEND_VERSION: "0"
run: |
uv sync --no-dev --group test
uv pip install mysqlclient aiomysql psycopg2 asyncpg pyodbc aioodbc oracledb
- name: Run tests
shell: bash
env:
TEST_URLS: mysql://test:test@127.0.0.1:3306/test postgresql://postgres:test@127.0.0.1:5432/ mssql+pyodbc://sa:YourStrongPassword123@127.0.0.1:1433/master?driver=ODBC+Driver+18+for+SQL+Server&TrustServerCertificate=yes
TEST_ASYNC_URLS: mysql+aiomysql://test:test@127.0.0.1:3306/test postgresql+asyncpg://postgres:test@127.0.0.1:5432/ mssql+aioodbc://sa:YourStrongPassword123@127.0.0.1:1433/master?driver=ODBC+Driver+18+for+SQL+Server&TrustServerCertificate=yes
run: |
uv run --no-dev coverage run -m unittest -cfv
uv run --no-dev coverage report -m
uv run --no-dev coverage xml
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v5
with:
token: ${{ secrets.CODECOV_TOKEN }}
build:
name: Build Distribution
runs-on: ubuntu-latest
needs: [lint, type-check, test, validate-tag]
if: needs.validate-tag.outputs.version != ''
steps:
- uses: actions/checkout@v6
- name: Install uv
uses: astral-sh/setup-uv@v7
with:
enable-cache: true
cache-dependency-glob: "pyproject.toml"
- name: Build package
run: uv build
env:
SETUPTOOLS_SCM_PRETEND_VERSION: ${{ needs.validate-tag.outputs.version }}
- name: Store the distribution packages
uses: actions/upload-artifact@v6
with:
name: python-package-distributions
path: dist/
publish:
name: Publish to PyPI
runs-on: ubuntu-latest
needs: [validate-tag, build]
if: needs.validate-tag.outputs.version != ''
environment:
name: pypi
url: https://pypi.org/p/sqlalchemy-dlock
steps:
- name: Download distribution packages
uses: actions/download-artifact@v7
with:
name: python-package-distributions
path: dist/
- name: Publish to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
skip-existing: true
verbose: true
github-release:
name: Create GitHub Release
runs-on: ubuntu-latest
needs: [validate-tag, build]
if: needs.validate-tag.outputs.version != ''
permissions:
contents: write
steps:
- uses: actions/checkout@v5
- name: Download distribution packages
uses: actions/download-artifact@v7
with:
name: python-package-distributions
path: dist/
- name: Generate release notes from CHANGELOG
id: release_notes
run: |
VERSION="${{ needs.validate-tag.outputs.version }}"
awk -v version="$VERSION" '
/^##[[:space:]]*$version/ { in_release=1; next }
in_release && /^##[[:space:]]/ { exit }
in_release { print }
' CHANGELOG.md > release_notes.md
{
echo "notes<<EOF"
cat release_notes.md
echo "EOF"
} >> "$GITHUB_OUTPUT"
- name: Create GitHub Release
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ github.ref }}
name: v${{ needs.validate-tag.outputs.version }}
body: ${{ steps.release_notes.outputs.notes }}
files: dist/*
generate_release_notes: false
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}