-
Notifications
You must be signed in to change notification settings - Fork 3
142 lines (119 loc) · 4.6 KB
/
auto-release.yml
File metadata and controls
142 lines (119 loc) · 4.6 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
name: Auto Release on Main
on:
push:
branches:
- main
paths-ignore:
- '.github/**'
- 'docs/**'
- '**/*.md'
- '.context/**'
- '.rules/**'
- '.serena/**'
permissions:
contents: write
jobs:
auto-release:
name: Auto Version and Release
runs-on: ubuntu-latest
# Skip if commit message contains version bump (avoid loops) or [skip-release]
if: >-
!contains(github.event.head_commit.message, 'Bump version to') &&
!contains(github.event.head_commit.message, '[skip-release]')
steps:
- name: Checkout code
uses: actions/checkout@v6
with:
fetch-depth: 0
# Use PAT to bypass branch protection rules
# Create a Fine-grained PAT with 'Contents: Read and write' permission
# and add it as repository secret named RELEASE_PAT
token: ${{ secrets.RELEASE_PAT }}
- name: Set up Python
uses: actions/setup-python@v6
with:
python-version: '3.12'
- name: Configure Git
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
- name: Get current version
id: current
run: |
# Extract version from pyproject.toml
VERSION=$(grep -m1 'version = ' pyproject.toml | sed 's/version = "\(.*\)"/\1/')
echo "version=$VERSION" >> $GITHUB_OUTPUT
echo "Current version: $VERSION"
- name: Calculate new alpha version
id: new_version
run: |
VERSION="${{ steps.current.outputs.version }}"
# Parse version components
# Handles: 0.6.5.dev3, 0.6.5a1, 0.6.5.alpha1, 0.6.5
if [[ "$VERSION" =~ ^([0-9]+\.[0-9]+\.[0-9]+)(\.dev[0-9]+|\.alpha[0-9]+|a[0-9]+|b[0-9]+|rc[0-9]+)?$ ]]; then
BASE="${BASH_REMATCH[1]}"
PRERELEASE="${BASH_REMATCH[2]}"
# Check if already alpha for this base version
LATEST_ALPHA=$(git tag -l "v${BASE}a*" | sort -V | tail -1 || echo "")
if [ -z "$LATEST_ALPHA" ]; then
# No alpha yet, start at a1
NEW_VERSION="${BASE}a1"
else
# Extract alpha number and increment
ALPHA_NUM=$(echo "$LATEST_ALPHA" | sed "s/v${BASE}a//")
NEW_ALPHA=$((ALPHA_NUM + 1))
NEW_VERSION="${BASE}a${NEW_ALPHA}"
fi
else
echo "Unexpected version format: $VERSION"
exit 1
fi
echo "new_version=$NEW_VERSION" >> $GITHUB_OUTPUT
echo "New version: $NEW_VERSION"
- name: Update version files
run: |
NEW_VERSION="${{ steps.new_version.outputs.new_version }}"
# Parse version for __version_info__
# Format: 0.6.7a1 -> (0, 6, 7, "alpha")
MAJOR=$(echo "$NEW_VERSION" | cut -d. -f1)
MINOR=$(echo "$NEW_VERSION" | cut -d. -f2)
PATCH=$(echo "$NEW_VERSION" | cut -d. -f3 | sed 's/[^0-9].*//')
if [[ "$NEW_VERSION" == *"a"* ]]; then
PRERELEASE="alpha"
elif [[ "$NEW_VERSION" == *"b"* ]]; then
PRERELEASE="beta"
elif [[ "$NEW_VERSION" == *"rc"* ]]; then
PRERELEASE="rc"
elif [[ "$NEW_VERSION" == *"dev"* ]]; then
PRERELEASE="dev"
else
PRERELEASE=""
fi
# Update pyproject.toml
sed -i "s/^version = .*/version = \"$NEW_VERSION\"/" pyproject.toml
# Update src/version.py with full exports
cat > src/version.py << PYEOF
"""Version information for HEDit."""
__version__ = "$NEW_VERSION"
__version_info__ = ($MAJOR, $MINOR, $PATCH, "$PRERELEASE")
def get_version() -> str:
"""Get the current version string."""
return __version__
def get_version_info() -> tuple:
"""Get the version info tuple (major, minor, patch, prerelease)."""
return __version_info__
PYEOF
# Fix indentation (remove leading spaces from heredoc)
sed -i 's/^ //' src/version.py
- name: Commit version bump
run: |
NEW_VERSION="${{ steps.new_version.outputs.new_version }}"
git add pyproject.toml src/version.py
git commit -m "Bump version to $NEW_VERSION"
git push origin main
- name: Create and push tag
run: |
NEW_VERSION="${{ steps.new_version.outputs.new_version }}"
git tag "v$NEW_VERSION"
git push origin "v$NEW_VERSION"
echo "Created tag: v$NEW_VERSION"