-
Notifications
You must be signed in to change notification settings - Fork 2
98 lines (80 loc) · 3.21 KB
/
release.yml
File metadata and controls
98 lines (80 loc) · 3.21 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
name: Release Hatiyar to PyPI
permissions:
contents: write
on:
push:
branches:
- main
jobs:
release:
name: Build and Publish to PyPI
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v5
with:
fetch-depth: 0
token: ${{ secrets.GITHUB_TOKEN }}
- name: Auto-increment version
id: version_bump
run: |
# Get current version from pyproject.toml
CURRENT_VERSION=$(grep -Po '(?<=^version = ")[^"]*' pyproject.toml)
echo "Current version: $CURRENT_VERSION"
# Check if this version was already released to PyPI
PYPI_CHECK=$(curl -s https://pypi.org/pypi/hatiyar/json | grep -o "\"$CURRENT_VERSION\"" || echo "not_found")
if [ "$PYPI_CHECK" = "not_found" ]; then
# Version is new, use it as-is
NEW_VERSION="$CURRENT_VERSION"
echo "✅ Using version $NEW_VERSION (not on PyPI yet)"
else
# Version exists on PyPI, determine bump type from commit message
COMMIT_MSG="${{ github.event.head_commit.message }}"
IFS='.' read -r MAJOR MINOR PATCH <<< "$CURRENT_VERSION"
echo "⚠️ Version $CURRENT_VERSION exists on PyPI"
echo "📝 Commit message: $COMMIT_MSG"
# Determine version bump based on conventional commits
if echo "$COMMIT_MSG" | grep -qiE "^BREAKING CHANGE:|^[a-z]+(\([a-z]+\))?!:"; then
# Major version bump (breaking changes)
MAJOR=$((MAJOR + 1))
MINOR=0
PATCH=0
BUMP_TYPE="MAJOR (breaking change)"
elif echo "$COMMIT_MSG" | grep -qiE "^feat(\([a-z]+\))?:"; then
# Minor version bump (new features)
MINOR=$((MINOR + 1))
PATCH=0
BUMP_TYPE="MINOR (new feature)"
else
# Patch version bump (fixes, chores, docs, etc.)
PATCH=$((PATCH + 1))
BUMP_TYPE="PATCH (fix/chore)"
fi
NEW_VERSION="$MAJOR.$MINOR.$PATCH"
echo "Auto-bumping to $NEW_VERSION ($BUMP_TYPE)"
# Update pyproject.toml with new version
sed -i "s/^version = \".*\"/version = \"$NEW_VERSION\"/" pyproject.toml
# Commit the version bump
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add pyproject.toml
git commit -m "chore: auto-bump version to $NEW_VERSION [skip ci]"
git push
fi
echo "version=$NEW_VERSION" >> $GITHUB_OUTPUT
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.12'
- name: Set up uv
uses: astral-sh/setup-uv@v7
with:
enable-cache: true
- name: Install dependencies
run: uv sync --all-extras
- name: Build package
run: uv build --no-sources
- name: Publish to PyPI
env:
UV_PUBLISH_TOKEN: ${{ secrets.PYPI_API_TOKEN }}
run: uv publish