diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 9ca5a20..d1a8baa 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -13,6 +13,8 @@ jobs: steps: - name: Set up Git repository uses: actions/checkout@v4 + # unfortunately we need to fetch all tags for version.py to work + fetch-depth: 0 - name: Fetch all Git tags # this is necessary for version.py because git describe does not work on a shallow clone: @@ -37,7 +39,6 @@ jobs: run: black --check . - name: Run unit tests (except the ones using Gurobi and CPLEX) - shell: bash -l {0} run: python -m pytest --cov=. --cov-report=lcov -k "not gurobi and not cplex" tests - name: Coveralls test coverage diff --git a/syfop/version.py b/syfop/version.py index 95e7a6a..e3f91c1 100644 --- a/syfop/version.py +++ b/syfop/version.py @@ -4,7 +4,16 @@ def get_version(): """Get the latest Git tag and prepend 'v' and use the Git comit hash as suffix if the current commit has not Git tag.""" - git_tag = subprocess.check_output(["git", "describe", "--tags"]).decode().strip() + # TODO this will raise an exception if: + # - there are no tags + # - if it is a shallow clone with --depth 1 + try: + git_tag = subprocess.check_output(["git", "describe", "--tags"], stderr=subprocess.STDOUT) + except subprocess.CalledProcessError as e: + raise RuntimeError(f"Unable to get version from Git: {e}: {e.output.decode()}") + + # TODO we don't check if the tag is a valid version string (e.g. v0.1.0). + git_tag = git_tag.decode().strip() version = git_tag.lstrip("v") # convert string from git-describe to a valid PEP440 version string