-
Notifications
You must be signed in to change notification settings - Fork 279
Feature/rt automation #403
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
junwang-noaa
merged 159 commits into
ufs-community:develop
from
BrianCurtis-NOAA:feature/rt-automation
Feb 25, 2021
Merged
Changes from all commits
Commits
Show all changes
159 commits
Select commit
Hold shift + click to select a range
54b1826
rt automation script
invalid-email-address 9d93b8d
rt automation script w/o token
invalid-email-address f8dfa9f
getting machine name test
invalid-email-address cff8446
Updates to python script, and addition of YAML database
invalid-email-address 89c6248
added check for approved users, added check for triggers in pr comments
invalid-email-address d35e286
Script now interacts with github directly, is able to process triggers
invalid-email-address ad2364f
Merge branch 'develop' into feature/rt-automation
invalid-email-address ed3450f
Added repo clone and submodule functions
invalid-email-address 0b3a691
Merge branch 'develop' into feature/rt-automation
invalid-email-address 84154fe
Added threaded process submition with callback for regression tests
invalid-email-address ab8c83e
Merge branch 'develop' into feature/rt-automation
invalid-email-address 2ba8ec2
remove an extra sys.exit()
BrianCurtis-NOAA cc57e45
Switched to using Labels
BrianCurtis-NOAA a5ecb16
Merge branch 'develop' into feature/rt-automation
BrianCurtis-NOAA 3db3ff2
Rename RegressionTests_hera.intel.log to RegressionTests_neon.intel.log
BrianCurtis-NOAA ce666c5
Rename RegressionTests_neon.intel.log to RegressionTests_hera.intel.log
BrianCurtis-NOAA c588de7
AUTO: Updated tests log
BrianCurtis-NOAA 31f10e5
Test change for repo
BrianCurtis-NOAA 3bbef07
Merge branch 'feature/rt-automation' of https://github.com/BrianCurti…
BrianCurtis-NOAA 239d839
Revert changes for testing
BrianCurtis-NOAA 923c46d
Auto: Added Updated RT Log file: tests/RegressionTests_hera.intel.log
BrianCurtis-NOAA 94d1e73
Auto: Added Updated RT Log file: tests/RegressionTests_hera.intel.log
BrianCurtis-NOAA 61aae99
Auto: Added Updated RT Log file: tests/RegressionTests_hera.intel.log
BrianCurtis-NOAA e3c2931
Auto: Added Updated RT Log file: tests/RegressionTests_hera.intel.log
BrianCurtis-NOAA f47c1ad
Add's ability to retrieve RT logs for PR repo. Moves access token ext…
BrianCurtis-NOAA 1b7c5f4
Merge branch 'feature/rt-automation' of https://github.com/BrianCurti…
BrianCurtis-NOAA 7ffde33
TEST ADDITION HOPEFUL
BrianCurtis-NOAA e32eb4b
Almost done implementing RT log files back to PR, saving files for he…
BrianCurtis-NOAA 9fba3a1
Merge branch 'feature/rt-automation' of https://github.com/BrianCurti…
BrianCurtis-NOAA 34ebb42
Merging develop into feature/rt-automation
BrianCurtis-NOAA 2271450
Updates from 1/12/21-Orion
BrianCurtis-NOAA 981ac9d
Auto: Added Updated RT Log file: tests/RegressionTests_hera.intel.log
BrianCurtis-NOAA b917a08
fix for finding RT log file
BrianCurtis-NOAA 78e4059
Merge branch 'feature/rt-automation' of https://github.com/BrianCurti…
BrianCurtis-NOAA b70bddd
rt hera oops
BrianCurtis-NOAA 7957cce
Auto: Added Updated RT Log file: tests/RegressionTests_hera.intel.log
BrianCurtis-NOAA dfeb1f5
Auto: Added Updated RT Log file: tests/RegressionTests_hera.intel.log
BrianCurtis-NOAA 77fa685
* Temporary test file for running on all machines
BrianCurtis-NOAA 75d7274
Merge branch 'feature/rt-automation' of https://github.com/BrianCurti…
BrianCurtis-NOAA a7e6392
Auto: Added Updated RT Log file: tests/RegressionTests_hera.intel.log
BrianCurtis-NOAA 62e077a
Moving to classes, renaming old rt_auto
BrianCurtis-NOAA f28b763
new file using object oriented coding
BrianCurtis-NOAA 3c5d25d
Auto: Added Updated RT Log file: tests/RegressionTests_hera.intel.log
BrianCurtis-NOAA baea07d
Moved towards OO style, tested on hera successfully
BrianCurtis-NOAA 369b868
Merge branch 'feature/rt-automation' of https://github.com/BrianCurti…
BrianCurtis-NOAA a24d5b5
Need to remove the label once done processing it
BrianCurtis-NOAA 1d2aab2
matched regressiontests hera
BrianCurtis-NOAA 06a4210
Fixed all object names to be explicit
BrianCurtis-NOAA 26dff30
Auto: Added Updated RT Log file: tests/RegressionTests_hera.intel.log
BrianCurtis-NOAA 5b9ac13
Added checks on RT completing before deleting the label on the GH repo
BrianCurtis-NOAA 0256508
IDK why i have to do this, but there's dif in RT hera.intel
BrianCurtis-NOAA ca2c2a3
Test for Brian
BrianCurtis-NOAA 6b63abf
Typo in RT command
BrianCurtis-NOAA 670e58d
Auto: Added Updated RT Log file: tests/RegressionTests_hera.intel.log
BrianCurtis-NOAA 730e7f4
Auto: Added Updated RT Log file: tests/RegressionTests_hera.intel.log
BrianCurtis-NOAA d17ce26
Removes DIR of PR's that don't exist, and removes dir of RT runs
BrianCurtis-NOAA 11ab5fd
Merge branch 'feature/rt-automation' of https://github.com/BrianCurti…
BrianCurtis-NOAA b1e4fe6
Force commit message to default on auto pull
BrianCurtis-NOAA d092abb
Auto: Added Updated RT Log file: tests/RegressionTests_hera.intel.log
BrianCurtis-NOAA 0b686c9
Auto: Added Updated RT Log file: tests/RegressionTests_orion.intel.log
BrianCurtis-NOAA 8efcd19
Merge branch 'feature/rt-automation' of https://github.com/BrianCurti…
BrianCurtis-NOAA adce8f6
Remove dir for specific RT, fix prompt after pull merge
BrianCurtis-NOAA 600198f
Merge branch 'feature/rt-automation' of https://github.com/BrianCurti…
BrianCurtis-NOAA 3cc79ad
Merge from upstream develop
BrianCurtis-NOAA e2443b3
Auto: Added Updated RT Log file: tests/RegressionTests_hera.intel.log
BrianCurtis-NOAA 59e19f9
Moved automated RT code into tests/auto and moved GHUSERNAME into acc…
BrianCurtis-NOAA cd32869
Merge branch 'feature/rt-automation' of https://github.com/BrianCurti…
BrianCurtis-NOAA 3f1ccb8
Auto: Added Updated RT Log file: tests/RegressionTests_hera.intel.log
BrianCurtis-NOAA 4defe5a
Some typos with sleep and bringing in print function from futures in …
BrianCurtis-NOAA f1f8b10
Merge branch 'feature/rt-automation' of https://github.com/BrianCurti…
BrianCurtis-NOAA 370b80b
Auto: Added Updated RT Log file: tests/RegressionTests_gaea.intel.log
e0792c4
Auto: Added Updated RT Log file: tests/RegressionTests_gaea.intel.log
BrianCurtis-NOAA 72a7f0a
don't need to load modulefiles, gaea reg exp check for hostname neede…
BrianCurtis-NOAA 4006342
Merge branch 'feature/rt-automation' of https://github.com/BrianCurti…
BrianCurtis-NOAA 893ee82
Auto: Added Updated RT Log file: tests/RegressionTests_gaea.intel.log
BrianCurtis-NOAA 515471d
Auto: Added Updated RT Log file: tests/RegressionTests_gaea.intel.log
BrianCurtis-NOAA fff2229
Auto: Added Updated RT Log file: tests/RegressionTests_hera.intel.log
BrianCurtis-NOAA 9ba3b4d
Added logger to all functions/classes. Added thread watcher so main()…
BrianCurtis-NOAA 0c363b9
Merge branch 'feature/rt-automation' of https://github.com/BrianCurti…
BrianCurtis-NOAA a4ec205
Auto: Added Updated RT Log file: tests/RegressionTests_gaea.intel.log
BrianCurtis-NOAA f8701bb
Auto: Added Updated RT Log file: tests/RegressionTests_gaea.intel.log
BrianCurtis-NOAA 4bd7304
typo for ACCNR
BrianCurtis-NOAA 1787538
Merge branch 'feature/rt-automation' of https://github.com/BrianCurti…
BrianCurtis-NOAA 4a6ae38
merging with upstream
BrianCurtis-NOAA 20fd5b8
Auto: Added Updated RT Log file: tests/RegressionTests_gaea.intel.log
BrianCurtis-NOAA 7749417
Auto: Added Updated RT Log file: tests/RegressionTests_orion.intel.log
BrianCurtis-NOAA 1e1e080
Merge branch 'feature/rt-automation' of https://github.com/BrianCurti…
BrianCurtis-NOAA f890f46
Auto: Added Updated RT Log file: tests/RegressionTests_gaea.intel.log
BrianCurtis-NOAA 4819bc5
Need extra export for Gaea to work
BrianCurtis-NOAA f967e31
Merge branch 'feature/rt-automation' of https://github.com/BrianCurti…
BrianCurtis-NOAA fe9248d
Bring back the full rt.conf
BrianCurtis-NOAA 41f5abf
Cleanup for PR to ufs-community/ufs-weather-model
BrianCurtis-NOAA 615eb46
Cleanup for PR to ufs-community/ufs-weather-model retry
BrianCurtis-NOAA 9b260b2
Checkout upstream Regression test logs
BrianCurtis-NOAA 9dee224
Delete RegressionTests_neon.intel.log
BrianCurtis-NOAA 0581477
Delete rt.conf.good
BrianCurtis-NOAA 1b73087
Fixed use of sys.exit and instead raise errors, removed sys import, b…
BrianCurtis-NOAA 1f3ae9f
Fixes and temp changes for testing
BrianCurtis-NOAA 2aff54b
Auto: Added Updated RT Log file: tests/RegressionTests_orion.intel.log
BrianCurtis-NOAA f641839
Removed dependency of pandas, added a KeyboardInterrupt catch to repl…
BrianCurtis-NOAA 9bf5469
Bringing back upstream rt.conf and RegressionTest from Orion
BrianCurtis-NOAA 4230e88
typo test fix
BrianCurtis-NOAA 96f8e39
Added more doc strong and removed the need for importing socket
BrianCurtis-NOAA 3dc339b
Merge branch 'feature/rt-automation' of https://github.com/BrianCurti…
BrianCurtis-NOAA 5344add
* Removed need for rt_auto.yml
BrianCurtis-NOAA 6778102
Auto: Added Updated RT Log file: tests/RegressionTests_hera.intel.log
BrianCurtis-NOAA ebc1edc
Auto: Added Updated RT Log file: tests/RegressionTests_hera.intel.log
BrianCurtis-NOAA 58e5255
* Fixed call using string to access callback function
BrianCurtis-NOAA 9735b3b
Merge branch 'feature/rt-automation' of https://github.com/BrianCurti…
BrianCurtis-NOAA 567deb6
Merge w/upstream
BrianCurtis-NOAA 5fe9ad6
rt.conf for testing
BrianCurtis-NOAA fde7d86
Auto: Added Updated RT Log file: tests/RegressionTests_orion.intel.log
BrianCurtis-NOAA c46c38b
Auto: Added Updated RT Log file: tests/RegressionTests_gaea.intel.log
BrianCurtis-NOAA 1e255f2
Merge branch 'feature/rt-automation' of https://github.com/BrianCurti…
BrianCurtis-NOAA 542183b
Bringing back current RegressionTests_* and rt.conf
BrianCurtis-NOAA 0217f9a
Update rt_auto.py
BrianCurtis-NOAA 56f0226
* removed uneeded imports
BrianCurtis-NOAA c48e9b6
Update to help testing cronjob
BrianCurtis-NOAA ce27027
Merging with develop
BrianCurtis-NOAA 7f60f65
Merge branch 'develop' into feature/rt-automation
BrianCurtis-NOAA 0efc765
* Fixes to get crontab run to work
BrianCurtis-NOAA fd5d0df
Auto: Added Updated RT Log file: tests/RegressionTests_hera.intel.log
BrianCurtis-NOAA 9c24b80
Auto: Added Updated RT Log file: tests/RegressionTests_hera.intel.log
BrianCurtis-NOAA 08c4aff
Run rt_auto.py and rt.sh in a login shell
BrianCurtis-NOAA 2b3eee7
Merge branch 'feature/rt-automation' of https://github.com/BrianCurti…
BrianCurtis-NOAA 6d2c032
Auto: Added Updated RT Log file: tests/RegressionTests_orion.intel.log
BrianCurtis-NOAA 42bfb7e
Auto: Added Updated RT Log file: tests/RegressionTests_gaea.intel.log
BrianCurtis-NOAA eb59dc6
Merge branch 'feature/rt-automation' of https://github.com/BrianCurti…
BrianCurtis-NOAA 578aa0a
Auto: Added Updated RT Log file: tests/RegressionTests_hera.intel.log
BrianCurtis-NOAA 588fe3d
Auto: Added Updated RT Log file: tests/RegressionTests_hera.intel.log
BrianCurtis-NOAA d93c8db
Auto: Added Updated RT Log file: tests/RegressionTests_hera.intel.log
BrianCurtis-NOAA 1b4df6a
Auto: adding rt_auto.log
BrianCurtis-NOAA 998f87d
Auto: Added Updated RT Log file: tests/RegressionTests_hera.intel.log
BrianCurtis-NOAA 2340211
* log level to info by default, never save debug to repo
BrianCurtis-NOAA f38dfcc
Merge branch 'feature/rt-automation' of https://github.com/BrianCurti…
BrianCurtis-NOAA 3a276e1
Auto: Added Updated RT Log file: tests/RegressionTests_hera.intel.log
BrianCurtis-NOAA 6af87be
Auto: adding rt_auto.log
BrianCurtis-NOAA fc3ea94
* Removed the need to log the API Token.
BrianCurtis-NOAA b2e8f26
Merge branch 'feature/rt-automation' of https://github.com/BrianCurti…
BrianCurtis-NOAA 931a701
* removed an extra log
BrianCurtis-NOAA 3405c9d
* get rid of extra commented out code
BrianCurtis-NOAA 68a5def
Auto: Added Updated RT Log file: tests/RegressionTests_gaea.intel.log
BrianCurtis-NOAA 1703e15
Auto: Added Updated RT Log file: tests/RegressionTests_orion.intel.log
BrianCurtis-NOAA 9a544f3
Merge branch 'feature/rt-automation' of https://github.com/BrianCurti…
BrianCurtis-NOAA 6efe04c
Auto: Added Updated RT Log file: tests/RegressionTests_hera.intel.log
BrianCurtis-NOAA 413c35a
Merge branch 'feature/rt-automation' of https://github.com/BrianCurti…
BrianCurtis-NOAA 55026e9
Jet Regression Test
BrianCurtis-NOAA a7c11bd
Merge branch 'feature/rt-automation' of https://github.com/BrianCurti…
BrianCurtis-NOAA aa8cb88
* Logs renamed and saved for a max one month.
BrianCurtis-NOAA 44f35f7
Merge branch 'feature/rt-automation' of https://github.com/BrianCurti…
BrianCurtis-NOAA c0e52cc
* typo fixes
BrianCurtis-NOAA 3dc3811
Auto: Added Updated RT Log file: tests/RegressionTests_hera.intel.log
BrianCurtis-NOAA 24eb8b7
hera.gnu log
BrianCurtis-NOAA 1d8b9a3
Merge branch 'feature/rt-automation' of https://github.com/BrianCurti…
BrianCurtis-NOAA 017aec1
WCoss Dell P3 Logs
14def7e
WCoss_Cray log
BrianCurtis-NOAA 0df4069
Filename change in rm_command to match filename generated
BrianCurtis-NOAA 06f96e2
Merge from develop and using RT logs from upstream
BrianCurtis-NOAA 0034991
Jet Python Path Updated
BrianCurtis-NOAA File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,316 @@ | ||
| """Automation of UFS Regression Testing | ||
|
|
||
| This script automates the process of UFS regression testing for code managers | ||
| at NOAA-EMC | ||
|
|
||
| This script should be started through rt_auto.sh so that env vars are set up | ||
| prior to start. | ||
| """ | ||
| from __future__ import print_function | ||
| from github import Github as gh | ||
| import argparse | ||
| import datetime | ||
| import subprocess | ||
| import re | ||
| import os | ||
| import logging | ||
|
|
||
| class GHInterface: | ||
| ''' | ||
| This class stores information for communicating with GitHub | ||
| ... | ||
|
|
||
| Attributes | ||
| ---------- | ||
| GHACCESSTOKEN : str | ||
| API token to autheticate with GitHub | ||
| client : pyGitHub communication object | ||
| The connection to GitHub to make API requests | ||
| ''' | ||
| def __init__(self): | ||
| self.logger = logging.getLogger('GHINTERFACE') | ||
| try: | ||
| self.client = gh(os.getenv('ghapitoken')) | ||
| except Exception as e: | ||
| self.logger.critical(f'Exception is {e}') | ||
| raise(e) | ||
|
|
||
| def parse_args_in(): | ||
| ''' Parse all input arguments coming from rt_auto.sh ''' | ||
| logger = logging.getLogger('PARSE_ARGS_IN') | ||
| # Create Parse | ||
| parser = argparse.ArgumentParser() | ||
|
|
||
| # Setup Input Arguments | ||
| choices = ['hera.intel', 'orion.intel', 'gaea.intel', 'jet.intel', 'wcoss_dell_p3'] | ||
| parser.add_argument('-m', '--machine', help='Machine and Compiler combination', required=True, choices=choices, type=str) | ||
| parser.add_argument('-w', '--workdir', help='Working directory', required=True, type=str) | ||
|
|
||
| # Get Arguments | ||
| args = parser.parse_args() | ||
|
|
||
| return args | ||
|
|
||
| def input_data(args): | ||
| ''' Create dictionaries of data needed for processing UFS pull requests ''' | ||
| logger = logging.getLogger('INPUT_DATA') | ||
| machine_dict = { | ||
| 'name': args.machine, | ||
| 'workdir': args.workdir | ||
| } | ||
| repo_list_dict = [{ | ||
| 'name': 'ufs-weather-model', | ||
| 'address': 'ufs-community/ufs-weather-model', | ||
| 'base': 'develop' | ||
| }] | ||
| action_list_dict = [{ | ||
| 'name': 'RT', | ||
| 'command': 'cd tests && /bin/bash --login ./rt.sh -e', | ||
| 'callback_fnc': 'move_rt_logs' | ||
| }] | ||
|
|
||
| return machine_dict, repo_list_dict, action_list_dict | ||
|
|
||
| def match_label_with_action(machine, actions, label): | ||
| ''' Match the label that initiates a job with an action in the dict''' | ||
| logger = logging.getLogger('MATCH_LABEL_WITH_ACTIONS') | ||
| split_label = label.name.split('-') | ||
|
|
||
| if len(split_label) != 3: return False | ||
| if not re.match(split_label[0], 'Auto'): return False | ||
| if not re.match(split_label[2], machine['name'].split('.')[0]): return False | ||
| action_match = next((action for action in actions if re.match(action['name'], split_label[1])), False) | ||
|
|
||
| return action_match | ||
|
|
||
|
|
||
| def get_preqs_with_actions(repos, machine, ghinterface_obj, actions): | ||
| ''' Create list of dictionaries of a pull request and its machine label and action ''' | ||
| logger = logging.getLogger('GET_PREQS_WITH_ACTIONS') | ||
| gh_preqs = [ghinterface_obj.client.get_repo(repo['address']).get_pulls(state='open', sort='created', base=repo['base']) for repo in repos] | ||
| each_pr = [preq for gh_preq in gh_preqs for preq in gh_preq] | ||
| preq_labels = [{'preq': pr, 'label': label} for pr in each_pr for label in pr.get_labels()] | ||
|
|
||
| for i, pr_label in enumerate(preq_labels): | ||
| match = match_label_with_action(machine, actions, pr_label['label']) | ||
| if match: | ||
| preq_labels[i]['action'] = match | ||
| else: | ||
| preq_labels[i] = False | ||
|
|
||
| preq_dict = [x for x in preq_labels if x] | ||
|
|
||
| return preq_dict | ||
|
|
||
| class Job: | ||
| ''' | ||
| This class stores all information needed to run jobs on this machine. | ||
| This class provides all methods needed to run all jobs. | ||
| ... | ||
|
|
||
| Attributes | ||
| ---------- | ||
| preq_dict: dict | ||
| Dictionary of all data that comes from the GitHub pull request | ||
| ghinterface_obj: object | ||
| An interface to GitHub setup through class GHInterface | ||
| machine: dict | ||
| Information about the machine the jobs will be running on | ||
| provided by the bash script | ||
| ''' | ||
|
|
||
| def __init__(self, preq_dict, ghinterface_obj, machine): | ||
| self.logger = logging.getLogger('JOB') | ||
| self.preq_dict = preq_dict | ||
| self.ghinterface_obj = ghinterface_obj | ||
| self.machine = machine | ||
|
|
||
| def remove_pr_label(self): | ||
| ''' Removes the pull request label that initiated the job run from PR ''' | ||
| self.logger.info(f'Removing Label: {self.preq_dict["label"]}') | ||
| self.preq_dict['preq'].remove_from_labels(self.preq_dict['label']) | ||
|
|
||
| def send_log_name_as_comment(self): | ||
| logger = logging.getLogger('JOB/SEND_LOG_NAME_AS_COMMENT') | ||
| logger.info('Removing last months logs (if any)') | ||
| last_month = datetime.date.today().replace(day=1) - datetime.timedelta(days=1) | ||
| rm_command = [[f'rm rt_auto_*_{last_month.strftime("%Y%m")}*.log', os.getcwd()]] | ||
| logger.info(f'Running "{rm_command}"') | ||
| try: | ||
| self.run_commands(rm_command) | ||
| except Exception as e: | ||
| logger.warning(f'"{rm_command}" failed with error:{e}') | ||
|
|
||
| new_log_name = f'rt_auto_{self.machine["name"]}_'\ | ||
| f'{datetime.datetime.now().strftime("%Y%m%d%H%M%S")}.log' | ||
| cp_command = [[f'cp rt_auto.log {new_log_name}', os.getcwd()]] | ||
| logger.info(f'Running "{cp_command}"') | ||
| try: | ||
| self.run_commands(cp_command) | ||
| except Exception as e: | ||
| logger.warning('Renaming rt_auto failed') | ||
| else: | ||
| comment_text = f'Log Name:{new_log_name}\n'\ | ||
| f'Log Location:{os.getcwd()}\n'\ | ||
| 'Logs are kept for one month' | ||
| try: | ||
| self.preq_dict['preq'].create_issue_comment(comment_text) | ||
| except Exception as e: | ||
| logger.warning('Creating comment with log location failed with:{e}') | ||
| else: | ||
| logger.info(f'{comment_text}') | ||
|
|
||
| def run_commands(self, commands_with_cwd): | ||
| logger = logging.getLogger('JOB/RUN_COMMANDS') | ||
| for command, in_cwd in commands_with_cwd: | ||
| logger.info(f'Running "{command}" in location "{in_cwd}"') | ||
| try: | ||
| output = subprocess.Popen(command, shell=True, cwd=in_cwd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) | ||
| out, err = output.communicate() | ||
| out = [] if not out else out.decode('utf8').split('\n') | ||
| err = [] if not err else err.decode('utf8').split('\n') | ||
| except Exception as e: | ||
| logger.critical(e) | ||
| [logger.critical(f'stdout: {item}') for item in out if not None] | ||
| [logger.critical(f'stderr: {eitem}') for eitem in err if not None] | ||
| assert(e) | ||
| else: | ||
| logger.info(f'Finished running: {command}') | ||
| [logger.debug(f'stdout: {item}') for item in out if not None] | ||
| [logger.debug(f'stderr: {eitem}') for eitem in err if not None] | ||
|
|
||
| def remove_pr_dir(self): | ||
| logger = logging.getLogger('JOB/REMOVE_PR_DIR') | ||
| pr_dir_str = f'{self.machine["workdir"]}/{str(self.preq_dict["preq"].id)}' | ||
| rm_command = [[f'rm -rf {pr_dir_str}', self.pr_repo_loc]] | ||
| logger.info(f'Running "{rm_command}"') | ||
| self.run_commands(rm_command) | ||
|
|
||
| def clone_pr_repo(self): | ||
| ''' clone the GitHub pull request repo, via command line ''' | ||
| logger = logging.getLogger('JOB/CLONE_PR_REPO') | ||
| repo_name = self.preq_dict['preq'].head.repo.name | ||
| self.branch = self.preq_dict['preq'].head.ref | ||
| git_url = self.preq_dict['preq'].head.repo.html_url.split('//') | ||
| git_url = f'{git_url[0]}//${{ghapitoken}}@{git_url[1]}' | ||
| logger.info(f'GIT URL: {git_url}') | ||
| logger.info('Starting repo clone') | ||
| repo_dir_str = f'{self.machine["workdir"]}/{str(self.preq_dict["preq"].id)}/{datetime.datetime.now().strftime("%Y%m%d%H%M%S")}' | ||
|
|
||
| create_repo_commands = [ | ||
| [f'mkdir -p "{repo_dir_str}"', self.machine['workdir']], | ||
| [f'git clone -b {self.branch} {git_url}', repo_dir_str], | ||
| [f'git submodule update --init --recursive', f'{repo_dir_str}/{repo_name}'] | ||
| ] | ||
|
|
||
| self.run_commands(create_repo_commands) | ||
|
|
||
| logger.info('Finished repo clone') | ||
| self.pr_repo_loc = repo_dir_str+"/"+repo_name | ||
| return self.pr_repo_loc | ||
|
|
||
| def run_function(self): | ||
| ''' Run the command associted with the label used to initiate this job ''' | ||
| logger = logging.getLogger('JOB/RUN_FUNCTION') | ||
| try: | ||
| logger.info(f'Running: "{self.preq_dict["action"]["command"]}" in "{self.pr_repo_loc}"') | ||
| output = subprocess.Popen(self.preq_dict['action']['command'], cwd=self.pr_repo_loc, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) | ||
| out,err = output.communicate() | ||
| out = [] if not out else out.decode('utf8').split('\n') | ||
| err = [] if not err else err.decode('utf8').split('\n') | ||
| except Exception as e: | ||
| logger.critical(e) | ||
| [logger.critical(f'stdout: {item}') for item in out if not None] | ||
| [logger.critical(f'stderr: {eitem}') for eitem in err if not None] | ||
| assert(e) | ||
| else: | ||
| if output.returncode != 0: | ||
| logger.critical(f'{self.preq_dict["action"]["command"]} Failed') | ||
| [logger.critical(f'stdout: {item}') for item in out if not None] | ||
| [logger.critical(f'stderr: {eitem}') for eitem in err if not None] | ||
| else: | ||
| try: | ||
| logger.info(f'Attempting to run callback: {self.preq_dict["action"]["callback_fnc"]}') | ||
| getattr(self, self.preq_dict['action']['callback_fnc'])() | ||
| except Exception as e: | ||
| logger.critical(f'Callback function {self.preq_dict["action"]["callback_fnc"]} failed with "{e}"') | ||
| goodexit = False | ||
| assert(e) | ||
| else: | ||
| logger.info(f'Finished callback {self.preq_dict["action"]["callback_fnc"]}') | ||
| [logger.debug(f'stdout: {item}') for item in out if not None] | ||
| [logger.debug(f'stderr: {eitem}') for eitem in err if not None] | ||
|
|
||
| # Add Callback Functions After Here | ||
| def move_rt_logs(self): | ||
| ''' This is the callback function associated with the "RT" command ''' | ||
| logger = logging.getLogger('JOB/MOVE_RT_LOGS') | ||
| rt_log = f'tests/RegressionTests_{self.machine["name"]}.log' | ||
| filepath = f'{self.pr_repo_loc}/{rt_log}' | ||
| rm_filepath = '/'.join((self.pr_repo_loc.split('/'))[:-1]) | ||
| if os.path.exists(filepath): | ||
| move_rt_commands = [ | ||
| [f'git add {rt_log}', self.pr_repo_loc], | ||
| [f'git commit -m "Auto: Added Updated RT Log file: {rt_log}"', self.pr_repo_loc], | ||
| [f'git pull --no-edit origin {self.branch}', self.pr_repo_loc], | ||
| ['sleep 10', self.pr_repo_loc], | ||
| [f'git push origin {self.branch}', self.pr_repo_loc] | ||
| ] | ||
| self.run_commands(move_rt_commands) | ||
|
|
||
| else: | ||
| logger.critical('Could not find RT log') | ||
| raise FileNotFoundError('Could not find RT log') | ||
|
|
||
| def main(): | ||
|
|
||
| # handle logging | ||
| log_path = os.getcwd() | ||
| log_filename = 'rt_auto.log' | ||
| # Please don't run the following on cron with level=logging.DEBUG | ||
| # as it exposes the GH API Token | ||
| # Only set it to DEBUG while debugging | ||
| logging.basicConfig(filename=log_filename, filemode='w', level=logging.INFO) | ||
| logger = logging.getLogger('MAIN') | ||
| logger.info('Starting Script') | ||
| # handle input args | ||
| logger.info('Parsing input args') | ||
| args = parse_args_in() | ||
|
|
||
| # get input data | ||
| logger.info('Calling input_data().') | ||
| machine, repos, actions = input_data(args) | ||
|
|
||
| # setup interface with GitHub | ||
| logger.info('Setting up GitHub interface.') | ||
| ghinterface_obj = GHInterface() | ||
|
|
||
| # get all pull requests from the GitHub object | ||
| logger.info('Getting all pull requests, labels and actions applicable to this machine.') | ||
| preq_dict = get_preqs_with_actions(repos, machine, ghinterface_obj, actions) | ||
|
|
||
| # add Job objects and run them | ||
| logger.info('Adding all jobs to an object list and running them.') | ||
| jobs = [Job(pullreq, ghinterface_obj, machine) for pullreq in preq_dict] | ||
| for job in jobs: | ||
| logger.info(f'Starting Job: {job}') | ||
| try: | ||
| logger.info('Calling remove_pr_label') | ||
| job.remove_pr_label() | ||
| logger.info('Calling clone_pr_repo') | ||
| job.clone_pr_repo() | ||
| logger.info('Calling run_function') | ||
| job.run_function() | ||
| logger.info('Calling remove_pr_dir') | ||
| job.remove_pr_dir() | ||
| logger.info('Calling send_log_name_as_comment') | ||
| job.send_log_name_as_comment() | ||
| except Exception as e: | ||
| logger.critical(e) | ||
| assert(e) | ||
|
|
||
| logger.info('Script Finished') | ||
|
|
||
|
|
||
| if __name__ == '__main__': | ||
| main() |
This file contains hidden or 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,45 @@ | ||
| #!/bin/bash --login | ||
| set -eux | ||
| if [ -f "accesstoken.sh" ]; then | ||
| source ./accesstoken.sh | ||
| else | ||
| echo "Please create accesstoken.sh (600) with the following content\n" | ||
| echo "export ghapitoken=<GitHub API Token Here>" | ||
| exit 1 | ||
| fi | ||
|
|
||
| export RT_COMPILER='intel' | ||
| source ../detect_machine.sh | ||
| echo "Machine ID: "+$MACHINE_ID | ||
| if [[ $MACHINE_ID = hera.* ]]; then | ||
| WORKDIR=/scratch1/NCEPDEV/nems/Brian.Curtis/test | ||
| export PATH=/scratch1/NCEPDEV/nems/emc.nemspara/soft/miniconda3/bin:$PATH | ||
| export PYTHONPATH=/scratch1/NCEPDEV/nems/emc.nemspara/soft/miniconda3/lib/python3.8/site-packages | ||
| elif [[ $MACHINE_ID = orion.* ]]; then | ||
| WORKDIR=/work/noaa/nems/bcurtis/test | ||
| export PATH=/work/noaa/nems/emc.nemspara/soft/miniconda3/bin:$PATH | ||
| export PYTHONPATH=/work/noaa/nems/emc.nemspara/soft/miniconda3/lib/python3.8/site-packages | ||
| elif [[ $MACHINE_ID = jet.* ]]; then | ||
| WORKDIR=/lfs4/HFIP/h-nems/Brian.Curtis/test | ||
| export ACCNR="h-nems" | ||
| export PATH=/lfs4/HFIP/hfv3gfs/software/miniconda3/4.8.3/envs/ufs-weather-model/bin:/lfs4/HFIP/hfv3gfs/software/miniconda3/4.8.3/bin:$PATH | ||
| export PYTHONPATH=/lfs4/HFIP/hfv3gfs/software/miniconda3/4.8.3/envs/ufs-weather-model/lib/python3.8/site-packages:/lfs4/HFIP/hfv3gfs/software/miniconda3/4.8.3/lib/python3.8/site-packages | ||
| elif [[ $MACHINE_ID = gaea.* ]]; then | ||
| WORKDIR=/lustre/f2/pdata/ncep/Brian.Curtis/test | ||
| export LOADEDMODULES=$LOADEDMODULES | ||
| export ACCNR="nggps_emc" # This applies to Brian.Curtis, may need change later | ||
| export PATH=/lustre/f2/pdata/esrl/gsd/contrib/miniconda3/4.8.3/envs/ufs-weather-model/bin:$PATH | ||
| export PYTHONPATH=/lustre/f2/pdata/esrl/gsd/contrib/miniconda3/4.8.3/lib/python3.8/site-packages | ||
| elif [[ $MACHINE_ID = cheyenne.* ]]; then | ||
|
BrianCurtis-NOAA marked this conversation as resolved.
|
||
| #export PATH=/glade/p/ral/jntp/tools/ecFlow-5.3.1/bin:$PATH | ||
| #export PYTHONPATH=/glade/p/ral/jntp/tools/ecFlow-5.3.1/lib/python2.7/site-packages | ||
| echo "cheyenne not currently supported. automated RT not starting" | ||
| exit 1 | ||
| else | ||
| echo "No Python Path for this machine. automated RT not starting" | ||
| exit 1 | ||
| fi | ||
|
|
||
| python rt_auto.py -m $MACHINE_ID -w $WORKDIR | ||
|
|
||
| exit 0 | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.