From 3b76d852a47179c6b121d1d192acf9f16f4b38b3 Mon Sep 17 00:00:00 2001 From: Marcelo Duarte Date: Mon, 16 Feb 2026 20:28:07 -0300 Subject: [PATCH] Add a script to bump-version --- .github/workflows/build.yml | 15 +------ Makefile | 24 ---------- ci/bump-version.sh | 89 +++++++++++++++++++++++++++++++++++++ ci/install-tools.sh | 6 +-- 4 files changed, 93 insertions(+), 41 deletions(-) create mode 100755 ci/bump-version.sh diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 9004bc5..22e769c 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -93,20 +93,7 @@ jobs: - name: Bump new dev version if: github.event_name != 'release' - run: | - git config user.name "Marcelo Duarte" - git config user.email marcelotduarte@users.noreply.github.com - SOURCE_DATE_EPOCH=$(git log -1 --pretty=%ct) - VERSION=$(uv version --short) - if (echo "$VERSION" | grep -q "\.dev"); then - uv version --no-sync --bump dev=$SOURCE_DATE_EPOCH - else - uv version --no-sync --bump patch --bump dev=$SOURCE_DATE_EPOCH - fi - NEW_VERSION=$(uv version --short) - git checkout -b build-$NEW_VERSION - git commit -m "Bump version: ${VERSION} → ${NEW_VERSION} [ci skip]" -a - git log -2 + run: ./ci/bump-version.sh build-dev - name: Build sdist and wheels run: ./ci/build-wheel.sh "${{ matrix.tag }}" diff --git a/Makefile b/Makefile index 4b9ae69..edf8738 100644 --- a/Makefile +++ b/Makefile @@ -59,27 +59,3 @@ cov: wheel coverage combine --keep --quiet -a $(COV_TMPDIR)/ coverage report coverage html --show-contexts - -.PHONY: release -release: - uv version - @echo "Run:" - @echo " uv version " - @echo "--or--" - @echo " uv version --bump " - @echo "--then--" - @echo " git push origin `git branch --show-current`" - @echo " git push origin `git branch --show-current` --tags" - -.PHONY: release-dev -release-dev: - git checkout -B release main - if (uv version --short | grep -q "\.dev"); then\ - uv version --bump dev;\ - else\ - uv version --bump patch --bump dev=0;\ - fi - git commit -m "Bump dev version: `uv version --short` [ci skip]" -a - git push origin `git branch --show-current` - git push origin `git branch --show-current` --tags - git log -1 diff --git a/ci/bump-version.sh b/ci/bump-version.sh new file mode 100755 index 0000000..9810dde --- /dev/null +++ b/ci/bump-version.sh @@ -0,0 +1,89 @@ +#!/bin/bash + +# Get script directory (without using /usr/bin/realpath) +_CI_DIR=$(dirname "${BASH_SOURCE[0]}") +CI_DIR=$(cd "$_CI_DIR" && pwd) + +# Python information (platform and version) +if ! which uv &>/dev/null; then + # Install/update uv + "$CI_DIR/install-tools.sh" --dev +fi + +# Usage +_usage () { + echo "Usage:" + echo "$0 " + echo "Based on:" + echo " https://docs.astral.sh/uv/reference/cli/#uv-version--bump" + echo "Also can be used as:" + echo "$0 " +} + +if [ -z "$1" ] || [ "$1" == "--help" ]; then + _usage + exit 1 +fi + +echo "::group::Bump new version" +VERSION=$(uv version --short) +if [ "$1" == "major" ] || [ "$1" == "minor" ] || [ "$1" == "patch" ]; then + uv version --no-sync --bump "$1" + exit_value=$? +elif [ "$1" == "stable" ]; then + uv version --no-sync --bump stable + exit_value=$? + if [ $exit_value != 0 ]; then + echo "You must create a release first." + exit $exit_value + fi +elif [ "$1" == "dev" ]; then + if (echo "$VERSION" | grep -q "\.dev"); then + uv version --no-sync --bump dev + else + uv version --no-sync --bump patch --bump dev=0 + fi + exit_value=$? +elif [ "$1" == "build-dev" ]; then + SOURCE_DATE_EPOCH=$(git log -1 --pretty=%ct) + if (echo "$VERSION" | grep -q "\.dev"); then + uv version --no-sync --bump dev="$SOURCE_DATE_EPOCH" + else + uv version --no-sync --bump patch --bump dev="$SOURCE_DATE_EPOCH" + fi + exit_value=$? +elif [ "$1" == "major-dev" ] || [ "$1" == "minor-dev" ] || [ "$1" == "patch-dev" ]; then + if (echo "$VERSION" | grep -q "\.dev"); then + echo "error: to increase an version, use option or option." + exit 1 + fi + if [ "$1" == "major-dev" ]; then + uv version --no-sync --bump major --bump dev=0 + elif [ "$1" == "minor-dev" ]; then + uv version --no-sync --bump minor --bump dev=0 + elif [ "$1" == "patch-dev" ]; then + uv version --no-sync --bump patch --bump dev=0 + fi + exit_value=$? +else + echo "error: invalid option: $1" + exit 1 +fi +if [ $exit_value != 0 ]; then + exit $exit_value +fi +NEW_VERSION=$(uv version --short) +if ! (git config --get user.email | grep -q "@"); then + git config user.name "Marcelo Duarte" + git config user.email marcelotduarte@users.noreply.github.com +fi +if (git branch --show-current | grep -q "main"); then + git checkout -B release main +fi +git commit -m "Bump version: ${VERSION} → ${NEW_VERSION} [ci skip]" -a +git log -1 +if ! [ "$CI" == "true" ]; then + git push origin "$(git branch --show-current)" + git push origin "$(git branch --show-current)" --tags +fi +echo "::endgroup::" diff --git a/ci/install-tools.sh b/ci/install-tools.sh index 8f81956..8d1d636 100755 --- a/ci/install-tools.sh +++ b/ci/install-tools.sh @@ -5,7 +5,7 @@ mkdir -p "$INSTALL_DIR" if which python &>/dev/null; then PY_PLATFORM=$(python -c "import sysconfig; print(sysconfig.get_platform(), end='')") -elif ! [ -n "$MINGW_PACKAGE_PREFIX" ]; then +elif [ -z "$MINGW_PACKAGE_PREFIX" ]; then PY_PLATFORM="mingw" else PY_PLATFORM="" @@ -46,7 +46,7 @@ if [ "$IS_CONDA" == "1" ]; then SYS_PLATFORM=$(python -c "import sys; print(sys.platform, end='')") # Packages to install pkgs=("uv" "python-build") - if which python &>/dev/null; then + if ! which python &>/dev/null; then pkgs+=("python=3.13") fi @@ -88,7 +88,7 @@ if [ "$IS_CONDA" == "1" ]; then elif [ "$IS_MINGW" == "1" ]; then # Packages to install pkgs=("$MINGW_PACKAGE_PREFIX-uv" "$MINGW_PACKAGE_PREFIX-python-build") - if which python &>/dev/null; then + if ! which python &>/dev/null; then pkgs+=("$MINGW_PACKAGE_PREFIX-python") fi