1818import unittest
1919import subprocess
2020
21+ import click
2122from git import Repo
2223
2324
25+ DEV_BRANCHES = ["master" ]
26+
27+
2428class TestScript (unittest .TestCase ):
2529 def test_get_docs_version (self ):
2630 ver , alias = get_docs_version ("master" , [])
@@ -41,7 +45,7 @@ def test_get_docs_version(self):
4145
4246
4347def get_docs_version (ref_name , release_branches ):
44- if ref_name == "master" :
48+ if ref_name in DEV_BRANCHES :
4549 return "dev" , ""
4650
4751 if ref_name in release_branches :
@@ -72,11 +76,19 @@ def get_rel_branch_names(blist):
7276 return sorted (names , key = lambda x : int (x .split ("." )[1 ]), reverse = True )
7377
7478
75- def main (repo_dir ):
76- # Git remote must be set to publish docs
77- remote = os .environ .get ("REMOTE" )
78- if not remote :
79- print ("REMOTE env var must be set to publish, running dry mode" )
79+ @click .command ()
80+ @click .option ("--test" , is_flag = True )
81+ @click .option ("--dry" , is_flag = True )
82+ @click .option ("--remote" , default = "origin" , help = "The git remote where to push." )
83+ def main (test , dry , remote ):
84+ # Run tests if requested
85+ if test :
86+ unittest .main (argv = ["" ], exit = False )
87+ sys .exit (0 )
88+
89+ # Detect repo root folder
90+ here = os .path .dirname (os .path .realpath (__file__ ))
91+ repo_dir = os .path .join (here , ".." )
8092
8193 # Get current repo
8294 repo = Repo (repo_dir )
@@ -93,18 +105,16 @@ def main(repo_dir):
93105 )
94106 return 0
95107
96- args = [
97- "task docs:publish" ,
98- f"DOCS_REMOTE={ remote } " ,
99- f"DOCS_VERSION={ docs_version } " ,
100- f"DOCS_ALIAS={ alias } " ,
101- ]
102- if remote :
103- subprocess .run (args , shell = True , check = True , cwd = repo_dir )
104- else :
105- print (" " .join (args ))
108+ # Taskfile args aren't regular args so we put everything in one string
109+ cmd = (
110+ f"task docs:publish DOCS_REMOTE={ remote } DOCS_VERSION={ docs_version } DOCS_ALIAS={ alias } " ,
111+ )
106112
107- return 0
113+ if dry :
114+ print (cmd )
115+ return 0
116+
117+ subprocess .run (cmd , shell = True , check = True , cwd = repo_dir )
108118
109119
110120# Usage:
@@ -116,9 +126,4 @@ def main(repo_dir):
116126# $python build.py
117127#
118128if __name__ == "__main__" :
119- if len (sys .argv ) > 1 and sys .argv [1 ] == "test" :
120- unittest .main (argv = ["" ], exit = False )
121- sys .exit (0 )
122-
123- here = os .path .dirname (os .path .realpath (__file__ ))
124- sys .exit (main (os .path .join (here , ".." )))
129+ sys .exit (main ())
0 commit comments