diff --git a/.github/workflows/pypi.yaml b/.github/workflows/pypi.yaml new file mode 100644 index 0000000..651c0e1 --- /dev/null +++ b/.github/workflows/pypi.yaml @@ -0,0 +1,40 @@ +name: Publish to Pypi +on: + release: + types: [published] + +jobs: + publish: + name: Publish to PyPI + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v3 + with: + fetch-depth: 0 + + - name: Install Python3 + run: | + sudo apt-get update + sudo apt-get install python3 python3-pip + + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install setuptools wheel twine + + - name: Extract tag name + run: echo ::set-output name=TAG_NAME::$(echo $GITHUB_REF | cut -d / -f 3) + + - name: Set version to tag + run: | + sed -i "s/{{VERSION_PLACEHOLDER}}/${{ steps.tag.outputs.TAG_NAME }}/g" osdk/const.py + + - name: Build a binary wheel + run: | + python setup.py sdist bdist_wheel + + - name: Publish a Python distribution to PyPI + uses: pypa/gh-action-pypi-publish@release/v1 + with: + password: ${{ secrets.PYPI_API_TOKEN }} diff --git a/osdk/cmds.py b/osdk/cmds.py index 166b9ab..6b2646a 100644 --- a/osdk/cmds.py +++ b/osdk/cmds.py @@ -145,7 +145,7 @@ cmds += [Cmd("h", "help", "Show this help message", helpCmd)] def versionCmd(args: Args): - print(f"OSDK v{const.VERSION}\n") + print(f"OSDK v{const.get_version()}\n") cmds += [Cmd("v", "version", "Show current version", versionCmd)] diff --git a/osdk/const.py b/osdk/const.py index 9eec9c5..b998d9d 100644 --- a/osdk/const.py +++ b/osdk/const.py @@ -1,7 +1,8 @@ import os import sys +import subprocess -VERSION = "0.4.0" +VERSION = "{{VERSION_PLACEHOLDER}}" MODULE_DIR = os.path.dirname(os.path.realpath(__file__)) ARGV0 = os.path.basename(sys.argv[0]) OSDK_DIR = ".osdk" diff --git a/osdk/utils.py b/osdk/utils.py index b1374de..1b22a9c 100644 --- a/osdk/utils.py +++ b/osdk/utils.py @@ -2,6 +2,8 @@ from typing import Any, TypeVar, cast import json import hashlib +from osdk import shell, const + T = TypeVar('T') @@ -56,3 +58,10 @@ def asList(i: T | list[T] | None) -> list[T]: if isinstance(i, list): return cast(list[T], i) return [i] + + +def get_version() -> str: + if const.VERSION == "{{VERSION_PLACEHOLDER}}": + return str(int(shell.popen(*["git", "rev-parse", "--short", "HEAD"])[:-1], 16)) + else: + return const.VERSION \ No newline at end of file diff --git a/setup.py b/setup.py index e51ca27..b057eec 100644 --- a/setup.py +++ b/setup.py @@ -1,9 +1,9 @@ from setuptools import setup -from osdk.const import VERSION +from osdk.utils import get_version setup( name="osdk", - version=VERSION, + version=get_version(), python_requires='>=3.10', description="Operating System Development Kit", author="The DEVSE Community",