|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +set -euo pipefail |
| 4 | + |
| 5 | +# Source the vars.sh script |
| 6 | +source vars.sh |
| 7 | + |
| 8 | + |
| 9 | +# Function to increment version |
| 10 | +increment_version() { |
| 11 | + local version=$1 |
| 12 | + local part=$2 |
| 13 | + IFS='.' read -ra ver <<< "$version" |
| 14 | + case $part in |
| 15 | + major) ((ver[0]++)); ver[1]=0; ver[2]=0 ;; |
| 16 | + minor) ((ver[1]++)); ver[2]=0 ;; |
| 17 | + patch) ((ver[2]++)) ;; |
| 18 | + esac |
| 19 | + echo "${ver[0]}.${ver[1]}.${ver[2]}" |
| 20 | +} |
| 21 | + |
| 22 | +# Get current version from pyproject.toml |
| 23 | +current_version=$(grep "^version" pyproject.toml | sed -E 's/version = "(.*)"/\1/') |
| 24 | + |
| 25 | +# Prompt for version increment type |
| 26 | +echo "Current version: $current_version" |
| 27 | +echo "Select version increment type:" |
| 28 | +echo "1) Major" |
| 29 | +echo "2) Minor" |
| 30 | +echo "3) Patch" |
| 31 | +echo "4) No increment" |
| 32 | +read -p "Enter your choice (1-4): " choice |
| 33 | + |
| 34 | +case $choice in |
| 35 | + 1) new_version=$(increment_version "$current_version" major) ;; |
| 36 | + 2) new_version=$(increment_version "$current_version" minor) ;; |
| 37 | + 3) new_version=$(increment_version "$current_version" patch) ;; |
| 38 | + 4) new_version=$current_version ;; |
| 39 | + *) echo "Invalid choice. Exiting."; exit 1 ;; |
| 40 | +esac |
| 41 | + |
| 42 | +if [ "$new_version" != "$current_version" ]; then |
| 43 | + # Update version in pyproject.toml |
| 44 | + sed -i.bak "s/^version = .*/version = \"$new_version\"/" pyproject.toml && rm pyproject.toml.bak |
| 45 | + |
| 46 | + # Update version in __init__.py |
| 47 | + sed -i.bak "s/__version__ = .*/__version__ = \"$new_version\"/" src/duohub/__init__.py && rm src/duohub/__init__.py.bak |
| 48 | + |
| 49 | + # Commit version changes |
| 50 | + git add pyproject.toml src/duohub/__init__.py |
| 51 | + git commit -m "chore: bump version to $new_version" |
| 52 | +fi |
| 53 | + |
| 54 | +# Ensure we're on the main branch and up-to-date |
| 55 | +git checkout main |
| 56 | +git pull origin main |
| 57 | + |
| 58 | +poetry build |
| 59 | + |
| 60 | +# Create and push Git tag |
| 61 | +git tag "v$new_version" |
| 62 | +git push origin "v$new_version" |
| 63 | + |
| 64 | +# Push changes to GitHub |
| 65 | +git push origin main |
| 66 | + |
| 67 | +# Publish to PyPI using the token format |
| 68 | +poetry config pypi-token.pypi $PYPI_TOKEN |
| 69 | +poetry publish --username __token__ --password $PYPI_TOKEN |
| 70 | + |
| 71 | +echo "Release $new_version completed successfully!" |
| 72 | + |
| 73 | +# Prompt for release title and description |
| 74 | +read -p "Enter the release title: " release_title |
| 75 | +echo "Enter the release description (press Ctrl+D when finished):" |
| 76 | +release_description=$(cat) |
| 77 | + |
| 78 | +# Create a GitHub release with the provided title and description |
| 79 | +curl -X POST \ |
| 80 | + -H "Authorization: token $GITHUB_TOKEN" \ |
| 81 | + -H "Accept: application/vnd.github.v3+json" \ |
| 82 | + https://api.github.com/repos/duohub-ai/duohub-py/releases \ |
| 83 | + -d "{ |
| 84 | + \"tag_name\": \"v$new_version\", |
| 85 | + \"target_commitish\": \"main\", |
| 86 | + \"name\": \"$release_title\", |
| 87 | + \"body\": \"$release_description\", |
| 88 | + \"draft\": false, |
| 89 | + \"prerelease\": false |
| 90 | + }" |
| 91 | + |
| 92 | +echo "GitHub release created for v$new_version with title: $release_title" |
0 commit comments