Skip to content

Commit 438e1ef

Browse files
Add a script to bump-version
1 parent 1d7497d commit 438e1ef

4 files changed

Lines changed: 93 additions & 41 deletions

File tree

.github/workflows/build.yml

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -93,20 +93,7 @@ jobs:
9393

9494
- name: Bump new dev version
9595
if: github.event_name != 'release'
96-
run: |
97-
git config user.name "Marcelo Duarte"
98-
git config user.email marcelotduarte@users.noreply.github.com
99-
SOURCE_DATE_EPOCH=$(git log -1 --pretty=%ct)
100-
VERSION=$(uv version --short)
101-
if (echo "$VERSION" | grep -q "\.dev"); then
102-
uv version --no-sync --bump dev=$SOURCE_DATE_EPOCH
103-
else
104-
uv version --no-sync --bump patch --bump dev=$SOURCE_DATE_EPOCH
105-
fi
106-
NEW_VERSION=$(uv version --short)
107-
git checkout -b build-$NEW_VERSION
108-
git commit -m "Bump version: ${VERSION} → ${NEW_VERSION} [ci skip]" -a
109-
git log -2
96+
run: ./ci/bump-version.sh build-dev
11097

11198
- name: Build sdist and wheels
11299
run: ./ci/build-wheel.sh "${{ matrix.tag }}"

Makefile

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -59,27 +59,3 @@ cov: wheel
5959
coverage combine --keep --quiet -a $(COV_TMPDIR)/
6060
coverage report
6161
coverage html --show-contexts
62-
63-
.PHONY: release
64-
release:
65-
uv version
66-
@echo "Run:"
67-
@echo " uv version <new-version>"
68-
@echo "--or--"
69-
@echo " uv version --bump <major|minor|patch>"
70-
@echo "--then--"
71-
@echo " git push origin `git branch --show-current`"
72-
@echo " git push origin `git branch --show-current` --tags"
73-
74-
.PHONY: release-dev
75-
release-dev:
76-
git checkout -B release main
77-
if (uv version --short | grep -q "\.dev"); then\
78-
uv version --bump dev;\
79-
else\
80-
uv version --bump patch --bump dev=0;\
81-
fi
82-
git commit -m "Bump dev version: `uv version --short` [ci skip]" -a
83-
git push origin `git branch --show-current`
84-
git push origin `git branch --show-current` --tags
85-
git log -1

ci/bump-version.sh

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
#!/bin/bash
2+
3+
# Get script directory (without using /usr/bin/realpath)
4+
_CI_DIR=$(dirname "${BASH_SOURCE[0]}")
5+
CI_DIR=$(cd "$_CI_DIR" && pwd)
6+
7+
# Python information (platform and version)
8+
if ! which uv &>/dev/null; then
9+
# Install/update uv
10+
"$CI_DIR/install-tools.sh" --dev
11+
fi
12+
13+
# Usage
14+
_usage () {
15+
echo "Usage:"
16+
echo "$0 <major|minor|patch|dev|stable>"
17+
echo "Based on:"
18+
echo " https://docs.astral.sh/uv/reference/cli/#uv-version--bump"
19+
echo "Also can be used as:"
20+
echo "$0 <major-dev|minor-dev|patch-dev|build-dev>"
21+
}
22+
23+
if [ -z "$1" ] || [ "$1" == "--help" ]; then
24+
_usage
25+
exit 1
26+
fi
27+
28+
echo "::group::Bump new version"
29+
VERSION=$(uv version --short)
30+
if [ "$1" == "major" ] || [ "$1" == "minor" ] || [ "$1" == "patch" ]; then
31+
uv version --no-sync --bump "$1"
32+
exit_value=$?
33+
elif [ "$1" == "stable" ]; then
34+
uv version --no-sync --bump stable
35+
exit_value=$?
36+
if [ $exit_value != 0 ]; then
37+
echo "You must create a <dev> release first."
38+
exit $exit_value
39+
fi
40+
elif [ "$1" == "dev" ]; then
41+
if (echo "$VERSION" | grep -q "\.dev"); then
42+
uv version --no-sync --bump dev
43+
else
44+
uv version --no-sync --bump patch --bump dev=0
45+
fi
46+
exit_value=$?
47+
elif [ "$1" == "build-dev" ]; then
48+
SOURCE_DATE_EPOCH=$(git log -1 --pretty=%ct)
49+
if (echo "$VERSION" | grep -q "\.dev"); then
50+
uv version --no-sync --bump dev="$SOURCE_DATE_EPOCH"
51+
else
52+
uv version --no-sync --bump patch --bump dev="$SOURCE_DATE_EPOCH"
53+
fi
54+
exit_value=$?
55+
elif [ "$1" == "major-dev" ] || [ "$1" == "minor-dev" ] || [ "$1" == "patch-dev" ]; then
56+
if (echo "$VERSION" | grep -q "\.dev"); then
57+
echo "error: to increase an <dev> version, use <dev> option or <build-dev> option."
58+
exit 1
59+
fi
60+
if [ "$1" == "major-dev" ]; then
61+
uv version --no-sync --bump major --bump dev=0
62+
elif [ "$1" == "minor-dev" ]; then
63+
uv version --no-sync --bump minor --bump dev=0
64+
elif [ "$1" == "patch-dev" ]; then
65+
uv version --no-sync --bump patch --bump dev=0
66+
fi
67+
exit_value=$?
68+
else
69+
echo "error: invalid option: $1"
70+
exit 1
71+
fi
72+
if [ $exit_value != 0 ]; then
73+
exit $exit_value
74+
fi
75+
NEW_VERSION=$(uv version --short)
76+
if (git branch --show-current | grep -q "main"); then
77+
git checkout -B release main
78+
fi
79+
if (git config --get user.email | grep -q "@"); then
80+
git config user.name "Marcelo Duarte"
81+
git config user.email marcelotduarte@users.noreply.github.com
82+
fi
83+
git commit -m "Bump version: ${VERSION}${NEW_VERSION} [ci skip]" -a
84+
git log -1
85+
if ! [ "$CI" == "true" ]; then
86+
git push origin "$(git branch --show-current)"
87+
git push origin "$(git branch --show-current)" --tags
88+
fi
89+
echo "::endgroup::"

ci/install-tools.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ mkdir -p "$INSTALL_DIR"
55

66
if which python &>/dev/null; then
77
PY_PLATFORM=$(python -c "import sysconfig; print(sysconfig.get_platform(), end='')")
8-
elif ! [ -n "$MINGW_PACKAGE_PREFIX" ]; then
8+
elif [ -z "$MINGW_PACKAGE_PREFIX" ]; then
99
PY_PLATFORM="mingw"
1010
else
1111
PY_PLATFORM=""
@@ -46,7 +46,7 @@ if [ "$IS_CONDA" == "1" ]; then
4646
SYS_PLATFORM=$(python -c "import sys; print(sys.platform, end='')")
4747
# Packages to install
4848
pkgs=("uv" "python-build")
49-
if which python &>/dev/null; then
49+
if ! which python &>/dev/null; then
5050
pkgs+=("python=3.13")
5151
fi
5252

@@ -88,7 +88,7 @@ if [ "$IS_CONDA" == "1" ]; then
8888
elif [ "$IS_MINGW" == "1" ]; then
8989
# Packages to install
9090
pkgs=("$MINGW_PACKAGE_PREFIX-uv" "$MINGW_PACKAGE_PREFIX-python-build")
91-
if which python &>/dev/null; then
91+
if ! which python &>/dev/null; then
9292
pkgs+=("$MINGW_PACKAGE_PREFIX-python")
9393
fi
9494

0 commit comments

Comments
 (0)