build: new release workflow

This commit is contained in:
Daylin Morgan 2023-08-23 02:35:05 -05:00
parent 871d352189
commit 6d6621bf37
Signed by: daylin
GPG key ID: C1E52E7DD81DF79F
4 changed files with 62 additions and 13 deletions

View file

@ -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

View file

@ -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"]
# )

View file

@ -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

57
scripts/release.py Executable file
View file

@ -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()