Skip to content

Commit b503c1d

Browse files
committed
100% passing tests. Also implementing Github Actions for managing versioning and uploading to Pypi
1 parent e1bb39c commit b503c1d

6 files changed

Lines changed: 525 additions & 431 deletions

File tree

.github/workflows/release.yml

Lines changed: 167 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,167 @@
1+
name: Release Workflow
2+
3+
on:
4+
# Trigger on pushes to branches starting with 'release/'
5+
push:
6+
branches:
7+
- 'release/*'
8+
# Trigger on Pull Requests targeting branches starting with 'release/'
9+
pull_request:
10+
branches:
11+
- 'release/*'
12+
13+
# Default permissions required for most jobs
14+
permissions:
15+
contents: read
16+
17+
jobs:
18+
# --------------------------------------------------
19+
# Job 1: Linting and Testing (Runs on push and PR)
20+
# --------------------------------------------------
21+
# --------------------------------------------------
22+
# Job 1: Linting and Testing (Runs on push and PR)
23+
# --------------------------------------------------
24+
lint_test:
25+
name: Lint & Test
26+
runs-on: ubuntu-latest
27+
steps:
28+
- name: Checkout code
29+
uses: actions/checkout@v4
30+
with:
31+
fetch-depth: 0 # Needed for pre-commit checks on changed files
32+
33+
- name: Set up Python
34+
uses: actions/setup-python@v5
35+
with:
36+
python-version: '3.13' # Specify your desired Python version
37+
38+
# Install uv
39+
- name: Install uv
40+
run: curl -LsSf https://astral.sh/uv/install.sh | sh
41+
shell: bash
42+
43+
# Add uv to the PATH
44+
- name: Add uv to PATH
45+
run: echo "$HOME/.cargo/bin" >> $GITHUB_PATH
46+
shell: bash
47+
48+
- name: Install dependencies with uv
49+
run: |
50+
# Install packages from requirements.txt and additional tools
51+
uv pip install -r requirements.txt pytest pytest-cov pre-commit build twine
52+
53+
- name: Run pre-commit hooks
54+
uses: pre-commit/action@v3.0.1
55+
# pre-commit might internally use pip/virtualenv, uv installation
56+
# primarily affects the main dependency installation step.
57+
58+
- name: Run tests with coverage
59+
run: pytest --cov=sqlmodel_crud_utils --cov-report=xml --cov-report=term # Generate XML and terminal reports
60+
61+
- name: Upload coverage report
62+
uses: actions/upload-artifact@v4
63+
with:
64+
name: coverage-report
65+
path: coverage.xml
66+
if-no-files-found: error # Fail if coverage.xml is not generated
67+
68+
# --------------------------------------------------
69+
# Job 2: Build Package (Runs only on push to release/*)
70+
# --------------------------------------------------
71+
build:
72+
name: Build Package
73+
needs: lint_test # Depends on successful linting and testing
74+
# Only run this job on direct pushes to release/* branches, not on PRs
75+
if: github.event_name == 'push' && startsWith(github.ref, 'refs/heads/release/')
76+
runs-on: ubuntu-latest
77+
steps:
78+
- name: Checkout code
79+
uses: actions/checkout@v4
80+
81+
- name: Set up Python
82+
uses: actions/setup-python@v5
83+
with:
84+
python-version: '3.11' # Match the version used for testing
85+
86+
- name: Install build dependencies
87+
run: |
88+
python -m pip install --upgrade pip
89+
pip install build
90+
91+
- name: Build source distribution and wheel
92+
run: python -m build
93+
94+
- name: Upload build artifacts
95+
uses: actions/upload-artifact@v4
96+
with:
97+
name: python-package-distributions
98+
path: dist/
99+
if-no-files-found: error # Fail if build artifacts aren't found
100+
101+
# --------------------------------------------------
102+
# Job 3: Create GitHub Release (Runs only on push to release/*)
103+
# --------------------------------------------------
104+
create_release:
105+
name: Create GitHub Release
106+
needs: build # Depends on successful build
107+
# Only run this job on direct pushes to release/* branches
108+
if: github.event_name == 'push' && startsWith(github.ref, 'refs/heads/release/')
109+
runs-on: ubuntu-latest
110+
permissions:
111+
contents: write # Required to create releases and tags
112+
steps:
113+
- name: Checkout code
114+
uses: actions/checkout@v4
115+
116+
- name: Download build artifacts
117+
uses: actions/download-artifact@v4
118+
with:
119+
name: python-package-distributions
120+
path: dist
121+
122+
- name: Extract version from branch name
123+
id: get_version
124+
# Assumes branch name is like 'release/v1.2.3'
125+
# Extracts 'v1.2.3' as the tag name
126+
run: echo "TAG_NAME=${GITHUB_REF#refs/heads/release/}" >> $GITHUB_OUTPUT
127+
128+
- name: Create GitHub Release
129+
uses: softprops/action-gh-release@v2
130+
with:
131+
tag_name: ${{ steps.get_version.outputs.TAG_NAME }}
132+
name: Release ${{ steps.get_version.outputs.TAG_NAME }}
133+
# body: | # Optional: Add release notes here
134+
# Release notes for version ${{ steps.get_version.outputs.TAG_NAME }}
135+
# - Feature A
136+
# - Bugfix B
137+
draft: false
138+
prerelease: false # Set to true if it's a pre-release
139+
files: dist/* # Upload all files from the dist directory
140+
141+
# --------------------------------------------------
142+
# Job 4: Publish to PyPI (Runs only on push to release/*)
143+
# --------------------------------------------------
144+
publish_pypi:
145+
name: Publish to PyPI
146+
needs: create_release # Depends on successful release creation
147+
# Only run this job on direct pushes to release/* branches
148+
if: github.event_name == 'push' && startsWith(github.ref, 'refs/heads/release/')
149+
runs-on: ubuntu-latest
150+
environment: # Optional: Define environment for PyPI publishing rules/secrets
151+
name: pypi
152+
url: https://pypi.org/p/sqlmodel-crud-utils # Replace with your actual PyPI package URL
153+
permissions:
154+
id-token: write # Required for trusted publishing
155+
steps:
156+
- name: Download build artifacts
157+
uses: actions/download-artifact@v4
158+
with:
159+
name: python-package-distributions
160+
path: dist
161+
162+
- name: Publish package to PyPI
163+
uses: pypa/gh-action-pypi-publish@release/v1
164+
# No need for secrets.PYPI_API_TOKEN if using trusted publishing
165+
# with:
166+
# user: __token__
167+
# password: ${{ secrets.PYPI_API_TOKEN }}

0 commit comments

Comments
 (0)