-
Notifications
You must be signed in to change notification settings - Fork 8
/
tasks.py
41 lines (30 loc) · 1.03 KB
/
tasks.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
import re
from pathlib import Path
from invoke import Exit, task
@task
def release(ctx):
toml = Path("pyproject.toml").read_text()
match = re.search(r'version = "(.*?)"', toml)
if match:
version = match.group(1)
print(f"Releasing {version}")
ctx.run(f"git tag {version}", echo=True)
ctx.run(f"git push origin {version}", echo=True)
else:
print("Failed to find version in the pyproject.toml")
def run_test_cmd(ctx, cmd, env=None) -> int:
print("=" * 79)
print(f"> {cmd}")
return ctx.run(cmd, warn=True, env=env).exited
@task
def test(ctx):
failed_commands = []
if run_test_cmd(ctx, "pre-commit run --all-files"):
failed_commands.append("Pre commit hooks")
if run_test_cmd(ctx, "mypy pyjwt_key_fetcher"):
failed_commands.append("Mypy")
if run_test_cmd(ctx, "pytest"):
failed_commands.append("Unit tests")
if failed_commands:
msg = "Errors: " + ", ".join(failed_commands)
raise Exit(message=msg, code=len(failed_commands))