|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +# Exit on any error |
| 4 | +set -e |
| 5 | + |
| 6 | +# Function to increment minor version |
| 7 | +increment_version() { |
| 8 | + local version=$1 |
| 9 | + local major=$(echo $version | cut -d. -f1) |
| 10 | + local minor=$(echo $version | cut -d. -f2) |
| 11 | + local patch=$(echo $version | cut -d. -f3) |
| 12 | + |
| 13 | + # Increment minor version |
| 14 | + patch=$((patch + 1)) |
| 15 | + echo "${major}.${minor}.${patch}" |
| 16 | +} |
| 17 | + |
| 18 | +# Check if PYPI_TOKEN environment variable exists |
| 19 | +if [ -z "$PYPI_TOKEN" ]; then |
| 20 | + echo "Error: PYPI_TOKEN environment variable is not set" |
| 21 | + echo "Please set it first:" |
| 22 | + echo "export PYPI_TOKEN=your_token_here" |
| 23 | + exit 1 |
| 24 | +fi |
| 25 | + |
| 26 | +# Get current version from pyproject.toml |
| 27 | +current_version=$(grep "^version = " pyproject.toml | cut -d'"' -f2) |
| 28 | +echo "Current version: $current_version" |
| 29 | + |
| 30 | +# Calculate new version |
| 31 | +new_version=$(increment_version $current_version) |
| 32 | +echo "New version: $new_version" |
| 33 | + |
| 34 | +# Update version in pyproject.toml |
| 35 | +sed -i.bak "s/^version = \"${current_version}\"/version = \"${new_version}\"/" pyproject.toml |
| 36 | +rm pyproject.toml.bak |
| 37 | + |
| 38 | +# Clean up old builds |
| 39 | +echo "Cleaning up old builds..." |
| 40 | +rm -rf dist/ build/ *.egg-info/ |
| 41 | + |
| 42 | +# Configure Poetry with PyPI token |
| 43 | +echo "Configuring Poetry with PyPI token..." |
| 44 | +poetry config pypi-token.pypi "${PYPI_TOKEN}" |
| 45 | + |
| 46 | +# Build the package |
| 47 | +echo "Building package..." |
| 48 | +poetry build |
| 49 | + |
| 50 | +# List built files |
| 51 | +echo "Built files:" |
| 52 | +ls -l dist/ |
| 53 | + |
| 54 | +# Publish to PyPI |
| 55 | +echo "Publishing to PyPI..." |
| 56 | +poetry publish |
| 57 | + |
| 58 | +echo "Successfully published version ${new_version} to PyPI!" |
| 59 | + |
| 60 | +# Waitting 30 seconds for verification |
| 61 | +echo "Verifying installation..." |
| 62 | +sleep 30 |
| 63 | +pip install --no-cache-dir easy-model-deployer==${new_version} |
| 64 | + |
| 65 | +echo "Done! Try running: emd --help" |
| 66 | +echo "Note to push the latest version in pyproject.toml as ${new_version}, please update it manually." |
0 commit comments