-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdevops.py
96 lines (69 loc) · 2.84 KB
/
devops.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# !/usr/bin/env python
# -*- coding: utf-8 -*-
__coverage__ = 0.00
__author__ = "Bruce_H_Cottman"
__license__ = "MIT License"
""" A sandbox devops implemented in Python.
Environment can vary by language, os, cpu, packages,
package versions....
"""
import subprocess as sp
import colorama
from colorama import Fore, Back, Style
colorama.init()
print(colorama.ansi.clear_screen())
def devops_step(serial_script_cmd:str ,nstep:int, return_code: int):
""" execute devops step logic"""
rc = -1 # next step return_code
if return_code == 0:
child = sp.Popen(serial_script_cmd, shell=True,
stdout=sp.PIPE,
stderr=sp.PIPE)
stdout, stderr = child.communicate()
rc = child.returncode
print(Back.BLACK + Fore.GREEN+' \nExecuting devops step(', nstep, '): ', serial_script_cmd+ Fore.WHITE)
print(Style.RESET_ALL)
print("stdout: ", stdout.decode('utf-8'), "\n stderr: ", stderr.decode('utf-8'), Fore.WHITE)
if rc == 0:
print(Back.BLACK + Fore.GREEN+' yes! :Pass Go!!!' + Fore.WHITE)
nstep += 1
else:
print(Back.BLACK + Fore.RED + ' Failed! ', serial_script_cmd, rc, Fore.WHITE)
return nstep, rc
nstep = 1
return_code = 0
# black pep-8 formatting
serial_script_cmd = 'black -v tests'
nstep,rc = devops_step(serial_script_cmd, nstep, return_code )
#mypy type checking
serial_script_cmd = 'mypy src'
nstep, rc = devops_step(serial_script_cmd, nstep, return_code)
#pylint
serial_script_cmd = 'pylint src -E -v'
nstep, rc = devops_step(serial_script_cmd, nstep, return_code)
#pytest for tests
serial_script_cmd = 'pytest -v tests'
nstep, rc = devops_step(serial_script_cmd, nstep, return_code)
#coverage
serial_script_cmd = 'coverage run -m pytest tests'
nstep, rc = devops_step(serial_script_cmd, nstep, return_code)
serial_script_cmd = 'coverage report'
nstep, rc = devops_step(serial_script_cmd, nstep, return_code)
######
import uuid
pid = 'branch-' + str(uuid.uuid4())
serial_script_cmd = 'git checkout -b ' + pid
nstep, rc = devops_step(serial_script_cmd, nstep, return_code)
serial_script_cmd = 'git add -A'
nstep, rc = devops_step(serial_script_cmd, nstep, return_code)
# git commit -m'[message]'
serial_script_cmd = 'git config user.email "[email protected]" '
nstep, rc = devops_step(serial_script_cmd, nstep, return_code)
serial_script_cmd = 'git config user.name "bcottman" '
nstep, rc = devops_step(serial_script_cmd, nstep, return_code)
serial_script_cmd = 'git commit -m "sandbox commit that passesd all local unit tests"'
nstep, rc = devops_step(serial_script_cmd, nstep, return_code)
serial_script_cmd = 'git config --list'
nstep, rc = devops_step(serial_script_cmd, nstep, return_code)
serial_script_cmd = 'git push -u origin ' + pid
nstep, rc = devops_step(serial_script_cmd, nstep, return_code)