Skip to content

Commit

Permalink
Fetch complete git history on Github actions
Browse files Browse the repository at this point in the history
This should allow installing syfop via pip and fix the issues with
version.py.
  • Loading branch information
lumbric committed May 7, 2024
1 parent 06c200a commit e75a0a0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
Expand Down
11 changes: 10 additions & 1 deletion syfop/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit e75a0a0

Please sign in to comment.