|
| 1 | +#!/usr/bin/env bash |
| 2 | +set -euo pipefail |
| 3 | + |
| 4 | +RED='\033[0;31m' |
| 5 | +GREEN='\033[0;32m' |
| 6 | +YELLOW='\033[1;33m' |
| 7 | +NC='\033[0m' |
| 8 | + |
| 9 | +log() { echo -e "${GREEN}[release]${NC} $1"; } |
| 10 | +warn() { echo -e "${YELLOW}[release]${NC} $1"; } |
| 11 | +err() { echo -e "${RED}[release]${NC} $1"; exit 1; } |
| 12 | + |
| 13 | +REPO_ROOT="$(cd "$(dirname "$0")/.." && pwd)" |
| 14 | +cd "$REPO_ROOT" |
| 15 | + |
| 16 | +git diff --quiet || err "Working tree is dirty — commit or stash changes first." |
| 17 | + |
| 18 | +LATEST_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "none") |
| 19 | +log "Latest tag: $LATEST_TAG" |
| 20 | + |
| 21 | +CURRENT_VERSION=$(grep -E '^version\s*=' pyproject.toml | head -1 | sed 's/version\s*=\s*"\([^"]*\)"/\1/') |
| 22 | +log "Current version in pyproject.toml: $CURRENT_VERSION" |
| 23 | + |
| 24 | +echo "" |
| 25 | +read -r -p "Enter new version (e.g. 0.1.9): " NEW_VERSION |
| 26 | + |
| 27 | +if [[ ! "$NEW_VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then |
| 28 | + err "Invalid version format — use X.Y.Z (e.g. 0.1.9)" |
| 29 | +fi |
| 30 | + |
| 31 | +TAG="v${NEW_VERSION}" |
| 32 | + |
| 33 | +if git rev-parse "$TAG" >/dev/null 2>&1; then |
| 34 | + err "Tag $TAG already exists." |
| 35 | +fi |
| 36 | + |
| 37 | +# --- Apply version bumps across all files --- |
| 38 | + |
| 39 | +sed -i "s/^version = \"$CURRENT_VERSION\"/version = \"$NEW_VERSION\"/" pyproject.toml |
| 40 | +sed -i "s/VERSION = \"v$CURRENT_VERSION\"/VERSION = \"v$NEW_VERSION\"/" pythonbpf/codegen.py |
| 41 | +sed -i "s/release = \"$CURRENT_VERSION\"/release = \"$NEW_VERSION\"/" docs/conf.py |
| 42 | +sed -i "s/version = \"$CURRENT_VERSION\"/version = \"$NEW_VERSION\"/" docs/conf.py |
| 43 | + |
| 44 | +log "Bumped version $CURRENT_VERSION → $NEW_VERSION in:" |
| 45 | +log " pyproject.toml" |
| 46 | +log " pythonbpf/codegen.py" |
| 47 | +log " docs/conf.py" |
| 48 | + |
| 49 | +# --- Show diff and confirm --- |
| 50 | + |
| 51 | +echo "" |
| 52 | +log "Changes to be committed:" |
| 53 | +git diff --stat |
| 54 | +echo "" |
| 55 | +git diff |
| 56 | + |
| 57 | +echo "" |
| 58 | +read -r -p "Commit these changes and create tag $TAG? [y/N]: " CONFIRM |
| 59 | +if [[ ! "$CONFIRM" =~ ^[Yy]$ ]]; then |
| 60 | + git checkout -- pyproject.toml pythonbpf/codegen.py docs/conf.py |
| 61 | + warn "Reverted changes. Aborted." |
| 62 | + exit 0 |
| 63 | +fi |
| 64 | + |
| 65 | +git add pyproject.toml pythonbpf/codegen.py docs/conf.py |
| 66 | +git commit -m "Bump version to $NEW_VERSION" |
| 67 | +log "Committed version bump." |
| 68 | + |
| 69 | +git tag "$TAG" |
| 70 | +log "Created tag $TAG." |
| 71 | + |
| 72 | +echo "" |
| 73 | +read -r -p "Push commit and tag to origin? [y/N]: " PUSH |
| 74 | +if [[ "$PUSH" =~ ^[Yy]$ ]]; then |
| 75 | + git push origin HEAD |
| 76 | + git push origin "$TAG" |
| 77 | + log "Pushed commit and tag $TAG. CI will build and publish to PyPI." |
| 78 | +else |
| 79 | + warn "Push skipped. Run: git push origin HEAD && git push origin $TAG" |
| 80 | +fi |
0 commit comments