-
Notifications
You must be signed in to change notification settings - Fork 1
/
versioner.py
executable file
·99 lines (84 loc) · 3.39 KB
/
versioner.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#!/usr/bin/env python
from __future__ import print_function
import re
import sys
import time
import fileinput
import subprocess
# Fetch version from git tags, and write to version.py.
# Also, when git is not available (PyPi package), use stored version.py.
initfile = "PIED/__init__.py"
version_git = sys.argv[1]
print("Setting new version to - {}".format(version_git))
# Make sure we you have the current changes in master w/o any
# merge conflicts
try:
subprocess.check_call(["git", "pull"])
except Exception as inst:
sys.exit("You have unmerged conflicts from master. Fix these then "
+ "rerun versioner.py\n{}".format(inst))
# Make sure to track previous release version
prev_version = ""
with open(initfile, 'r') as infile:
for line in infile:
if line.strip().startswith("__version__"):
prev_version = str(line.split("=")[1].strip().strip("\""))
break
print("last version - {}".format(prev_version))
# Update docs/releasenotes.rst to include commit history for this version
release_file = "docs/releasenotes.rst"
# Get all commits since last tag
# git log --pretty=oneline tagA..
cmd = "git log --pretty=oneline {}..".format(prev_version)
new_commits = subprocess.check_output(cmd.split())
# Split off just the first element, cuz we don't care about the
# commit tag
print(new_commits)
commit_lines = [x.split(b" ", 1) for x in new_commits.split(b"\n")]
checkfor = "Merge branch 'master' of https://github.com/isaacovercast/PIED"
# Write updates to releasenotes.rst
for line in fileinput.input(release_file, inplace=1):
if line.strip().startswith("=========="):
line += "\n"
line += version_git + "\n"
line += "-" * len(version_git) + "\n"
line += "**" + time.strftime("%B %d, %Y") + "**\n\n"
for commit in commit_lines:
try:
# Squash merge commits from the releasenotes cuz it annoying
# Also any cosmetic commits
if commit[1] == checkfor:
continue
if "cosmetic" in commit[1]:
continue
line += "- " + commit[1] + "\n"
except:
pass
print(line.strip("\n"))
# Write version to PIED/__init__.py
for line in fileinput.input(initfile, inplace=1):
if line.strip().startswith("__version__"):
line = "__version__ = \""+version_git+"\""
print(line.strip("\n"))
conda_yaml_file = "conda.recipe/PIED/meta.yaml"
for line in fileinput.input(conda_yaml_file, inplace=1):
if line.strip().startswith("version"):
line = " version: \"{}\"".format(version_git)
print(line.strip("\n"))
try:
subprocess.call(["git", "add", release_file])
subprocess.call(["git", "add", initfile])
subprocess.call(["git", "add", conda_yaml_file])
subprocess.call(["git", "commit", "-m \"Updating PIED/__init__.py to "+\
"version - {}".format(version_git)])
subprocess.call(["git", "push"])
subprocess.call(["git", "tag", "-a", version_git, "-m", "Updating PIED to "+\
"version - {}".format(version_git)])
subprocess.call(["git", "push", "origin", version_git])
except Exception as e:
print("Something broke - {}".format(e))
print("Push new version of conda installer")
try:
subprocess.call(["conda", "build", "-c", "conda-forge", "conda.recipe/PIED"])
except Exception as e:
print("something broke - {}".format(e))