forked from msgflux/msgspec-ext
-
Notifications
You must be signed in to change notification settings - Fork 0
158 lines (128 loc) · 4.37 KB
/
publish.yml
File metadata and controls
158 lines (128 loc) · 4.37 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
name: Release
on:
workflow_run:
workflows: ["Validate Release"]
types:
- completed
branches: [main]
permissions:
contents: write
id-token: write
jobs:
build-and-tag:
name: Build and Tag
# Only run if validation succeeded and commit has RELEASE marker
if: |
github.event.workflow_run.conclusion == 'success' &&
contains(github.event.workflow_run.head_commit.message, 'RELEASE:')
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 2
- name: Set up Python
uses: actions/setup-python@v6
with:
python-version: '3.10'
- name: Install uv
uses: astral-sh/setup-uv@v7
- name: Install packaging
run: pip install packaging
- name: Get current version
id: current
run: |
VERSION=$(grep -oP '__version__ = "\K[^"]+' src/msgspec_ext/version.py)
echo "version=$VERSION" >> $GITHUB_OUTPUT
echo "Current version: $VERSION"
- name: Get previous version
id: previous
run: |
PREV_VERSION=$(git show HEAD~1:src/msgspec_ext/version.py 2>/dev/null | grep -oP '__version__ = "\K[^"]+' || echo "0.0.0")
echo "version=$PREV_VERSION" >> $GITHUB_OUTPUT
echo "Previous version: $PREV_VERSION"
- name: Validate version bump
id: validate
run: |
python << EOF
from packaging.version import parse as parse_version
import sys
current = "${{ steps.current.outputs.version }}"
previous = "${{ steps.previous.outputs.version }}"
print(f"Comparing: {previous} -> {current}")
if parse_version(current) > parse_version(previous):
print(f"✅ Version bumped from {previous} to {current}")
sys.exit(0)
elif parse_version(current) == parse_version(previous):
print(f"⚠️ No version change detected")
sys.exit(1)
else:
print(f"❌ Version downgrade detected: {previous} -> {current}")
sys.exit(1)
EOF
- name: Install dependencies
run: uv sync --locked
- name: Build package
run: uv build
- name: Check package
run: uv run twine check dist/*
- name: Create and push tag
run: |
VERSION="v${{ steps.current.outputs.version }}"
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git tag -a "$VERSION" -m "Release ${{ steps.current.outputs.version }}"
git push origin "$VERSION"
echo "✅ Created and pushed tag: $VERSION"
- name: Upload dist artifacts
uses: actions/upload-artifact@v4
with:
name: python-package-distributions
path: dist/
publish:
name: Publish to PyPI
needs: build-and-tag
runs-on: ubuntu-latest
environment: pypi
permissions:
id-token: write
steps:
- name: Download dist artifacts
uses: actions/download-artifact@v4
with:
name: python-package-distributions
path: dist/
- name: Publish to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
create-release:
name: Create GitHub Release
needs: publish
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Get version
id: version
run: |
VERSION=$(grep -oP '__version__ = "\K[^"]+' src/msgspec_ext/version.py)
echo "version=$VERSION" >> $GITHUB_OUTPUT
- name: Create GitHub Release
uses: softprops/action-gh-release@v2
with:
tag_name: v${{ steps.version.outputs.version }}
name: Release v${{ steps.version.outputs.version }}
body: |
## Release v${{ steps.version.outputs.version }}
See [CHANGELOG.md](https://github.com/msgflux/msgspec-ext/blob/main/CHANGELOG.md) for details.
### Installation
```bash
pip install msgspec-ext==${{ steps.version.outputs.version }}
```
Or with uv:
```bash
uv add msgspec-ext==${{ steps.version.outputs.version }}
```
draft: false
prerelease: false