-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ACM-11501] Updated shell script for automation (#700)
* updated shell script for automation Signed-off-by: Disaiah Bennett <[email protected]> * Added Github Action job for regenerating oeprator SHA commits Signed-off-by: Disaiah Bennett <[email protected]> --------- Signed-off-by: Disaiah Bennett <[email protected]>
- Loading branch information
Showing
4 changed files
with
197 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
# This is a basic workflow to help you get started with Actions | ||
|
||
name: Regenerate Operator SHAs Commits | ||
|
||
# Controls when the action will run. | ||
on: | ||
# Runs every three hours | ||
schedule: | ||
- cron: "0 */6 * * *" | ||
|
||
# Allows you to run this workflow manually from the Actions tab | ||
workflow_dispatch: | ||
|
||
# A workflow run is made up of one or more jobs that can run sequentially or in parallel | ||
jobs: | ||
# This workflow contains a single job called "build" | ||
build: | ||
# The type of runner that the job will run on | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
python-version: [3.9] | ||
|
||
# Steps represent a sequence of tasks that will be executed as part of the job | ||
steps: | ||
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it | ||
- uses: actions/checkout@v2 | ||
with: | ||
token: ${{ secrets.HUB_OPERATOR_TOKEN }} | ||
- name: Set up Python ${{ matrix.python-version }} | ||
uses: actions/setup-python@v2 | ||
with: | ||
python-version: ${{ matrix.python-version }} | ||
|
||
# Runs a set of commands using the runners shell | ||
- name: Regenerate Operator SHAs Commits | ||
id: generate_sha_commit | ||
run: | | ||
make regenerate-operator-sha-commits | ||
exit_code=$? | ||
if [ $exit_code -ne 0 ]; then | ||
echo "Regenerate Operator SHAs Commit step failed with exit code $exit_code" | ||
exit $exit_code | ||
fi | ||
- name: Send Slack Message on Failure | ||
if: ${{ failure() }} | ||
env: | ||
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} | ||
run: | | ||
SLACK_MESSAGE=":exclamation: *GitHub Actions Job Failed* :exclamation:\n\n" | ||
SLACK_MESSAGE+="Job Name: $GITHUB_WORKFLOW/$GITHUB_JOB\n" | ||
SLACK_MESSAGE+="Job URL: $GITHUB_SERVER_URL/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID\n" | ||
SLACK_MESSAGE+="Error Details: Your job failed. Please check the job logs for more information." | ||
curl -X POST -H "Content-type: application/json" --data "{ | ||
\"text\": \"$SLACK_MESSAGE\" | ||
}" $SLACK_WEBHOOK_URL | ||
- name: Create Pull Request | ||
uses: peter-evans/create-pull-request@v3 | ||
with: | ||
signoff: true | ||
branch: "regenerate-operator-sha-commits" | ||
delete-branch: true | ||
title: "Operator SHAs Commit Update" | ||
committer: GitHub <[email protected]> | ||
author: ${{ github.actor }} <${{ github.actor }}@users.noreply.github.com> | ||
labels: | | ||
do-not-merge/hold | ||
ok-to-test | ||
reviewers: cameronmwall,dislbenn,ngraham20 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,82 @@ | ||
from git import Repo, exc | ||
#!/usr/bin/env python3 | ||
# Copyright (c) 2024 Red Hat, Inc. | ||
# Copyright Contributors to the Open Cluster Management project | ||
# Assumes: Python 3.6+ | ||
|
||
import argparse | ||
import coloredlogs | ||
import os | ||
import logging | ||
import shutil | ||
import time | ||
|
||
from git import Repo, exc | ||
|
||
# Configure logging with coloredlogs | ||
coloredlogs.install(level='DEBUG') # Set the logging level as needed | ||
|
||
def clone_repository(repo_url, repo_path, branch='main'): | ||
if os.path.exists(repo_path): | ||
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.") | ||
|
||
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)) | ||
os.system("python3 " + os.path.dirname(os.path.realpath(__file__)) + f"/{operation_script} {operation_args}") | ||
os.remove(os.path.join(os.path.dirname(os.path.realpath(__file__)), f"{operation_script}")) | ||
|
||
def main(args): | ||
logging.basicConfig(level=logging.INFO) | ||
start_time = time.time() # Record start time | ||
|
||
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/dislbenn/installer-dev-tools.git", repo_path) | ||
script_dir = "tmp/dev-tools/bundle-generation" | ||
|
||
if args.lint_bundles: | ||
logging.info("Preparing to perform linting for bundles...") | ||
operation_script = "generate-bundles.py" | ||
operation_args = "--lint --destination pkg/templates/" | ||
|
||
prepare_operation(script_dir, operation_script, operation_args) | ||
logging.info("Bundles linted successfully.") | ||
|
||
elif args.update_bundles: | ||
logging.info("Preparing to update bundles...") | ||
operation_script = "generate-bundles.py" | ||
operation_args = "--destination pkg/templates/" | ||
|
||
prepare_operation(script_dir, operation_script, operation_args) | ||
logging.info("Bundles updated successfully.") | ||
|
||
elif args.update_commits: | ||
logging.info("Preparing to update commit SHAs...") | ||
operation_script = "generate-sha-commits.py" | ||
operation_args = f"--repo {args.repo} --branch {args.branch}" | ||
|
||
prepare_operation(script_dir, operation_script, operation_args) | ||
logging.info("Commit SHAs updated successfully.") | ||
|
||
else: | ||
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 | ||
|
||
if __name__ == "__main__": | ||
parser = argparse.ArgumentParser() | ||
|
||
parser.add_argument("--lint-bundles", action="store_true", help="Perform linting for operator bundles") | ||
parser.add_argument("--update-bundles", action="store_true", help="Regenerate operator bundles") | ||
parser.add_argument("--update-commits", action="store_true", help="Regenerate operator bundles with commit SHA") | ||
|
||
parser.add_argument("--repo", help="Repository name") | ||
parser.add_argument("--branch", default='main', help="Branch name") | ||
parser.set_defaults(bundle=False, commit=False, lint=False) | ||
|
||
repo_path = os.path.join(os.path.dirname(os.path.realpath(__file__)), "tmp/dev-tools") # Path to clone repo to | ||
if os.path.exists(repo_path): # If path exists, remove and re-clone | ||
shutil.rmtree(repo_path) | ||
repository = Repo.clone_from("https://github.com/stolostron/installer-dev-tools.git", repo_path) # Clone repo to above path | ||
repository.git.checkout('main') # If a branch is specified, checkout that branch | ||
shutil.copy(os.path.join(os.path.dirname(os.path.realpath(__file__)), "tmp/dev-tools/bundle-generation/generate-bundles.py"), os.path.join(os.path.dirname(os.path.realpath(__file__)), "generate-bundles.py")) | ||
os.system("python3 " + os.path.dirname(os.path.realpath(__file__)) + "/generate-bundles.py --destination pkg/templates/") | ||
os.remove(os.path.join(os.path.dirname(os.path.realpath(__file__)), "generate-bundles.py")) | ||
args = parser.parse_args() | ||
main(args) |