Skip to content

Commit

Permalink
Added simple release scripts (databrickslabs#248)
Browse files Browse the repository at this point in the history
  • Loading branch information
edurdevic authored Nov 10, 2022
1 parent b1f7d5a commit 8df7e75
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 0 deletions.
19 changes: 19 additions & 0 deletions scripts/tag_version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import os
import sys
import re

def main(version):
os.system("git checkout main && git pull")
os.system("git tag -a v_%s -m 'Version %s'" % (version, version))
os.system("git push origin v_%s" % version)

if __name__ == "__main__":
if len(sys.argv) < 2:
raise Exception("Please specify a version. Use format x.y.z.")
version = sys.argv[1]

if (not re.match(r'\d+\.\d+\.\d+', version)):
raise Exception("Invalid version: %s. Use format x.y.z." % version)

main(version)

62 changes: 62 additions & 0 deletions scripts/update_version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import os
import re
import sys

def main(version, snapshot):
update_pom_version('../pom.xml', version + snapshot)
update_python_version('../python/mosaic/__init__.py', version + snapshot)
update_r_version('../R/sparkR-mosaic/sparkrMosaic/DESCRIPTION', version)
update_r_version('../R/sparklyr-mosaic/sparklyrMosaic/DESCRIPTION', version)

if not snapshot:
update_docs_version('../docs/source/conf.py', version)

def update_pom_version(file, version):
update_version(file, r'(<version>)(\d+\.\d+\.\d+(-SNAPSHOT)?)(</version>)', r'\g<1>%s\g<4>' % version)

def update_python_version(file, version):
update_version(file, r'(__version__ = )("\d+\.\d+\.\d+(-SNAPSHOT)?")', r'\g<1>"%s"' % version)

def update_r_version(file, version):
update_version(file, r'(Version: )(\d+\.\d+\.\d+(-SNAPSHOT)?)', r'\g<1>%s' % version)

def update_docs_version(file, version):
update_version(file, r'(release = )("v\d+\.\d+\.\d+")', r'\g<1>"v%s"' % version)


def update_version(file, pattern, replace_pattern):
#Open file and replace

with open (file, 'r' ) as f:
content = f.read()
content_new = re.sub(pattern, replace_pattern, content, flags = re.M, count = 1)
with open (file, 'w' ) as f:
f.write(content_new)


if __name__ == "__main__":

version = sys.argv[1]
snapshot = ""
if len(sys.argv) > 2:
snapshot = sys.argv[2]
if snapshot != "-SNAPSHOT":
raise Exception("Invalid argument: %s. Use -SNAPSHOT or leave blank." % snapshot)

if re.match(r'\d+\.\d+\.\d+', version) is None:
raise Exception("Invalid version: %s. Use format x.y.z." % version)

os.system(
"git checkout main && git pull && git checkout -b releases/v_%s%s" % (version, snapshot)
)
main(version, snapshot)
print("Version updated to %s%s" % (version, snapshot))
print("Please update the CHANGELOG.md and press ENTER to continue.")
input()

os.system("git add '../pom.xml'")
os.system("git add '../python/mosaic/__init__.py'")
os.system("git add '../R/sparkR-mosaic/sparkrMosaic/DESCRIPTION'")
os.system("git add '../R/sparklyr-mosaic/sparklyrMosaic/DESCRIPTION'")

os.system("git commit -m 'Update version to %s%s' && git push -u origin releases/v_%s%s" % (version, snapshot, version, snapshot))

0 comments on commit 8df7e75

Please sign in to comment.