-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtasks.py
More file actions
131 lines (99 loc) · 2.53 KB
/
tasks.py
File metadata and controls
131 lines (99 loc) · 2.53 KB
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
"""
Tasks for maintaining the project.
Execute 'invoke --list' for guidance on using Invoke
"""
import shutil
import pprint
import sys
from invoke import task
from pathlib import Path
Path().expanduser()
CMD_PKG = "github.com/romnn/mongoimport/cmd/mongoimport"
PKG = "github.com/romnn/mongoimport"
ROOT_DIR = Path(__file__).parent
BUILD_DIR = ROOT_DIR.joinpath("build")
def _delete_file(file):
try:
file.unlink(missing_ok=True)
except TypeError:
# missing_ok argument added in 3.8
try:
file.unlink()
except FileNotFoundError:
pass
@task
def format(c):
"""Format code
"""
c.run("pre-commit run go-fmt --all-files")
c.run("pre-commit run go-imports --all-files")
@task
def test(c):
"""Run tests
"""
c.run("env GO111MODULE=on go test -v -race ./...")
@task
def cyclo(c):
"""Check code complexity
"""
c.run("pre-commit run go-cyclo --all-files")
@task
def lint(c):
"""Lint code
"""
c.run("pre-commit run go-lint --all-files")
c.run("pre-commit run go-vet --all-files")
@task
def install_hooks(c):
"""Install pre-commit hooks
"""
c.run("pre-commit install")
@task
def pre_commit(c):
"""Run all pre-commit checks
"""
c.run("pre-commit run --all-files")
@task(help=dict(publish="Publish the coverage result to codecov.io (default False)",),)
def coverage(c, publish=False):
"""Create coverage report
"""
c.run(
"env GO111MODULE=on go test -v -race -coverprofile=coverage.txt -coverpkg=all -covermode=atomic ./..."
)
if publish:
# Publish the results via codecov
c.run("bash <(curl -s https://codecov.io/bash)")
@task
def cc(c):
"""Build the project for all architectures
"""
c.run(
'gox -os="linux darwin windows" -arch="amd64" -output="build/{{.Dir}}-{{.OS}}-{{.Arch}}" -ldflags "-X main.Rev=`git rev-parse --short HEAD`" -verbose %s'
% CMD_PKG
)
@task
def build(c):
"""Build the project
"""
c.run("pre-commit run go-build --all-files")
@task
def run(c):
"""Run the cmd target
"""
options = sys.argv[3:]
c.run("go run {} {}".format(CMD_PKG, " ".join(options)))
@task
def clean_build(c):
"""Clean up files from package building
"""
c.run("rm -fr build/")
@task
def clean_coverage(c):
"""Clean up files from coverage measurement
"""
c.run("find . -name 'coverage.txt' -exec rm -fr {} +")
@task(pre=[clean_build, clean_coverage])
def clean(c):
"""Runs all clean sub-tasks
"""
pass