-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcicd.py
61 lines (46 loc) · 1.91 KB
/
cicd.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
import os
import subprocess
from typing import Any, List
from halo import Halo
def run_bash_and_check(command: List[str], stdout: Any = None, stderr: Any = None) -> None:
if stdout or stderr:
subprocess.run(command, check=True, stdout=stdout, stderr=stderr)
else:
subprocess.run(command, check=True)
def fmt() -> None:
"""Format code."""
spinner = Halo(text="> Running yapf on project", spinner="arc", placement="right")
spinner.start()
run_bash_and_check(["python3", "-m", "yapf", "--recursive", "-i", "bra_database"])
run_bash_and_check(["python3", "-m", "isort", "bra_database"])
spinner.succeed()
def flake() -> None:
"""Check lint."""
spinner = Halo(text="> Running Flake8 on project", spinner="arc", placement="right")
spinner.start()
run_bash_and_check(["python3", "-m", "flake8", "bra_database"])
spinner.succeed()
def lint() -> None:
"""Check lint."""
spinner = Halo(text="> Running PyLint on project", spinner="arc", placement="right")
spinner.start()
run_bash_and_check(["python3", "-m", "pylint", "bra_database"])
spinner.succeed()
def bandit() -> None:
"""Check security issues."""
spinner = Halo(text="> Running FLake8-bandit on project", spinner="arc", placement="right")
spinner.start()
run_bash_and_check(["python3", "-m", "bandit", "--exit-zero", "-r", "bra_database"])
spinner.succeed()
def coverage() -> None:
"""Perform coverage analysis."""
spinner = Halo(text="> Checking code coverage", spinner="dots", placement="left")
spinner.start()
run_bash_and_check(["python3", "-m", "coverage", "run", "-m", "pytest", "tests"])
spinner.succeed()
def unit_tests() -> None:
"""Perform tests."""
spinner = Halo(text="> Running project's unit tests", spinner="dots", placement="left")
spinner.start()
run_bash_and_check(["python3", "-m", "pytest", "-q", "tests"])
spinner.succeed()