-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtasks.sh
More file actions
159 lines (130 loc) · 4.08 KB
/
tasks.sh
File metadata and controls
159 lines (130 loc) · 4.08 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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
#!/usr/bin/env bash
# from https://sharats.me/posts/shell-script-best-practices/
set -o errexit
set -o nounset
set -o pipefail
# set -o xtrace
TIMEFORMAT="Task completed in %3lR"
SRC_FILES="./gaunit ./tests setup.py"
FORMAT_FILES="./gaunit ./tests setup.py ./examples"
PACKAGE="gaunit"
##### Dev
docs() { ## Build html documentation
( cd docs; sphinx-build -b html -a -E "." "build/html" )
}
docs-open() {
DOCS_PATH="docs/build/html/index.html"
if command -v start &> /dev/null # Windows
then
start $DOCS_PATH
else
xdg-open $DOCS_PATH
fi
}
pip-comp() { ## Compile requirements files
pip-compile requirements/base.in
pip-compile requirements/dev.in
pip-compile requirements/samples.in
}
pip-up() { ## Update requirements files
pip-compile --upgrade --resolver=backtracking requirements/base.in
pip-compile --upgrade --resolver=backtracking requirements/dev.in
pip-compile --upgrade --resolver=backtracking requirements/samples.in
}
install-dev() { ## * Install dev requirements
pip install -e .
pip install -r requirements/dev.txt
npm install -g conventional-changelog-cli
}
install-examples() { ## Install examples requirements
pip install -e .
pip install -r requirements/samples.txt
}
clean-logs() { ## Remove all log & RF report files
rm *.log log.html output.xml report.html || true
}
tests() { ## * Run all tests
test-unit
test-cli
test-lint
test-format
test-package
}
test-format() { ## Run code formatting tests
black --check --diff $FORMAT_FILES
}
test-lint() { ## Run code linting tests
pylint --errors-only $SRC_FILES
}
test-unit() { ## Run unit tests (with coverage run)
coverage run -m unittest discover tests
}
test-cli() { ## Run tests on gaunit command
ga --version
ga check tests/test_cli_mock.har home_engie -t tests/tracking_plan.json
ga check tests/test_cli_mock.har home_engie -t tests/tracking_plan.json --all
# test for https://github.com/VinceCabs/GAUnit/issues/3:
ga check tests/test_cli_mock.har home_engie -t tests/tracking_plan.json \
| grep --fixed-strings "OK: all expected events found" \
|| _fail "CLI test failed: 'ga check'"
ga extract tests/test_cli_mock.har -f dp | grep --fixed-strings "[{'dp': 'A'}, {'dp': 'B'}, {'dp': 'C'}, {'dp': 'X'}]" \
|| _fail "CLI test failed: 'ga extract'"
ga extract tests/test_cli_ss_mock.har -f dp -tu "tracking.example.com" \
| grep --fixed-strings "[{'dp': 'A'}, {'dp': 'B'}, {'dp': 'C'}, {'dp': 'X'}]" \
|| _fail "CLI test failed: 'ga extract'"
}
test-unit-v() { ## Run unit tests (verbose)
coverage run -m unittest discover tests -v
}
test-package() { ## Test that package can be uploaded to pypi
twine check dist/$PACKAGE-$(version).tar.gz
}
format() { ## * Format code
black $FORMAT_FILES
}
##### Use & Deploy
install-minimal() { ## Install minimal usage requirements
pip install --upgrade gaunit
}
build-package() { ## Build a python package ready to upload to pypi
python setup.py sdist bdist_wheel
}
push-package() { ## * Build, test and push python packages to pypi
test-package
python -m twine upload --skip-existing dist/$PACKAGE-*.tar.gz
}
changelog() { ## updates CHANGELOG.md
conventional-changelog ---preset angular --infile CHANGELOG.md --same-file
}
release() { ## * Test, create a release tag and push it to repos (origin)
tests
TAG=v$(version)
# create tag
echo "=== Creating tag $TAG"
git tag -d v$(version) || true
git tag v$TAG
# push tag
echo "=== Pushing tag $TAG to origin"
git push origin
git push origin :$(TAG) || true
git push origin $(TAG)
}
###### Additional commands
_fail() {
echo "FAIL: $1"
exit 0
}
version() { ## Print the current version
python -c "import io, os; about = {}; exec(io.open(os.path.join('$PACKAGE', '__about__.py'), 'rt', encoding='utf-8').read(), about); print(about['__version__'])"
}
help() { ## print this help
echo "$0 <task> <args>"
grep -E '^([a-zA-Z_-]+\(\) {.*?## .*|######* .+)$$' $0 \
| sed 's/######* \(.*\)/\n \1/g' \
| sed 's/\([a-zA-Z-]\+\)()/\1/' \
| awk 'BEGIN {FS = "{.*?## "}; {printf "\033[93m%-30s\033[0m %s\033[0m\n", $1, $2}'
}
default() {
help
}
"${@:-default}"