keep-it-secret/tasks.py
2024-06-05 07:10:16 +00:00

55 lines
994 B
Python

# -*- coding: utf-8 -*-
# type: ignore
import os
from invoke import task
try:
from ops.tasks import * # noqa: F401,F403
except ImportError:
pass
@task
def flake8(ctx, warn=False):
return ctx.run('flake8', warn=warn)
@task
def mypy(ctx, warn=False):
return ctx.run('mypy .', warn=warn)
@task
def tests(ctx, warn=False):
pytest_command_line = [
'pytest',
'-v',
]
if 'KEEP_IT_SECRET_JUNIT_XML_PATH' in os.environ:
pytest_command_line.append(
f"--junit-xml={os.environ['KEEP_IT_SECRET_JUNIT_XML_PATH']}",
)
return ctx.run(' '.join(pytest_command_line), warn=warn)
@task
def ci(ctx):
result = True
ctx.run('mkdir -p build')
if flake8(ctx, warn=True).exited != 0:
result = False
if mypy(ctx, warn=True).exited != 0:
result = False
if tests(ctx, warn=True).exited != 0:
result = False
if result is False:
raise RuntimeError('Some checks have failed')