Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update release.py #6

Merged
merged 3 commits into from
Oct 4, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 15 additions & 12 deletions scripts/release.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,26 @@
#!/usr/bin/env python3

import os
import re
import subprocess


def create_tag():
subprocess.check_call(["git", "fetch", "--all", "--tags"]) # fetch remote tags
subprocess.check_call(["git", "fetch", "--all", "--tags"])
# create new tag as per current release
stream = os.popen('git describe --abbrev=0 --tags')
current_tag = stream.read().strip()
# TODO(Xueyan): the current parsing is buggy, if the main version number is a two-digit number.
# You need parse the string, e.g., the first string is 'v', and after 'v', there should be
# two numbers seperated by a '.'
if current_tag[0] != 'v':
raise Exception("The tag name should start with v")
major_version = int(current_tag[1])
minor_version = int(current_tag[3])
q, r = divmod(minor_version + 1, 10)
return "v{}.{}".format(major_version + q, r)

if not re.match("^v[0-9]+[.][0-9]", current_tag):
raise Exception("Error: tag name does not follow expected pattern.")

version = current_tag[1:].split('.')

major_version = int(version[0])
minor_version = int(version[1])
increment, new_minor_version = divmod(minor_version + 1, 10)

return f"v{major_version + increment}.{new_minor_version}"


def build_binary():
Expand All @@ -40,13 +43,13 @@ def main():
raise Exception('ERROR: This script should be run in the root folder of the project.')

tag_name = create_tag()
title = "Perses {}".format(tag_name)
title = f"Perses {tag_name}"

# get built binary path
jar = build_binary()

# release
release_command = ['hub', 'release', 'create', '-a', jar, '-m', title, tag_name]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be improved with f-string.

https://realpython.com/python-f-strings/

release_command = ['hub', 'release', 'create', '--browse', f"--attach={jar}", f'--message={title}', tag_name]

pipe = None
subprocess.check_call(
Expand Down