Skip to content

Commit 313b9d6

Browse files
authored
Updated shell script for automation (stolostron#1765)
* updated shell script for automation Signed-off-by: dislbenn <dbennett@redhat.com> * updated makefile linting command Signed-off-by: dislbenn <dbennett@redhat.com> --------- Signed-off-by: dislbenn <dbennett@redhat.com>
1 parent ec5edb7 commit 313b9d6

File tree

2 files changed

+67
-28
lines changed

2 files changed

+67
-28
lines changed

Makefile.dev

+12-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
# Copyright Contributors to the Open Cluster Management project
22

3+
ORG ?= stolostron
4+
REPO ?= installer-dev-tools
5+
BRANCH ?= main
6+
7+
PIPELINE_REPO ?= pipeline
8+
PIPELINE_BRANCH ?= 2.12-integration
9+
310
.PHONY: update-manifest
411

512
deps:
@@ -28,23 +35,23 @@ prep-mock-install:
2835

2936
lint-operator-bundles: ## Lints the operator bundles
3037
pip3 install -r hack/bundle-automation/requirements.txt
31-
python3 ./hack/bundle-automation/generate-shell.py --lint-bundles
38+
python3 ./hack/bundle-automation/generate-shell.py --lint-bundles --org $(ORG) --repo $(REPO) --branch $(BRANCH)
3239

3340
regenerate-charts-from-bundles: ## Regenerates the operator charts from bundles
3441
pip3 install -r hack/bundle-automation/requirements.txt
35-
python3 ./hack/bundle-automation/generate-shell.py --update-charts-from-bundles
42+
python3 ./hack/bundle-automation/generate-shell.py --update-charts-from-bundles --org $(ORG) --repo $(REPO) --branch $(BRANCH)
3643

3744
regenerate-operator-sha-commits: ## Regenerates the operator bundles
3845
pip3 install -r hack/bundle-automation/requirements.txt
39-
python3 ./hack/bundle-automation/generate-shell.py --update-commits --repo pipeline --branch 2.12-integration
46+
python3 ./hack/bundle-automation/generate-shell.py --update-commits --org $(ORG) --repo $(REPO) --branch $(BRANCH) --pipeline-repo $(PIPELINE_REPO) --pipeline-branch $(PIPELINE_BRANCH)
4047

4148
regenerate-charts: ## Regenerates the charts
4249
pip3 install -r hack/bundle-automation/chart-requirements.txt
43-
python3 ./hack/bundle-automation/generate-shell.py --update-charts
50+
python3 ./hack/bundle-automation/generate-shell.py --update-charts --org $(ORG) --repo $(REPO) --branch $(BRANCH)
4451

4552
copy-charts: ## Regenerates the operator bundles
4653
pip3 install -r hack/bundle-automation/requirements.txt
47-
python3 ./hack/bundle-automation/generate-shell.py --copy-charts
54+
python3 ./hack/bundle-automation/generate-shell.py --copy-charts --org $(ORG) --repo $(REPO) --branch $(BRANCH)
4855

4956
# different from `in-cluster-install` (call no secrets, no observability-crd)
5057
mock-install: prereqs subscriptions docker-build docker-push deploy

hack/bundle-automation/generate-shell.py

+55-23
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,20 @@
1616
# Configure logging with coloredlogs
1717
coloredlogs.install(level='DEBUG') # Set the logging level as needed
1818

19-
def clone_repository(repo_url, repo_path, branch='main'):
19+
def clone_repository(git_url, repo_path, branch):
2020
if os.path.exists(repo_path):
21+
logging.warning(f"Repository path: {repo_path} already exists. Removing existing directory.")
2122
shutil.rmtree(repo_path)
22-
logging.info(f"Cloning repository from {repo_url} to {repo_path}...")
2323

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
2733

2834
def prepare_operation(script_dir, operation_script, operation_args):
2935
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):
3541

3642
def main(args):
3743
logging.basicConfig(level=logging.INFO)
44+
3845
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
3955

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
4264
script_dir = "tmp/dev-tools/bundle-generation"
4365

66+
# Check which operation is requested based on command-line arguments
4467
if args.lint_bundles:
45-
logging.info("Preparing to perform linting for bundles...")
68+
logging.info("Starting linting for bundles...")
4669
operation_script = "bundles-to-charts.py"
4770
operation_args = "--lint --destination pkg/templates/"
4871

4972
prepare_operation(script_dir, operation_script, operation_args)
50-
logging.info("Bundles linted successfully.")
73+
logging.info("✔️ Bundles linted successfully.")
5174

5275
elif args.update_charts_from_bundles:
53-
logging.info("Preparing to update operator charts from bundles...")
76+
logging.info("Updating operator charts from bundles...")
5477
operation_script = "bundles-to-charts.py"
5578
operation_args = "--destination pkg/templates/"
5679

5780
prepare_operation(script_dir, operation_script, operation_args)
58-
logging.info("Bundles updated successfully.")
81+
logging.info("✔️ Bundles updated successfully.")
5982

6083
elif args.update_charts:
61-
logging.info("Preparing to update operator...")
84+
logging.info("Updating operator charts...")
6285
operation_script = "generate-charts.py"
6386
operation_args = "--destination pkg/templates/"
6487

6588
prepare_operation(script_dir, operation_script, operation_args)
66-
logging.info("Bundles updated successfully.")
89+
logging.info("✔️ Bundles updated successfully.")
6790

6891
elif args.copy_charts:
69-
logging.info("Preparing to copy charts...")
92+
logging.info("Copying charts...")
7093
operation_script = "move-charts.py"
7194
operation_args = "--destination pkg/templates/"
7295

7396
prepare_operation(script_dir, operation_script, operation_args)
74-
logging.info("Bundles updated successfully.")
97+
logging.info("✔️ Bundles updated successfully.")
7598

7699
elif args.update_commits:
77-
logging.info("Preparing to update commit SHAs...")
100+
logging.info("Updating commit SHAs...")
78101
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}"
80103

81104
prepare_operation(script_dir, operation_script, operation_args)
82-
logging.info("Commit SHAs updated successfully.")
105+
logging.info("✔️ Commit SHAs updated successfully.")
83106

84107
else:
85-
logging.warning("No operation specified.")
108+
logging.warning("⚠️ No operation specified.")
86109

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.")
89113

90114
if __name__ == "__main__":
115+
# Set up argument parsing for command-line execution
91116
parser = argparse.ArgumentParser()
92117

118+
# Define command-line arguments and their help descriptions
93119
parser.add_argument("--lint-bundles", action="store_true", help="Perform linting for operator bundles")
94120
parser.add_argument("--update-charts-from-bundles", action="store_true", help="Regenerate operator charts from bundles")
95121
parser.add_argument("--update-commits", action="store_true", help="Regenerate operator bundles with commit SHA")
96122
parser.add_argument("--update-charts", action="store_true", help="Regenerate operator charts")
97123
parser.add_argument("--copy-charts", action="store_true", help="Copy operator charts")
98124

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
101132
parser.set_defaults(bundle=False, commit=False, lint=False)
102133

134+
# Parse command-line arguments and call the main function
103135
args = parser.parse_args()
104136
main(args)

0 commit comments

Comments
 (0)