Skip to content

Commit 8664769

Browse files
committed
ci: auto-trigger release on push to release branch
- Push to `release` branch reads version from pyproject.toml and auto-creates tag + GitHub Release - Fails early if tag already exists (prevents duplicate releases) - Keeps workflow_dispatch as fallback for manual bump/custom tag https://claude.ai/code/session_01GxFo5FHfDC9YUavH3orT6o
1 parent 1a32510 commit 8664769

1 file changed

Lines changed: 28 additions & 22 deletions

File tree

.github/workflows/release.yml

Lines changed: 28 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
name: Release
22

33
on:
4+
push:
5+
branches:
6+
- release
47
workflow_dispatch:
58
inputs:
69
bump:
7-
description: "Version bump type (ignored if custom_tag is set)"
10+
description: "Version bump type"
811
required: true
912
default: "patch"
1013
type: choice
@@ -31,58 +34,61 @@ jobs:
3134
- name: Determine new version
3235
id: version
3336
run: |
37+
# Read version from pyproject.toml as source of truth
38+
CURRENT=$(grep '^version = ' pyproject.toml | sed 's/version = "\(.*\)"/\1/')
39+
echo "Current version in pyproject.toml: ${CURRENT}"
40+
3441
# Get latest semver tag
3542
LATEST=$(git tag --sort=-v:refname | grep -E '^v[0-9]+\.[0-9]+\.[0-9]+$' | head -1)
3643
echo "Latest tag: ${LATEST:-none}"
3744
45+
# For workflow_dispatch with custom_tag
3846
if [ -n "${{ inputs.custom_tag }}" ]; then
3947
NEW_TAG="${{ inputs.custom_tag }}"
40-
# Strip leading 'v' for version number
4148
NEW_VERSION="${NEW_TAG#v}"
42-
else
49+
# For workflow_dispatch with bump
50+
elif [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
4351
if [ -z "$LATEST" ]; then
4452
LATEST="v0.0.0"
4553
fi
46-
47-
# Parse version
4854
VERSION="${LATEST#v}"
4955
IFS='.' read -r MAJOR MINOR PATCH <<< "$VERSION"
5056
5157
case "${{ inputs.bump }}" in
52-
major)
53-
MAJOR=$((MAJOR + 1))
54-
MINOR=0
55-
PATCH=0
56-
;;
57-
minor)
58-
MINOR=$((MINOR + 1))
59-
PATCH=0
60-
;;
61-
patch)
62-
PATCH=$((PATCH + 1))
63-
;;
58+
major) MAJOR=$((MAJOR + 1)); MINOR=0; PATCH=0 ;;
59+
minor) MINOR=$((MINOR + 1)); PATCH=0 ;;
60+
patch) PATCH=$((PATCH + 1)) ;;
6461
esac
6562
6663
NEW_VERSION="${MAJOR}.${MINOR}.${PATCH}"
6764
NEW_TAG="v${NEW_VERSION}"
65+
# For push to release branch: use pyproject.toml version directly
66+
else
67+
NEW_VERSION="${CURRENT}"
68+
NEW_TAG="v${NEW_VERSION}"
69+
fi
70+
71+
# Check if tag already exists
72+
if git rev-parse "refs/tags/${NEW_TAG}" >/dev/null 2>&1; then
73+
echo "::error::Tag ${NEW_TAG} already exists. Update the version in pyproject.toml before releasing."
74+
exit 1
6875
fi
6976
7077
echo "new_tag=${NEW_TAG}" >> "$GITHUB_OUTPUT"
7178
echo "new_version=${NEW_VERSION}" >> "$GITHUB_OUTPUT"
72-
echo "New version: ${NEW_TAG}"
79+
echo "New release: ${NEW_TAG}"
7380
74-
- name: Update pyproject.toml version
81+
- name: Update pyproject.toml version if needed
7582
run: |
7683
sed -i "s/^version = \".*\"/version = \"${{ steps.version.outputs.new_version }}\"/" pyproject.toml
77-
echo "Updated pyproject.toml:"
84+
echo "pyproject.toml version:"
7885
grep '^version' pyproject.toml
7986
80-
- name: Commit version bump
87+
- name: Commit version bump if needed
8188
run: |
8289
git config user.name "github-actions[bot]"
8390
git config user.email "github-actions[bot]@users.noreply.github.com"
8491
git add pyproject.toml
85-
# Only commit if there are changes
8692
if git diff --cached --quiet; then
8793
echo "No version change needed"
8894
else

0 commit comments

Comments
 (0)