Skip to content

Commit

Permalink
Add checks to bumpver script before version bump
Browse files Browse the repository at this point in the history
Let's make sure that we won't release a broken code.
  • Loading branch information
jkonecny12 authored and jpodivin committed May 9, 2024
1 parent 0b99680 commit 58f5df3
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions scripts/bumpver.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/usr/bin/env python
import argparse
import subprocess
import sys


NAME = "logdetective"
Expand Down Expand Up @@ -48,6 +49,30 @@ def create_tag(version):
subprocess.run(["git", "tag", f"{NAME}-{version}"], check=True)


def run_checks():
"""Run checks on the code and check lock file."""
ok = True
print("Running poetry lock check")
try:
subprocess.run(["poetry", "check", "--lock"],
check=True,
stdout=sys.stdout, stderr=sys.stderr)
except subprocess.CalledProcessError:
print("Poetry lock file is not up to date!", file=sys.stderr)
ok = False

print("Running tests")
try:
subprocess.run(["tox"],
check=True,
stdout=sys.stdout, stderr=sys.stderr)
except subprocess.CalledProcessError:
print("Tests failed!", file=sys.stderr)
ok = False

return ok


if __name__ == "__main__":
# Parse arguments
parse = argparse.ArgumentParser("bumpver.py",
Expand All @@ -57,8 +82,18 @@ def create_tag(version):
parse.add_argument("--version", action="store", default=None,
dest="version", help="""Set a specific version. Without this argument the
patch version bump will be automatically used.""")
parse.add_argument("--no-check", action="store_false",
default=True, dest="check",
help="Disable checks on the code and lock file before commit.")
args = parse.parse_args()

# Run checks before version bump
if args.check:
if not run_checks():
print("\nChecks returned error!", file=sys.stderr)
print("If you want to bypass checks use '--no-check' argument.")
sys.exit(1)

# Bump the project version
new_version = bump_version(args.version)
commit(new_version)
Expand Down

0 comments on commit 58f5df3

Please sign in to comment.