-
Notifications
You must be signed in to change notification settings - Fork 58
/
task
97 lines (83 loc) · 3.28 KB
/
task
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
#!/usr/bin/env bash
# Print each command as it is run
set -x
clean () {
# Remove unnecessary / temporary files
rm -rf build/ dist/ .eggs/
rm -rf tests/uploads/ tests/htmlcov/ tests/.cache-url
rm -f .coverage
find . \( -name '*.egg-info' -o -name '*.egg' -o -name '*.pyc' -o -name '*.pyo' -o -name '__pycache__' \) -exec rm -fr {} +
}
reformat () {
git ls-files | grep -E '\.py$' | grep -v pytest.complexity_error.invalid.py | xargs black --skip-string-normalization --line-length=99
git ls-files | grep -E '\.(js|jsx|ts|css|scss|sass|yaml|yml|md)$' | xargs -n100 npx [email protected] --write
}
lint () {
ruff check
}
test () {
nosetests
pytest/run.sh
}
stats () {
# Get complexity of each part of Gramex and Gramex Enterprise. Save in gramex/
python pkg/usage/gramexsize.py . ../gramexenterprise/ | tr -d '\r' > gramex/gramexsize.csv
# Count number of lines of code
PYLOC=`find gramex -name '*.py' ! -path '*/node_modules/*' | grep '\.py$' | xargs wc -l | tail -1 | sed 's/[^0-9]//g'`
JSLOC=`find gramex -name '*.js' ! -path '*/node_modules/*' | grep '\.js$' | xargs wc -l | tail -1 | sed 's/[^0-9]//g'`
TESTLOC=`find tests testlib pytest -name '*.py' ! -path '*node_modules/*' | grep '\.py$' | xargs wc -l | tail -1 | sed 's/[^0-9]//g'`
printf "type,loc\nPython,$PYLOC\nJavaScript,$JSLOC\nTests,$TESTLOC\n" | tee reports/loc.csv
}
docs () {
(cd mkdocs; mkdocs build)
}
pushdocs () {
# Requires pip install -e . --config-settings editable_mode=strict
rsync -avzP mkdocs/api [email protected]:/mnt/gramener/apps/guide/
}
pushpypi () {
clean
pip install --upgrade build twine
python -m build .
# Use API token from gramener account
twine upload -u __token__ dist/*
}
pushcoverage () {
rsync -avzP tests/htmlcov/ [email protected]:/mnt/gramener/demo.gramener.com/gramextestcoverage/
}
update () {
find gramex/apps/ -maxdepth 2 -name package.json | xargs dirname | xargs -L1 bash -c 'cd "$0" && npm update && npm audit fix'
}
security () {
# Run all security tests
ruff check gramex --select S > reports/bandit.txt
freshclam
clamscan --recursive --exclude-dir=.git --exclude-dir=.ruff_cache --exclude-dir=__pycache__ --exclude-dir=mkdocs --exclude-dir=.eggs --exclude-dir=node_modules > reports/clamav.txt
find gramex/apps/ -maxdepth 2 -name package.json | xargs dirname | xargs -L1 bash -c 'cd "$0" && npm audit --parseable || true' > reports/npm-audit.txt
syft gramex > reports/syft.txt
snyk test --dev --all-projects --skip-unresolved > reports/snyk.txt || true
}
# Usage: VERSION=1.xx.0 bash task builddocker pushdocker
builddocker () {
docker pull frolvlad/alpine-glibc:alpine-3.17
VERSION=$VERSION bash pkg/docker-gramex-base/setup.sh
VERSION=$VERSION bash pkg/docker-gramex/setup.sh
VERSION=$VERSION bash pkg/docker-gramex-test/setup.sh
VERSION=$VERSION bash pkg/docker-gramex-pytest/setup.sh
}
pushdocker () {
docker login # log in as sanand0 / pratapvardhan
docker push gramener/gramex-base:$VERSION
docker push gramener/gramex-base:latest
docker push gramener/gramex:$VERSION
docker push gramener/gramex:latest
docker push gramener/gramex-pytest:$VERSION
docker push gramener/gramex-pytest:latest
}
# Run all commands from the same folder as this script
cd "$(dirname "$0")"
# Run all commands
for cmd in "$@"
do
"$cmd"
done