11#!/usr/bin/env python
22import click
3+ from datetime import datetime
34from six .moves import input
45from subprocess import check_call , check_output
56import sys
67
7- WORKING_BRANCH = "PREP_RELEASE_%s"
88DATABRICKS_REMOTE = "[email protected] :databricks/spark-deep-learning.git" 9- PUBLISH_MODES = {"local" : "publishLocal" , "m2" : "publishM2" , "spark-package" : "spDist" }
9+ PUBLISH_MODES = {"local" : "publishLocal" , "m2" : "publishM2" , "spark-package-publish" : "spPublish" }
10+
11+ WORKING_BRANCH = "WORKING_BRANCH_RELEASE_%s_@%s"
12+ # lower case "z" puts the branch at the end of the github UI.
13+ WORKING_DOCS_BRANCH = "zWORKING_BRANCH_DOCS_%s_@%s"
14+ RELEASE_TAG = "v%s"
15+
1016
1117def prominentPrint (x ):
1218 x = str (x )
@@ -30,9 +36,12 @@ def verify(prompt, interactive):
3036@click .option ("--publish-to" , default = "local" ,
3137 help = "Where to publish artifact, one of: %s" % list (PUBLISH_MODES .keys ()))
3238@click .option ("--no-prompt" , is_flag = True , help = "Automated mode with no user prompts." )
33- def main (release_version , next_version , publish_to , no_prompt ):
39+ @click .option ("--git-remote" , default = DATABRICKS_REMOTE ,
40+ help = "Push current branch and docs to this git remote." )
41+ def main (release_version , next_version , publish_to , no_prompt , git_remote ):
3442 interactive = not no_prompt
3543
44+ time = datetime .now ().strftime ("%Y-%m-%dT%H-%M-%S" )
3645 if publish_to not in PUBLISH_MODES :
3746 modes = list (PUBLISH_MODES .keys ())
3847 print ("Unknown publish target, --publish-to should be one of: %s." % modes )
@@ -47,22 +56,32 @@ def main(release_version, next_version, publish_to, no_prompt):
4756 sys .exit (1 )
4857
4958 current_branch = check_output (["git" , "rev-parse" , "--abbrev-ref" , "HEAD" ]).strip ()
50- if current_branch != "master" :
59+ if current_branch != b "master" :
5160 if not verify ("You're not on the master branch do you want to continue? (y/n)" ,
5261 interactive ):
5362 sys .exit (1 )
5463
5564 uncommitted_changes = check_output (["git" , "diff" , "--stat" ])
56- if uncommitted_changes != "" :
65+ if uncommitted_changes != b "" :
5766 print (uncommitted_changes )
5867 print ("There seem to be uncommitted changes on your current branch. Please commit or "
5968 "stash them and try again." )
6069 sys .exit (1 )
6170
62- working_branch = WORKING_BRANCH % release_version
63- if working_branch in check_output (["git" , "branch" ]):
64- prominentPrint (
65- "Working branch %s already exists, please delete it and try again." % working_branch )
71+ working_branch = WORKING_BRANCH % (release_version , time )
72+ gh_pages_branch = WORKING_DOCS_BRANCH % (release_version , time )
73+
74+ release_tag = RELEASE_TAG % release_version
75+ target_tags = [release_tag ]
76+
77+ existing_tags = check_output (["git" , "tag" ]).decode ().split ()
78+ conflict_tags = list (filter (lambda a : a in existing_tags , target_tags ))
79+ if conflict_tags :
80+ msg = ("The following tags already exist:\n "
81+ " %s\n "
82+ "Please delete them and try." )
83+ msg = msg % "\n " .join (conflict_tags )
84+ prominentPrint (msg )
6685 sys .exit (1 )
6786
6887 prominentPrint ("Creating working branch for this release." )
@@ -73,7 +92,7 @@ def main(release_version, next_version, publish_to, no_prompt):
7392 check_call (["./build/sbt" , update_version ])
7493
7594 prominentPrint ("Building and testing with sbt." )
76- check_call (["git" , "checkout" , "v%s" % release_version ])
95+ check_call (["git" , "checkout" , release_tag ])
7796
7897 publish_target = PUBLISH_MODES [publish_to ]
7998 check_call (["./build/sbt" , "clean" , publish_target ])
@@ -84,8 +103,31 @@ def main(release_version, next_version, publish_to, no_prompt):
84103 check_call (["git" , "branch" , "-d" , working_branch ])
85104
86105 prominentPrint ("Local branch updated" )
87- if verify ("Would you like to push local branch to databricks remote? (y/n)" , interactive ):
88- check_call (["git" , "push" , DATABRICKS_REMOTE , current_branch ])
106+ if verify ("Would you like to push local branch & version tag to remote: %s? (y/n)" % git_remote ,
107+ interactive ):
108+ check_call (["git" , "push" , git_remote , current_branch ])
109+ check_call (["git" , "push" , git_remote , release_tag ])
110+
111+ prominentPrint ("Building release docs" )
112+
113+ if not verify ("Would you like to build release docs? (y/n)" , interactive ):
114+ # All done, exit happy
115+ sys .exit (0 )
116+
117+ check_call (["git" , "checkout" , "-b" , gh_pages_branch , release_tag ])
118+ check_call (["./dev/build-docs.sh" ])
119+
120+ commit_message = "Build docs for release %s." % release_version
121+ check_call (["git" , "add" , "-f" , "docs/_site" ])
122+ check_call (["git" , "commit" , "-m" , commit_message ])
123+ msg = "Would you like to push docs branch to %s and update gh-pages branch? (y/n)"
124+ msg %= git_remote
125+ if verify (msg , interactive ):
126+ check_call (["git" , "push" , git_remote , gh_pages_branch ])
127+ check_call (["git" , "push" , "-f" , git_remote , gh_pages_branch + ":gh-pages" ])
128+
129+ check_call (["git" , "checkout" , current_branch ])
130+ check_call (["git" , "branch" , "-D" , gh_pages_branch ])
89131
90132
91133if __name__ == "__main__" :
0 commit comments