diff --git a/app/data/version.txt b/app/data/version.txt new file mode 100644 index 00000000..81447904 --- /dev/null +++ b/app/data/version.txt @@ -0,0 +1,2 @@ +# This file should be re-generated running: scripts/update-version-file.sh script +v1.0.6-alpha 9278d09 diff --git a/app/version.py b/app/version.py new file mode 100644 index 00000000..0547f0ea --- /dev/null +++ b/app/version.py @@ -0,0 +1,30 @@ +# Copyright © 2023 Cerc + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. + +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . + +import click +import importlib + +@click.command() +@click.pass_context +def command(ctx): + '''print tool version''' + + # See: https://stackoverflow.com/a/20885799/1701505 + from . import data + with importlib.resources.open_text(data, "version.txt") as version_file: + # TODO: code better version that skips comment lines + version_string = version_file.read().splitlines()[1] + + print(f"Version: {version_string}") diff --git a/cli.py b/cli.py index 1703a422..e2e94ab2 100644 --- a/cli.py +++ b/cli.py @@ -19,6 +19,7 @@ from app import setup_repositories from app import build_containers from app import build_npms from app import deploy_system +from app import version CONTEXT_SETTINGS = dict(help_option_names=['-h', '--help']) @@ -49,3 +50,4 @@ cli.add_command(setup_repositories.command, "setup-repositories") cli.add_command(build_containers.command, "build-containers") cli.add_command(build_npms.command, "build-npms") cli.add_command(deploy_system.command, "deploy-system") +cli.add_command(version.command, "version") diff --git a/scripts/build-shiv-package.sh b/scripts/build-shiv-package.sh new file mode 100755 index 00000000..98f49f4f --- /dev/null +++ b/scripts/build-shiv-package.sh @@ -0,0 +1,3 @@ +# Builds the shiv "package" for distribution +./scripts/update_version_file.sh +shiv -c laconic-so -o package/laconic-so . diff --git a/first_time_setup.sh b/scripts/first_time_setup.sh similarity index 100% rename from first_time_setup.sh rename to scripts/first_time_setup.sh diff --git a/scripts/update-version-file.sh b/scripts/update-version-file.sh new file mode 100755 index 00000000..fdcdac32 --- /dev/null +++ b/scripts/update-version-file.sh @@ -0,0 +1,3 @@ +version_file_name=./app/data/version.txt +echo "# This file should be re-generated running: scripts/update-version-file.sh script" > $version_file_name +echo $( git describe --tags --abbrev=0 ; git rev-parse --short HEAD ) >> $version_file_name