From 6d6621bf37852891f6117e0a7500d0ab04e15228 Mon Sep 17 00:00:00 2001 From: Daylin Morgan Date: Wed, 23 Aug 2023 02:35:05 -0500 Subject: [PATCH] build: new release workflow --- Makefile | 9 ------- noxfile.py | 5 ++++ scripts/bump-dev.sh | 4 ---- scripts/release.py | 57 +++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 62 insertions(+), 13 deletions(-) delete mode 100755 scripts/bump-dev.sh create mode 100755 scripts/release.py diff --git a/Makefile b/Makefile index 452f17e..5a88dda 100644 --- a/Makefile +++ b/Makefile @@ -1,13 +1,4 @@ VERSION ?= $(shell git describe --tags --always --dirty=-dev | sed 's/^v//g') -PREFIX ?= ~/bin - -bump: ## update version and tag commit - @echo "bumping to version => $(VERSION)" - @sed -i 's/__version__ = ".*"/__version__ = "$(VERSION)"/g' src/viv/viv.py - @git add src/viv/viv.py && git commit -m "chore: bump version" --no-verify - @git tag v$(VERSION) - @git tag -d latest || true - @git tag latest venv: ## generate environment pdm install diff --git a/noxfile.py b/noxfile.py index 03df2e1..31bdccb 100644 --- a/noxfile.py +++ b/noxfile.py @@ -49,6 +49,11 @@ def docs(session): session.run("mkdocs", "build") +@nox.session +def release(session): + session.run("./scripts/release.py", external=True) + + # @nox.session( # python=["3.8", "3.9", "3.10", "3.11"] # ) diff --git a/scripts/bump-dev.sh b/scripts/bump-dev.sh deleted file mode 100755 index 4c25a17..0000000 --- a/scripts/bump-dev.sh +++ /dev/null @@ -1,4 +0,0 @@ -#!/usr/bin/env sh -TAG=$(git describe --tags --always --dirty=-dev --exclude 'latest') -VERSION="${TAG#v}" -sed -i "s/__version__ = \".*\"/__version__ = \"$VERSION\"/g" src/viv/viv.py diff --git a/scripts/release.py b/scripts/release.py new file mode 100755 index 0000000..233cf8e --- /dev/null +++ b/scripts/release.py @@ -0,0 +1,57 @@ +#!/usr/bin/env python3 + +import re +import subprocess +import sys +from datetime import datetime +from pathlib import Path + +FILE = Path(__file__).parent.parent / "src/viv/viv.py" + + +def get_version(): + return subprocess.check_output( + [ + "git", + "describe", + "--tags", + "--always", + "--dirty=-dev", + "--exclude", + "latest", + ], + text=True, + ) + + +def inc_build(build): + """increment build number while keeping lexicographic order + 1001 -> 1002 + 1999 -> 22000 + 22001 -> 22002 + """ + next = str(int(build) + 1) + return next if build[0] <= next[0] else f"{int(next[0])*11}{next[1:]}" + + +def release(): + full = get_version() + if full.endswith("-dev"): + print("uncommitted changes refusing to proceed") + sys.exit(1) + + # remove v and git info + current = full[1:].split("-")[0] + _, build = current.split(".") + next = f"{datetime.now().year}.{inc_build(build)}" + msg = f"bump {current} -> {next}" + FILE.write_text( + re.sub(r'__version__ = "[\d\.]+"', f'__version__ = "{next}"', FILE.read_text()) + ) + subprocess.run(["git", "add", FILE]) + subprocess.run(["git", "commit", "-m", msg, "--no-verify"]) + subprocess.run(["git", "tag", f"v{next}"]) + + +if __name__ == "__main__": + release()