-
Notifications
You must be signed in to change notification settings - Fork 1
150 lines (130 loc) Β· 5.7 KB
/
release.yml
File metadata and controls
150 lines (130 loc) Β· 5.7 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
on:
push:
branches: [main]
jobs:
release:
runs-on: ubuntu-latest
permissions:
contents: write
id-token: write
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
token: ${{ secrets.GITHUB_TOKEN }}
- name: Install uv
uses: astral-sh/setup-uv@v4
with:
version: "latest"
- name: Set up Python
run: uv python install 3.11
- name: Install dependencies
run: uv sync --all-extras
- name: Run tests
run: uv run pytest tests -v --tb=short
- name: Get version from pyproject.toml
id: version
run: |
VERSION=$(uv run python -c "import tomllib; print(tomllib.load(open('pyproject.toml', 'rb'))['project']['version'])")
echo "version=$VERSION" >> $GITHUB_OUTPUT
echo "::notice::π¦ Version in pyproject.toml: $VERSION"
- name: Check if tag exists
id: check_tag
run: |
if git rev-parse "v${{ steps.version.outputs.version }}" >/dev/null 2>&1; then
echo "exists=true" >> $GITHUB_OUTPUT
echo "::notice::π Tag v${{ steps.version.outputs.version }} already exists - skipping release"
else
echo "exists=false" >> $GITHUB_OUTPUT
echo "::notice::π New version detected! Will create release v${{ steps.version.outputs.version }}"
fi
- name: Check PyPI for existing version
id: check_pypi
if: steps.check_tag.outputs.exists == 'false'
run: |
VERSION="${{ steps.version.outputs.version }}"
HTTP_STATUS=$(curl -s -o /dev/null -w "%{http_code}" "https://pypi.org/pypi/zernio-sdk/$VERSION/json")
if [ "$HTTP_STATUS" = "200" ]; then
echo "::error::β Version $VERSION already exists on PyPI! Bump the version in pyproject.toml"
exit 1
else
echo "::notice::β
Version $VERSION not found on PyPI - ready to publish"
fi
- name: Release Summary
run: |
echo "## π Release Summary" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "| Item | Value |" >> $GITHUB_STEP_SUMMARY
echo "|------|-------|" >> $GITHUB_STEP_SUMMARY
echo "| Version | \`${{ steps.version.outputs.version }}\` |" >> $GITHUB_STEP_SUMMARY
echo "| Tag exists | ${{ steps.check_tag.outputs.exists }} |" >> $GITHUB_STEP_SUMMARY
if [ "${{ steps.check_tag.outputs.exists }}" = "true" ]; then
echo "| Action | βοΈ **Skipped** (version already released) |" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "> π‘ To release a new version, update \`version\` in \`pyproject.toml\`" >> $GITHUB_STEP_SUMMARY
else
echo "| Action | π **New Release** |" >> $GITHUB_STEP_SUMMARY
echo "| GitHub Release | v${{ steps.version.outputs.version }} |" >> $GITHUB_STEP_SUMMARY
echo "| PyPI | zernio-sdk==${{ steps.version.outputs.version }} |" >> $GITHUB_STEP_SUMMARY
fi
- name: Build package
if: steps.check_tag.outputs.exists == 'false'
run: |
uv build
echo "::notice::π¦ Built: $(ls dist/)"
- name: Create GitHub Release
if: steps.check_tag.outputs.exists == 'false'
uses: softprops/action-gh-release@v2
with:
tag_name: v${{ steps.version.outputs.version }}
name: v${{ steps.version.outputs.version }}
files: dist/*
generate_release_notes: true
body: |
## Install
This package is published under two names:
```bash
pip install late-sdk==${{ steps.version.outputs.version }}
# or
pip install zernio-sdk==${{ steps.version.outputs.version }}
```
- name: Publish zernio-sdk to PyPI
if: steps.check_tag.outputs.exists == 'false'
uses: pypa/gh-action-pypi-publish@release/v1
with:
password: ${{ secrets.PYPI_API_TOKEN }}
- name: Swap package name to late-sdk
if: steps.check_tag.outputs.exists == 'false'
run: |
python3 -c "
import re
with open('pyproject.toml', 'r') as f:
content = f.read()
content = re.sub(r'name = \"zernio-sdk\"', 'name = \"late-sdk\"', content)
with open('pyproject.toml', 'w') as f:
f.write(content)
"
- name: Build as late-sdk
if: steps.check_tag.outputs.exists == 'false'
run: |
rm -rf dist/
uv build
- name: Publish late-sdk to PyPI
if: steps.check_tag.outputs.exists == 'false'
uses: pypa/gh-action-pypi-publish@release/v1
with:
password: ${{ secrets.PYPI_API_TOKEN }}
- name: Post-release Summary
if: steps.check_tag.outputs.exists == 'false'
run: |
echo "" >> $GITHUB_STEP_SUMMARY
echo "## β
Release Complete" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "- π·οΈ GitHub: [v${{ steps.version.outputs.version }}](https://github.com/${{ github.repository }}/releases/tag/v${{ steps.version.outputs.version }})" >> $GITHUB_STEP_SUMMARY
echo "- π¦ PyPI: [zernio-sdk ${{ steps.version.outputs.version }}](https://pypi.org/project/zernio-sdk/${{ steps.version.outputs.version }}/)" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "Install with:" >> $GITHUB_STEP_SUMMARY
echo "\`\`\`bash" >> $GITHUB_STEP_SUMMARY
echo "pip install zernio-sdk==${{ steps.version.outputs.version }}" >> $GITHUB_STEP_SUMMARY
echo "\`\`\`" >> $GITHUB_STEP_SUMMARY