Add version info from git tags

This commit is contained in:
Balakrishnan Balasubramanian 2023-06-23 21:30:31 -04:00
parent 2bf809c454
commit 9107474d31
4 changed files with 41 additions and 6 deletions

View File

@ -1,5 +1,3 @@
shell:
MYPYPATH=`pipenv --venv`/lib/python3.11/site-packages pipenv shell
@ -18,6 +16,7 @@ requirements.txt: Pipfile.lock
build: clean requirements.txt
python3 -m pip install -r requirements.txt --target build
cp -r mail4one/ build/
sed -i "s/DEVELOMENT/$(shell scripts/get_version.sh)/" build/mail4one/version.py
python3 -m compileall build/mail4one -f
rm -rf build/*.dist-info
python3 -m zipapp \

View File

@ -9,6 +9,7 @@ from getpass import getpass
from .smtp import create_smtp_server_starttls, create_smtp_server
from .pop3 import create_pop_server
from .version import VERSION
from . import config
from . import pwhash
@ -25,15 +26,17 @@ def setup_logging(cfg: config.LogCfg):
if cfg.logfile == "STDOUT":
logging.basicConfig(level=cfg.level, format=logging_format)
else:
logging.basicConfig(filename=cfg.logfile, level=cfg.level, format=logging_format)
logging.basicConfig(filename=cfg.logfile,
level=cfg.level,
format=logging_format)
async def a_main(cfg: config.Config) -> None:
default_tls_context: ssl.SSLContext | None = None
if tls := cfg.default_tls:
logging.info(f"Initializing default tls {tls.certfile=}, {tls.keyfile=}")
logging.info(
f"Initializing default tls {tls.certfile=}, {tls.keyfile=}")
default_tls_context = create_tls_context(tls.certfile, tls.keyfile)
def get_tls_context(tls: config.TLSCfg | str):
@ -102,6 +105,7 @@ def main() -> None:
description="Personal Mail Server",
epilog="See https://gitea.balki.me/balki/mail4one for more info",
)
parser.add_argument("-v", "--version", action="version", version=VERSION)
parser.add_argument(
"-e",
"--echo_password",
@ -150,7 +154,7 @@ def main() -> None:
else:
cfg = config.Config(args.config.read_text())
setup_logging(config.LogCfg(cfg.logging))
logging.info(f"Starting mail4one {args.config=!s}")
logging.info(f"Starting mail4one {VERSION} {args.config=!s}")
asyncio.run(a_main(cfg))

2
mail4one/version.py Normal file
View File

@ -0,0 +1,2 @@
VERSION = "DEVELOMENT"

30
scripts/get_version.sh Executable file
View File

@ -0,0 +1,30 @@
#!/bin/sh
commit=$(git rev-parse --short HEAD)
# This is true if there is a tag on current HEAD
if git describe --exact-match > /dev/null 2>&1
then
tag_val=$(git describe --dirty=DIRTY --exact-match)
case "$tag_val" in
*DIRTY)
echo "git=$commit-changes"
exit
;;
v*) # Only consider tags starting with v
echo "$tag_val"
;;
*)
echo "git-$commit"
esac
else
tag_val=$(git describe --dirty=DIRTY)
case "$tag_val" in
*DIRTY)
echo "git-$commit-changes"
;;
*)
echo "git-$commit"
esac
fi