-
Notifications
You must be signed in to change notification settings - Fork 7
182 lines (148 loc) · 5.58 KB
/
python-publish.yml
File metadata and controls
182 lines (148 loc) · 5.58 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
# This workflow will upload a Python Package using Twine when code is pushed to main
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python#publishing-to-package-registries
# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.
name: Upload Python Package
on:
push:
branches: [ "master" ]
release:
types: [published]
permissions:
contents: write
id-token: write
jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.10", "3.11", "3.12"]
steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -e ".[dev,async]"
- name: Run tests
run: |
pytest tests/ -v
deploy:
needs: test
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/master'
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
token: ${{ secrets.GITHUB_TOKEN }}
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.11'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install build twine tomli-w tomli
- name: Create version update script
run: |
cat > update_version.py << 'EOF'
import sys
import os
try:
import tomllib
except ImportError:
import tomli as tomllib
import tomli_w
def get_current_version():
with open('pyproject.toml', 'rb') as f:
data = tomllib.load(f)
return data['project']['version']
def increment_version(version):
parts = version.split('.')
parts[-1] = str(int(parts[-1]) + 1)
return '.'.join(parts)
def update_version(new_version):
with open('pyproject.toml', 'rb') as f:
data = tomllib.load(f)
data['project']['version'] = new_version
with open('pyproject.toml', 'wb') as f:
tomli_w.dump(data, f)
if __name__ == "__main__":
current = get_current_version()
new = increment_version(current)
update_version(new)
print(f"Updated version from {current} to {new}")
# Write to GitHub output
with open(os.environ['GITHUB_OUTPUT'], 'a') as f:
f.write(f"new_version={new}\n")
EOF
- name: Update version
id: update_version
run: python update_version.py
- name: Build package
run: python -m build
- name: Check package
run: twine check dist/*
- name: Publish package to PyPI
env:
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }}
run: |
twine upload dist/*
- name: Commit version update
run: |
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
git add pyproject.toml
git commit -m "Bump version to ${{ steps.update_version.outputs.new_version }}" || exit 0
git push
- name: Create Git Tag
run: |
git tag v${{ steps.update_version.outputs.new_version }}
git push origin v${{ steps.update_version.outputs.new_version }}
- name: Generate Release Notes
id: release_notes
run: |
# Get commits since last tag
LAST_TAG=$(git describe --tags --abbrev=0 HEAD~1 2>/dev/null || echo "")
if [ -z "$LAST_TAG" ]; then
# First release - get all commits
COMMITS=$(git log --pretty=format:"- %s (%h)" --no-merges HEAD~10..HEAD)
else
# Get commits since last tag
COMMITS=$(git log --pretty=format:"- %s (%h)" --no-merges $LAST_TAG..HEAD~1)
fi
# Create release notes file
cat > release_notes.md << EOF
## 🚀 Release v${{ steps.update_version.outputs.new_version }}
### What's Changed
$COMMITS
### 📦 Installation
\`\`\`bash
pip install lightapi==${{ steps.update_version.outputs.new_version }}
\`\`\`
### 📖 Documentation
- [Getting Started](https://iklobato.github.io/lightapi/getting-started/installation/)
- [API Reference](https://iklobato.github.io/lightapi/api-reference/core/)
- [Examples](https://iklobato.github.io/lightapi/examples/basic-rest/)
**Full Changelog**: https://github.com/iklobato/lightapi/compare/${LAST_TAG}...v${{ steps.update_version.outputs.new_version }}
EOF
echo "Generated release notes for v${{ steps.update_version.outputs.new_version }}"
- name: Create GitHub Release
uses: softprops/action-gh-release@v1
with:
tag_name: v${{ steps.update_version.outputs.new_version }}
name: "LightAPI v${{ steps.update_version.outputs.new_version }}"
body_path: release_notes.md
draft: false
prerelease: false
files: |
dist/lightapi-${{ steps.update_version.outputs.new_version }}-py3-none-any.whl
dist/lightapi-${{ steps.update_version.outputs.new_version }}.tar.gz
token: ${{ secrets.GITHUB_TOKEN }}