Skip to content

Commit

Permalink
updated shell script for automation (#1003)
Browse files Browse the repository at this point in the history
Signed-off-by: dislbenn <[email protected]>
  • Loading branch information
dislbenn authored Oct 9, 2024
1 parent 22c14bd commit 18618ce
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 29 deletions.
15 changes: 11 additions & 4 deletions Makefile.dev
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
# Copyright Contributors to the Open Cluster Management project

ORG ?= stolostron
REPO ?= installer-dev-tools
BRANCH ?= main

PIPELINE_REPO ?= backplane-pipeline
PIPELINE_BRANCH ?= 2.7-integration

.PHONY: subscriptions

Expand All @@ -21,19 +28,19 @@ upstream-install: ## Installs the upstream Backplane Operator by deploying a Cat

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

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

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

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

catalog-deploy: ## Deploys backplane operator via subscription
IMG="${IMAGE_TAG_BASE}-catalog:v${VERSION}" yq eval -i '.spec.image = env(IMG)' hack/catalog/catalogsource.yaml
Expand Down
82 changes: 57 additions & 25 deletions hack/bundle-automation/generate-shell.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,20 @@
# Configure logging with coloredlogs
coloredlogs.install(level='DEBUG') # Set the logging level as needed

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

repository = Repo.clone_from(repo_url, repo_path)
repository.git.checkout(branch)
logging.info("Repository cloned successfully.")
logging.info(f"Cloning Git repository: {git_url} (branch={branch}) to {repo_path}")
try:
repository = Repo.clone_from(git_url, repo_path)
repository.git.checkout(branch)
logging.info(f"Git repository: {git_url} successfully cloned.")

except Exception as e:
logging.error(f"Failed to clone Git repository: {git_url} (branch={branch}): {e}.")
raise

def prepare_operation(script_dir, operation_script, operation_args):
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))
Expand All @@ -35,70 +41,96 @@ def prepare_operation(script_dir, operation_script, operation_args):

def main(args):
logging.basicConfig(level=logging.INFO)

start_time = time.time() # Record start time
logging.info("🔄 Initiating the generate-shell script for operator bundle management and updates.")

# Extract org, repo, branch, pipeline_repo, and pipeline_branch from command-line arguments
# Use the specified org and branch or the defaults ('stolostron', 'installer-dev-tools', 'main', 'bacplane-pipeline', '2.7-integration')
org = args.org
repo = args.repo
branch = args.branch
pipeline_repo = args.pipeline_repo
pipeline_branch = args.pipeline_branch

# Define the destination path for the cloned repository
repo_path = os.path.join(os.path.dirname(os.path.realpath(__file__)), "tmp/dev-tools")

repo_path = os.path.join(os.path.dirname(os.path.realpath(__file__)), "tmp/dev-tools") # Destination path for cloned repository.
clone_repository("https://github.com/stolostron/installer-dev-tools.git", repo_path)
# Clone the repository using the specified git_url, destination path, and branch
git_url = f"https://github.com/{org}/{repo}.git"
clone_repository(git_url, repo_path, branch)

# Define the directory containing the bundle generation scripts
script_dir = "tmp/dev-tools/bundle-generation"

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

prepare_operation(script_dir, operation_script, operation_args)
logging.info("Bundles linted successfully.")
logging.info("✔️ Bundles linted successfully.")

elif args.update_charts_from_bundles:
logging.info("Preparing to update operator charts from bundles...")
logging.info("Updating operator charts from bundles...")
operation_script = "bundles-to-charts.py"
operation_args = "--destination pkg/templates/"

prepare_operation(script_dir, operation_script, operation_args)
logging.info("Bundles updated successfully.")
logging.info("✔️ Bundles updated successfully.")

elif args.update_charts:
logging.info("Preparing to update operator...")
logging.info("Updating operator charts...")
operation_script = "generate-charts.py"
operation_args = "--destination pkg/templates/"

prepare_operation(script_dir, operation_script, operation_args)
logging.info("Bundles updated successfully.")
logging.info("✔️ Bundles updated successfully.")

elif args.copy_charts:
logging.info("Preparing to copy charts...")
logging.info("Copying charts...")
operation_script = "move-charts.py"
operation_args = "--destination pkg/templates/"

prepare_operation(script_dir, operation_script, operation_args)
logging.info("Bundles updated successfully.")
logging.info("✔️ Bundles updated successfully.")

elif args.update_commits:
logging.info("Preparing to update commit SHAs...")
logging.info("Updating commit SHAs...")
operation_script = "generate-sha-commits.py"
operation_args = f"--repo {args.repo} --branch {args.branch}"
operation_args = f"--repo {pipeline_repo} --branch {pipeline_branch}"

prepare_operation(script_dir, operation_script, operation_args)
logging.info("Commit SHAs updated successfully.")
logging.info("✔️ Commit SHAs updated successfully.")

else:
logging.warning("No operation specified.")
logging.warning("⚠️ No operation specified.")

end_time = time.time() # Record end time
logging.info(f"Script execution took {end_time - start_time:.2f} seconds.") # Log duration
# Record the end time and log the duration of the script execution
end_time = time.time()
logging.info(f"Script execution took {end_time - start_time:.2f} seconds.")

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

parser.add_argument("--copy-charts", action="store_true", help="Copy operator charts from source repository")
# Define command-line arguments and their help descriptions
parser.add_argument("--lint-bundles", action="store_true", help="Perform linting for operator bundles")
parser.add_argument("--update-charts-from-bundles", action="store_true", help="Regenerate operator charts from bundles")
parser.add_argument("--update-charts", action="store_true", help="Regenerate operator charts")
parser.add_argument("--update-commits", action="store_true", help="Regenerate operator bundles with commit SHA")
parser.add_argument("--update-charts", action="store_true", help="Regenerate operator charts")
parser.add_argument("--copy-charts", action="store_true", help="Copy operator charts")

parser.add_argument("--org", help="GitHub Org name")
parser.add_argument("--repo", help="Github Repo name")
parser.add_argument("--branch", help="Github Repo Branch name")
parser.add_argument("--pipeline-repo", help="Pipeline Repository name")
parser.add_argument("--pipeline-branch", help="Pipeline Repository Branch name")

parser.add_argument("--repo", help="Repository name")
parser.add_argument("--branch", default='main', help="Branch name")
# Set default values for unspecified arguments
parser.set_defaults(bundle=False, commit=False, lint=False)

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

0 comments on commit 18618ce

Please sign in to comment.