16
16
# Configure logging with coloredlogs
17
17
coloredlogs .install (level = 'DEBUG' ) # Set the logging level as needed
18
18
19
- def clone_repository (repo_url , repo_path , branch = 'main' ):
19
+ def clone_repository (git_url , repo_path , branch ):
20
20
if os .path .exists (repo_path ):
21
+ logging .warning (f"Repository path: { repo_path } already exists. Removing existing directory." )
21
22
shutil .rmtree (repo_path )
22
- logging .info (f"Cloning repository from { repo_url } to { repo_path } ..." )
23
23
24
- repository = Repo .clone_from (repo_url , repo_path )
25
- repository .git .checkout (branch )
26
- logging .info ("Repository cloned successfully." )
24
+ logging .info (f"Cloning Git repository: { git_url } (branch={ branch } ) to { repo_path } " )
25
+ try :
26
+ repository = Repo .clone_from (git_url , repo_path )
27
+ repository .git .checkout (branch )
28
+ logging .info (f"Git repository: { git_url } successfully cloned." )
29
+
30
+ except Exception as e :
31
+ logging .error (f"Failed to clone Git repository: { git_url } (branch={ branch } ): { e } ." )
32
+ raise
27
33
28
34
def prepare_operation (script_dir , operation_script , operation_args ):
29
35
shutil .copy (os .path .join (os .path .dirname (os .path .realpath (__file__ )), f"{ script_dir } /{ operation_script } " ), os .path .join (os .path .dirname (os .path .realpath (__file__ )), operation_script ))
@@ -35,70 +41,96 @@ def prepare_operation(script_dir, operation_script, operation_args):
35
41
36
42
def main (args ):
37
43
logging .basicConfig (level = logging .INFO )
44
+
38
45
start_time = time .time () # Record start time
46
+ logging .info ("🔄 Initiating the generate-shell script for operator bundle management and updates." )
47
+
48
+ # Extract org, repo, branch, pipeline_repo, and pipeline_branch from command-line arguments
49
+ # Use the specified org and branch or the defaults ('stolostron', 'installer-dev-tools', 'main', 'pipeline', '2.12-integration')
50
+ org = args .org
51
+ repo = args .repo
52
+ branch = args .branch
53
+ pipeline_repo = args .pipeline_repo
54
+ pipeline_branch = args .pipeline_branch
39
55
40
- repo_path = os .path .join (os .path .dirname (os .path .realpath (__file__ )), "tmp/dev-tools" ) # Destination path for cloned repository.
41
- clone_repository ("https://github.com/stolostron/installer-dev-tools.git" , repo_path )
56
+ # Define the destination path for the cloned repository
57
+ repo_path = os .path .join (os .path .dirname (os .path .realpath (__file__ )), "tmp/dev-tools" )
58
+
59
+ # Clone the repository using the specified git_url, destination path, and branch
60
+ git_url = f"https://github.com/{ org } /{ repo } .git"
61
+ clone_repository (git_url , repo_path , branch )
62
+
63
+ # Define the directory containing the bundle generation scripts
42
64
script_dir = "tmp/dev-tools/bundle-generation"
43
65
66
+ # Check which operation is requested based on command-line arguments
44
67
if args .lint_bundles :
45
- logging .info ("Preparing to perform linting for bundles..." )
68
+ logging .info ("Starting linting for bundles..." )
46
69
operation_script = "bundles-to-charts.py"
47
70
operation_args = "--lint --destination pkg/templates/"
48
71
49
72
prepare_operation (script_dir , operation_script , operation_args )
50
- logging .info ("Bundles linted successfully." )
73
+ logging .info ("✔️ Bundles linted successfully." )
51
74
52
75
elif args .update_charts_from_bundles :
53
- logging .info ("Preparing to update operator charts from bundles..." )
76
+ logging .info ("Updating operator charts from bundles..." )
54
77
operation_script = "bundles-to-charts.py"
55
78
operation_args = "--destination pkg/templates/"
56
79
57
80
prepare_operation (script_dir , operation_script , operation_args )
58
- logging .info ("Bundles updated successfully." )
81
+ logging .info ("✔️ Bundles updated successfully." )
59
82
60
83
elif args .update_charts :
61
- logging .info ("Preparing to update operator..." )
84
+ logging .info ("Updating operator charts ..." )
62
85
operation_script = "generate-charts.py"
63
86
operation_args = "--destination pkg/templates/"
64
87
65
88
prepare_operation (script_dir , operation_script , operation_args )
66
- logging .info ("Bundles updated successfully." )
89
+ logging .info ("✔️ Bundles updated successfully." )
67
90
68
91
elif args .copy_charts :
69
- logging .info ("Preparing to copy charts..." )
92
+ logging .info ("Copying charts..." )
70
93
operation_script = "move-charts.py"
71
94
operation_args = "--destination pkg/templates/"
72
95
73
96
prepare_operation (script_dir , operation_script , operation_args )
74
- logging .info ("Bundles updated successfully." )
97
+ logging .info ("✔️ Bundles updated successfully." )
75
98
76
99
elif args .update_commits :
77
- logging .info ("Preparing to update commit SHAs..." )
100
+ logging .info ("Updating commit SHAs..." )
78
101
operation_script = "generate-sha-commits.py"
79
- operation_args = f"--repo { args . repo } --branch { args . branch } "
102
+ operation_args = f"--repo { pipeline_repo } --branch { pipeline_branch } "
80
103
81
104
prepare_operation (script_dir , operation_script , operation_args )
82
- logging .info ("Commit SHAs updated successfully." )
105
+ logging .info ("✔️ Commit SHAs updated successfully." )
83
106
84
107
else :
85
- logging .warning ("No operation specified." )
108
+ logging .warning ("⚠️ No operation specified." )
86
109
87
- end_time = time .time () # Record end time
88
- logging .info (f"Script execution took { end_time - start_time :.2f} seconds." ) # Log duration
110
+ # Record the end time and log the duration of the script execution
111
+ end_time = time .time ()
112
+ logging .info (f"Script execution took { end_time - start_time :.2f} seconds." )
89
113
90
114
if __name__ == "__main__" :
115
+ # Set up argument parsing for command-line execution
91
116
parser = argparse .ArgumentParser ()
92
117
118
+ # Define command-line arguments and their help descriptions
93
119
parser .add_argument ("--lint-bundles" , action = "store_true" , help = "Perform linting for operator bundles" )
94
120
parser .add_argument ("--update-charts-from-bundles" , action = "store_true" , help = "Regenerate operator charts from bundles" )
95
121
parser .add_argument ("--update-commits" , action = "store_true" , help = "Regenerate operator bundles with commit SHA" )
96
122
parser .add_argument ("--update-charts" , action = "store_true" , help = "Regenerate operator charts" )
97
123
parser .add_argument ("--copy-charts" , action = "store_true" , help = "Copy operator charts" )
98
124
99
- parser .add_argument ("--repo" , help = "Repository name" )
100
- parser .add_argument ("--branch" , default = 'main' , help = "Branch name" )
125
+ parser .add_argument ("--org" , help = "GitHub Org name" )
126
+ parser .add_argument ("--repo" , help = "Github Repo name" )
127
+ parser .add_argument ("--branch" , help = "Github Repo Branch name" )
128
+ parser .add_argument ("--pipeline-repo" , help = "Pipeline Repository name" )
129
+ parser .add_argument ("--pipeline-branch" , help = "Pipeline Repository Branch name" )
130
+
131
+ # Set default values for unspecified arguments
101
132
parser .set_defaults (bundle = False , commit = False , lint = False )
102
133
134
+ # Parse command-line arguments and call the main function
103
135
args = parser .parse_args ()
104
136
main (args )
0 commit comments