-
Notifications
You must be signed in to change notification settings - Fork 0
150 lines (130 loc) · 4.63 KB
/
release.yml
File metadata and controls
150 lines (130 loc) · 4.63 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
name: Release Workflow
on:
# Trigger on pushes to branches starting with 'release/'
push:
branches:
- 'release/*'
# Trigger on Pull Requests targeting branches starting with 'release/'
tags:
- 'v*'
pull_request:
branches:
- 'release/*'
# Default permissions required for most jobs
permissions:
contents: read
jobs:
# --------------------------------------------------
# Job 1: Linting and Testing (Runs on push and PR)
# --------------------------------------------------
lint_test:
name: Lint & Test
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0 # Needed for pre-commit checks on changed files
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.13'
- name: Install uv
uses: astral-sh/setup-uv@v5
- name: Install dependencies with uv
run: |
uv sync --group dev
- name: Run pre-commit hooks
uses: pre-commit/action@v3.0.1
- name: Run tests with coverage
run: |
uv run pytest --cov=sqlmodel_crud_utils --cov-report=xml --cov-report=term
- name: Upload coverage report
uses: actions/upload-artifact@v4
with:
name: coverage-report
path: coverage.xml
if-no-files-found: error # Fail if coverage.xml is not generated
# --------------------------------------------------
# Job 2: Build Package (Runs only on push to release/*)
# --------------------------------------------------
build:
name: Build Package
needs: lint_test # Depends on successful linting and testing
# Only run this job on direct pushes to release/* branches, not on PRs
if: github.event_name == 'push' && startsWith(github.ref, 'refs/heads/release/')
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.13'
- name: Install uv
uses: astral-sh/setup-uv@v5
- name: Build source distribution and wheel
run: uv build
- name: Upload build artifacts
uses: actions/upload-artifact@v4
with:
name: python-package-distributions
path: dist/
if-no-files-found: error # Fail if build artifacts aren't found
# --------------------------------------------------
# Job 3: Create GitHub Release (Runs only on push to release/*)
# --------------------------------------------------
create_release:
name: Create GitHub Release
needs: build # Depends on successful build
# Only run this job on direct pushes to release/* branches
if: github.event_name == 'push' && startsWith(github.ref, 'refs/heads/release/')
runs-on: ubuntu-latest
permissions:
contents: write # Required to create releases and tags
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Download build artifacts
uses: actions/download-artifact@v4
with:
name: python-package-distributions
path: dist
- name: Extract version from branch name
id: get_version
# Assumes branch name is like 'release/v1.2.3'
# Extracts 'v1.2.3' as the tag name
run: echo "TAG_NAME=${GITHUB_REF#refs/heads/release/}" >> $GITHUB_OUTPUT
- name: Create GitHub Release
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ steps.get_version.outputs.TAG_NAME }}
name: Release ${{ steps.get_version.outputs.TAG_NAME }}
draft: false
prerelease: false
files: dist/*
# --------------------------------------------------
# Job 4: Publish to PyPI (Runs only on push to release/*)
# --------------------------------------------------
publish_pypi:
name: Publish to PyPI
needs: create_release # Depends on successful release creation
# Only run this job on direct pushes to release/* branches
if: github.event_name == 'push' && startsWith(github.ref, 'refs/heads/release/')
runs-on: ubuntu-latest
environment:
name: pypi
url: https://pypi.org/p/sqlmodel-crud-utils
permissions:
id-token: write # Required for trusted publishing
steps:
- name: Download build artifacts
uses: actions/download-artifact@v4
with:
name: python-package-distributions
path: dist
- name: Publish package to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
user: __token__
password: ${{ secrets.PYPI_API_TOKEN }}