Skip to content
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

Feature/rt automation #403

Merged
Merged
Show file tree
Hide file tree
Changes from 148 commits
Commits
Show all changes
159 commits
Select commit Hold shift + click to select a range
54b1826
rt automation script
invalid-email-address Nov 23, 2020
9d93b8d
rt automation script w/o token
invalid-email-address Nov 23, 2020
f8dfa9f
getting machine name test
invalid-email-address Nov 23, 2020
cff8446
Updates to python script, and addition of YAML database
invalid-email-address Nov 24, 2020
89c6248
added check for approved users, added check for triggers in pr comments
invalid-email-address Nov 25, 2020
d35e286
Script now interacts with github directly, is able to process triggers
invalid-email-address Dec 7, 2020
ad2364f
Merge branch 'develop' into feature/rt-automation
invalid-email-address Dec 7, 2020
ed3450f
Added repo clone and submodule functions
invalid-email-address Dec 14, 2020
0b3a691
Merge branch 'develop' into feature/rt-automation
invalid-email-address Dec 15, 2020
84154fe
Added threaded process submition with callback for regression tests
invalid-email-address Dec 16, 2020
ab8c83e
Merge branch 'develop' into feature/rt-automation
invalid-email-address Dec 16, 2020
2ba8ec2
remove an extra sys.exit()
BrianCurtis-NOAA Dec 16, 2020
cc57e45
Switched to using Labels
BrianCurtis-NOAA Dec 23, 2020
a5ecb16
Merge branch 'develop' into feature/rt-automation
BrianCurtis-NOAA Dec 23, 2020
3db3ff2
Rename RegressionTests_hera.intel.log to RegressionTests_neon.intel.log
BrianCurtis-NOAA Jan 5, 2021
ce666c5
Rename RegressionTests_neon.intel.log to RegressionTests_hera.intel.log
BrianCurtis-NOAA Jan 5, 2021
c588de7
AUTO: Updated tests log
BrianCurtis-NOAA Jan 5, 2021
31f10e5
Test change for repo
BrianCurtis-NOAA Jan 6, 2021
3bbef07
Merge branch 'feature/rt-automation' of https://github.com/BrianCurti…
BrianCurtis-NOAA Jan 6, 2021
239d839
Revert changes for testing
BrianCurtis-NOAA Jan 7, 2021
923c46d
Auto: Added Updated RT Log file: tests/RegressionTests_hera.intel.log
BrianCurtis-NOAA Jan 8, 2021
94d1e73
Auto: Added Updated RT Log file: tests/RegressionTests_hera.intel.log
BrianCurtis-NOAA Jan 8, 2021
61aae99
Auto: Added Updated RT Log file: tests/RegressionTests_hera.intel.log
BrianCurtis-NOAA Jan 8, 2021
e3c2931
Auto: Added Updated RT Log file: tests/RegressionTests_hera.intel.log
BrianCurtis-NOAA Jan 8, 2021
f47c1ad
Add's ability to retrieve RT logs for PR repo. Moves access token ext…
BrianCurtis-NOAA Jan 8, 2021
1b7c5f4
Merge branch 'feature/rt-automation' of https://github.com/BrianCurti…
BrianCurtis-NOAA Jan 8, 2021
7ffde33
TEST ADDITION HOPEFUL
BrianCurtis-NOAA Jan 11, 2021
e32eb4b
Almost done implementing RT log files back to PR, saving files for he…
BrianCurtis-NOAA Jan 11, 2021
9fba3a1
Merge branch 'feature/rt-automation' of https://github.com/BrianCurti…
BrianCurtis-NOAA Jan 11, 2021
34ebb42
Merging develop into feature/rt-automation
BrianCurtis-NOAA Jan 12, 2021
2271450
Updates from 1/12/21-Orion
BrianCurtis-NOAA Jan 12, 2021
981ac9d
Auto: Added Updated RT Log file: tests/RegressionTests_hera.intel.log
BrianCurtis-NOAA Jan 12, 2021
b917a08
fix for finding RT log file
BrianCurtis-NOAA Jan 12, 2021
78e4059
Merge branch 'feature/rt-automation' of https://github.com/BrianCurti…
BrianCurtis-NOAA Jan 12, 2021
b70bddd
rt hera oops
BrianCurtis-NOAA Jan 12, 2021
7957cce
Auto: Added Updated RT Log file: tests/RegressionTests_hera.intel.log
BrianCurtis-NOAA Jan 12, 2021
dfeb1f5
Auto: Added Updated RT Log file: tests/RegressionTests_hera.intel.log
BrianCurtis-NOAA Jan 13, 2021
77fa685
* Temporary test file for running on all machines
BrianCurtis-NOAA Jan 13, 2021
75d7274
Merge branch 'feature/rt-automation' of https://github.com/BrianCurti…
BrianCurtis-NOAA Jan 13, 2021
a7e6392
Auto: Added Updated RT Log file: tests/RegressionTests_hera.intel.log
BrianCurtis-NOAA Jan 13, 2021
62e077a
Moving to classes, renaming old rt_auto
BrianCurtis-NOAA Jan 15, 2021
f28b763
new file using object oriented coding
BrianCurtis-NOAA Jan 15, 2021
3c5d25d
Auto: Added Updated RT Log file: tests/RegressionTests_hera.intel.log
BrianCurtis-NOAA Jan 21, 2021
baea07d
Moved towards OO style, tested on hera successfully
BrianCurtis-NOAA Jan 21, 2021
369b868
Merge branch 'feature/rt-automation' of https://github.com/BrianCurti…
BrianCurtis-NOAA Jan 21, 2021
a24d5b5
Need to remove the label once done processing it
BrianCurtis-NOAA Jan 21, 2021
1d2aab2
matched regressiontests hera
BrianCurtis-NOAA Jan 21, 2021
06a4210
Fixed all object names to be explicit
BrianCurtis-NOAA Jan 21, 2021
26dff30
Auto: Added Updated RT Log file: tests/RegressionTests_hera.intel.log
BrianCurtis-NOAA Jan 22, 2021
5b9ac13
Added checks on RT completing before deleting the label on the GH repo
BrianCurtis-NOAA Jan 22, 2021
0256508
IDK why i have to do this, but there's dif in RT hera.intel
BrianCurtis-NOAA Jan 22, 2021
ca2c2a3
Test for Brian
BrianCurtis-NOAA Jan 22, 2021
6b63abf
Typo in RT command
BrianCurtis-NOAA Jan 22, 2021
670e58d
Auto: Added Updated RT Log file: tests/RegressionTests_hera.intel.log
BrianCurtis-NOAA Jan 22, 2021
730e7f4
Auto: Added Updated RT Log file: tests/RegressionTests_hera.intel.log
BrianCurtis-NOAA Jan 25, 2021
d17ce26
Removes DIR of PR's that don't exist, and removes dir of RT runs
BrianCurtis-NOAA Jan 26, 2021
11ab5fd
Merge branch 'feature/rt-automation' of https://github.com/BrianCurti…
BrianCurtis-NOAA Jan 26, 2021
b1e4fe6
Force commit message to default on auto pull
BrianCurtis-NOAA Jan 27, 2021
d092abb
Auto: Added Updated RT Log file: tests/RegressionTests_hera.intel.log
BrianCurtis-NOAA Jan 27, 2021
0b686c9
Auto: Added Updated RT Log file: tests/RegressionTests_orion.intel.log
BrianCurtis-NOAA Jan 27, 2021
8efcd19
Merge branch 'feature/rt-automation' of https://github.com/BrianCurti…
BrianCurtis-NOAA Jan 27, 2021
adce8f6
Remove dir for specific RT, fix prompt after pull merge
BrianCurtis-NOAA Jan 27, 2021
600198f
Merge branch 'feature/rt-automation' of https://github.com/BrianCurti…
BrianCurtis-NOAA Jan 27, 2021
3cc79ad
Merge from upstream develop
BrianCurtis-NOAA Jan 27, 2021
e2443b3
Auto: Added Updated RT Log file: tests/RegressionTests_hera.intel.log
BrianCurtis-NOAA Jan 27, 2021
59e19f9
Moved automated RT code into tests/auto and moved GHUSERNAME into acc…
BrianCurtis-NOAA Jan 27, 2021
cd32869
Merge branch 'feature/rt-automation' of https://github.com/BrianCurti…
BrianCurtis-NOAA Jan 27, 2021
3f1ccb8
Auto: Added Updated RT Log file: tests/RegressionTests_hera.intel.log
BrianCurtis-NOAA Jan 27, 2021
4defe5a
Some typos with sleep and bringing in print function from futures in …
BrianCurtis-NOAA Jan 27, 2021
f1f8b10
Merge branch 'feature/rt-automation' of https://github.com/BrianCurti…
BrianCurtis-NOAA Jan 27, 2021
370b80b
Auto: Added Updated RT Log file: tests/RegressionTests_gaea.intel.log
Jan 28, 2021
e0792c4
Auto: Added Updated RT Log file: tests/RegressionTests_gaea.intel.log
BrianCurtis-NOAA Jan 28, 2021
72a7f0a
don't need to load modulefiles, gaea reg exp check for hostname neede…
BrianCurtis-NOAA Jan 28, 2021
4006342
Merge branch 'feature/rt-automation' of https://github.com/BrianCurti…
BrianCurtis-NOAA Jan 28, 2021
893ee82
Auto: Added Updated RT Log file: tests/RegressionTests_gaea.intel.log
BrianCurtis-NOAA Jan 28, 2021
515471d
Auto: Added Updated RT Log file: tests/RegressionTests_gaea.intel.log
BrianCurtis-NOAA Jan 29, 2021
fff2229
Auto: Added Updated RT Log file: tests/RegressionTests_hera.intel.log
BrianCurtis-NOAA Jan 29, 2021
9ba3b4d
Added logger to all functions/classes. Added thread watcher so main()…
BrianCurtis-NOAA Jan 29, 2021
0c363b9
Merge branch 'feature/rt-automation' of https://github.com/BrianCurti…
BrianCurtis-NOAA Jan 29, 2021
a4ec205
Auto: Added Updated RT Log file: tests/RegressionTests_gaea.intel.log
BrianCurtis-NOAA Jan 29, 2021
f8701bb
Auto: Added Updated RT Log file: tests/RegressionTests_gaea.intel.log
BrianCurtis-NOAA Jan 29, 2021
4bd7304
typo for ACCNR
BrianCurtis-NOAA Jan 29, 2021
1787538
Merge branch 'feature/rt-automation' of https://github.com/BrianCurti…
BrianCurtis-NOAA Jan 29, 2021
4a6ae38
merging with upstream
BrianCurtis-NOAA Jan 29, 2021
20fd5b8
Auto: Added Updated RT Log file: tests/RegressionTests_gaea.intel.log
BrianCurtis-NOAA Jan 29, 2021
7749417
Auto: Added Updated RT Log file: tests/RegressionTests_orion.intel.log
BrianCurtis-NOAA Jan 29, 2021
1e1e080
Merge branch 'feature/rt-automation' of https://github.com/BrianCurti…
BrianCurtis-NOAA Jan 29, 2021
f890f46
Auto: Added Updated RT Log file: tests/RegressionTests_gaea.intel.log
BrianCurtis-NOAA Jan 29, 2021
4819bc5
Need extra export for Gaea to work
BrianCurtis-NOAA Jan 30, 2021
f967e31
Merge branch 'feature/rt-automation' of https://github.com/BrianCurti…
BrianCurtis-NOAA Jan 30, 2021
fe9248d
Bring back the full rt.conf
BrianCurtis-NOAA Jan 30, 2021
41f5abf
Cleanup for PR to ufs-community/ufs-weather-model
BrianCurtis-NOAA Feb 1, 2021
615eb46
Cleanup for PR to ufs-community/ufs-weather-model retry
BrianCurtis-NOAA Feb 1, 2021
9b260b2
Checkout upstream Regression test logs
BrianCurtis-NOAA Feb 1, 2021
9dee224
Delete RegressionTests_neon.intel.log
BrianCurtis-NOAA Feb 1, 2021
0581477
Delete rt.conf.good
BrianCurtis-NOAA Feb 1, 2021
1b73087
Fixed use of sys.exit and instead raise errors, removed sys import, b…
BrianCurtis-NOAA Feb 2, 2021
1f3ae9f
Fixes and temp changes for testing
BrianCurtis-NOAA Feb 3, 2021
2aff54b
Auto: Added Updated RT Log file: tests/RegressionTests_orion.intel.log
BrianCurtis-NOAA Feb 3, 2021
f641839
Removed dependency of pandas, added a KeyboardInterrupt catch to repl…
BrianCurtis-NOAA Feb 3, 2021
9bf5469
Bringing back upstream rt.conf and RegressionTest from Orion
BrianCurtis-NOAA Feb 3, 2021
4230e88
typo test fix
BrianCurtis-NOAA Feb 4, 2021
96f8e39
Added more doc strong and removed the need for importing socket
BrianCurtis-NOAA Feb 4, 2021
3dc339b
Merge branch 'feature/rt-automation' of https://github.com/BrianCurti…
BrianCurtis-NOAA Feb 4, 2021
5344add
* Removed need for rt_auto.yml
BrianCurtis-NOAA Feb 10, 2021
6778102
Auto: Added Updated RT Log file: tests/RegressionTests_hera.intel.log
BrianCurtis-NOAA Feb 12, 2021
ebc1edc
Auto: Added Updated RT Log file: tests/RegressionTests_hera.intel.log
BrianCurtis-NOAA Feb 12, 2021
58e5255
* Fixed call using string to access callback function
BrianCurtis-NOAA Feb 12, 2021
9735b3b
Merge branch 'feature/rt-automation' of https://github.com/BrianCurti…
BrianCurtis-NOAA Feb 12, 2021
567deb6
Merge w/upstream
BrianCurtis-NOAA Feb 12, 2021
5fe9ad6
rt.conf for testing
BrianCurtis-NOAA Feb 12, 2021
fde7d86
Auto: Added Updated RT Log file: tests/RegressionTests_orion.intel.log
BrianCurtis-NOAA Feb 12, 2021
c46c38b
Auto: Added Updated RT Log file: tests/RegressionTests_gaea.intel.log
BrianCurtis-NOAA Feb 12, 2021
1e255f2
Merge branch 'feature/rt-automation' of https://github.com/BrianCurti…
BrianCurtis-NOAA Feb 12, 2021
542183b
Bringing back current RegressionTests_* and rt.conf
BrianCurtis-NOAA Feb 12, 2021
0217f9a
Update rt_auto.py
BrianCurtis-NOAA Feb 12, 2021
56f0226
* removed uneeded imports
BrianCurtis-NOAA Feb 12, 2021
c48e9b6
Update to help testing cronjob
BrianCurtis-NOAA Feb 22, 2021
ce27027
Merging with develop
BrianCurtis-NOAA Feb 22, 2021
7f60f65
Merge branch 'develop' into feature/rt-automation
BrianCurtis-NOAA Feb 22, 2021
0efc765
* Fixes to get crontab run to work
BrianCurtis-NOAA Feb 22, 2021
fd5d0df
Auto: Added Updated RT Log file: tests/RegressionTests_hera.intel.log
BrianCurtis-NOAA Feb 22, 2021
9c24b80
Auto: Added Updated RT Log file: tests/RegressionTests_hera.intel.log
BrianCurtis-NOAA Feb 22, 2021
08c4aff
Run rt_auto.py and rt.sh in a login shell
BrianCurtis-NOAA Feb 22, 2021
2b3eee7
Merge branch 'feature/rt-automation' of https://github.com/BrianCurti…
BrianCurtis-NOAA Feb 22, 2021
6d2c032
Auto: Added Updated RT Log file: tests/RegressionTests_orion.intel.log
BrianCurtis-NOAA Feb 22, 2021
42bfb7e
Auto: Added Updated RT Log file: tests/RegressionTests_gaea.intel.log
BrianCurtis-NOAA Feb 22, 2021
eb59dc6
Merge branch 'feature/rt-automation' of https://github.com/BrianCurti…
BrianCurtis-NOAA Feb 22, 2021
578aa0a
Auto: Added Updated RT Log file: tests/RegressionTests_hera.intel.log
BrianCurtis-NOAA Feb 22, 2021
588fe3d
Auto: Added Updated RT Log file: tests/RegressionTests_hera.intel.log
BrianCurtis-NOAA Feb 23, 2021
d93c8db
Auto: Added Updated RT Log file: tests/RegressionTests_hera.intel.log
BrianCurtis-NOAA Feb 23, 2021
1b4df6a
Auto: adding rt_auto.log
BrianCurtis-NOAA Feb 23, 2021
998f87d
Auto: Added Updated RT Log file: tests/RegressionTests_hera.intel.log
BrianCurtis-NOAA Feb 23, 2021
2340211
* log level to info by default, never save debug to repo
BrianCurtis-NOAA Feb 23, 2021
f38dfcc
Merge branch 'feature/rt-automation' of https://github.com/BrianCurti…
BrianCurtis-NOAA Feb 23, 2021
3a276e1
Auto: Added Updated RT Log file: tests/RegressionTests_hera.intel.log
BrianCurtis-NOAA Feb 23, 2021
6af87be
Auto: adding rt_auto.log
BrianCurtis-NOAA Feb 23, 2021
fc3ea94
* Removed the need to log the API Token.
BrianCurtis-NOAA Feb 24, 2021
b2e8f26
Merge branch 'feature/rt-automation' of https://github.com/BrianCurti…
BrianCurtis-NOAA Feb 24, 2021
931a701
* removed an extra log
BrianCurtis-NOAA Feb 24, 2021
3405c9d
* get rid of extra commented out code
BrianCurtis-NOAA Feb 24, 2021
68a5def
Auto: Added Updated RT Log file: tests/RegressionTests_gaea.intel.log
BrianCurtis-NOAA Feb 24, 2021
1703e15
Auto: Added Updated RT Log file: tests/RegressionTests_orion.intel.log
BrianCurtis-NOAA Feb 24, 2021
9a544f3
Merge branch 'feature/rt-automation' of https://github.com/BrianCurti…
BrianCurtis-NOAA Feb 24, 2021
6efe04c
Auto: Added Updated RT Log file: tests/RegressionTests_hera.intel.log
BrianCurtis-NOAA Feb 24, 2021
413c35a
Merge branch 'feature/rt-automation' of https://github.com/BrianCurti…
BrianCurtis-NOAA Feb 24, 2021
55026e9
Jet Regression Test
BrianCurtis-NOAA Feb 24, 2021
a7c11bd
Merge branch 'feature/rt-automation' of https://github.com/BrianCurti…
BrianCurtis-NOAA Feb 24, 2021
aa8cb88
* Logs renamed and saved for a max one month.
BrianCurtis-NOAA Feb 24, 2021
44f35f7
Merge branch 'feature/rt-automation' of https://github.com/BrianCurti…
BrianCurtis-NOAA Feb 24, 2021
c0e52cc
* typo fixes
BrianCurtis-NOAA Feb 24, 2021
3dc3811
Auto: Added Updated RT Log file: tests/RegressionTests_hera.intel.log
BrianCurtis-NOAA Feb 24, 2021
24eb8b7
hera.gnu log
BrianCurtis-NOAA Feb 24, 2021
1d8b9a3
Merge branch 'feature/rt-automation' of https://github.com/BrianCurti…
BrianCurtis-NOAA Feb 24, 2021
017aec1
WCoss Dell P3 Logs
Feb 25, 2021
14def7e
WCoss_Cray log
BrianCurtis-NOAA Feb 25, 2021
0df4069
Filename change in rm_command to match filename generated
BrianCurtis-NOAA Feb 25, 2021
06f96e2
Merge from develop and using RT logs from upstream
BrianCurtis-NOAA Feb 25, 2021
0034991
Jet Python Path Updated
BrianCurtis-NOAA Feb 25, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
206 changes: 103 additions & 103 deletions tests/RegressionTests_gaea.intel.log

Large diffs are not rendered by default.

385 changes: 166 additions & 219 deletions tests/RegressionTests_hera.intel.log

Large diffs are not rendered by default.

136 changes: 68 additions & 68 deletions tests/RegressionTests_jet.intel.log

Large diffs are not rendered by default.

226 changes: 113 additions & 113 deletions tests/RegressionTests_orion.intel.log

Large diffs are not rendered by default.

304 changes: 304 additions & 0 deletions tests/auto/rt_auto.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,304 @@
"""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 add_pr_label(self):
''' adds the pull request label that initiated the job run to PR'''
self.logger.info(f'Adding Label: {self.preq_dict["label"]}')
self.preq_dict['preq'].add_to_labels(self.preq_dict['label'])

def send_log_as_comment(self):
with open('rt_auto.log', 'r') as f:
filedata = f.read()
self.preq_dict['preq'].create_issue_comment(filedata)

def run_commands(self, commands_with_cwd):
logger = logging.getLogger('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:
self.add_pr_label()
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}', os.getcwd()]
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 runFunction(self):
BrianCurtis-NOAA marked this conversation as resolved.
Show resolved Hide resolved
''' Run the command associted with the label used to initiate this job '''
logger = logging.getLogger('JOB/RUNFUNCTION')
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:
self.add_pr_label()
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.critical(f'stdout: {item}') for item in out if not None]
[logger.critical(f'stderr: {eitem}') for eitem in err if not None]
logger.debug(output.returncode)
BrianCurtis-NOAA marked this conversation as resolved.
Show resolved Hide resolved
if output.returncode != 0:
self.add_pr_label()
logger.critical(f'{self.preq_dict["action"]["command"]} Failed')
[logger.debug(f'stdout: {item}') for item in out if not None]
[logger.debug(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:
self.add_pr_label()
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 runFunction')
job.runFunction()
logger.info('Calling remove_pr_dir')
job.remove_pr_dir()
logger.info('Calling send_log_as_comment')
job.send_log_as_comment()
except Exception as e:
job.add_pr_label()
logger.critical(e)
assert(e)

logger.info('Script Finished')


if __name__ == '__main__':
main()
47 changes: 47 additions & 0 deletions tests/auto/rt_auto.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#!/bin/bash --login
set -eux
if [ -f "accesstoken.sh" ]; then
source ./accesstoken.sh
export ghapitoken=$ghapitoken
BrianCurtis-NOAA marked this conversation as resolved.
Show resolved Hide resolved
else
echo "Please create accesstoken.sh (600) with the following content\n"
echo "/bin/bash\n"
BrianCurtis-NOAA marked this conversation as resolved.
Show resolved Hide resolved
echo "export ghapitoken=<GitHub API Token Here>"
exit 1
fi

export RT_COMPILER='intel'
DusanJovic-NOAA marked this conversation as resolved.
Show resolved Hide resolved
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/ecFlow-5.3.1/bin:$PATH
export PYTHONPATH=/lfs4/HFIP/hfv3gfs/software/ecFlow-5.3.1/lib/python2.7/site-packages
BrianCurtis-NOAA marked this conversation as resolved.
Show resolved Hide resolved
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.
Show resolved Hide 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