-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathtask
More file actions
executable file
·167 lines (141 loc) · 4.37 KB
/
task
File metadata and controls
executable file
·167 lines (141 loc) · 4.37 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
160
161
162
163
164
165
166
167
#!/usr/bin/env bash
set -e
if [[ -a '.env' ]]; then
source .env
fi
help-table() {
local cmd_width=10
local opt_width=6
local desc_width=40
local column="| %-${cmd_width}s | %-${opt_width}s | %-${desc_width}s |\n"
printf "$column" 'Command' 'Option' 'Description'
echo "|$(printf '%*s' $((cmd_width + 2)) '' | tr ' ' '-')|$(printf '%*s' $((opt_width + 2)) '' | tr ' ' '-')|$(printf '%*s' $((desc_width + 2)) '' | tr ' ' '-')|"
printf "$column" 'all' '' 'Run all tasks.'
printf "$column" 'install' '' 'Setup the local environment.'
printf "$column" 'lint' '' 'Run pre-commit.'
printf "$column" 'build' '' 'Build python packages with whool.'
printf "$column" 'publish' '' 'Publish python packages to PyPi.'
printf "$column" 'docs' '' 'Update index.html.'
}
help() {
echo
if [[ -n "$1" ]]; then
help-table | grep -i "$1" | column -t -s'|'
else
echo 'task <command> [options]'
echo
echo 'commands:'
echo
help-table
fi
echo
}
if [[ -d "$HOME/taskfile.build/bin" ]]; then
for file in "$HOME/taskfile.build/bin/"*; do
if [[ -f "$file" ]]; then
source "$file"
fi
done
fi
install() {
echo 'Setup .venv and install python dependencies'
uv venv
source .venv/bin/activate
uv pip install pre-commit git+https://github.com/OCA/maintainer-tools
}
lint() {
source .venv/bin/activate
echo 'Run pre-commit'
pre-commit run --all-files --show-diff-on-failure --color=always
}
build() {
source .venv/bin/activate
local root_dir="$(pwd)"
local metapackage_dir="$root_dir/setup/_metapackage"
local publish_dir="$root_dir/dist"
mkdir -p "$publish_dir"
rm -rf "$publish_dir"/*
local server_name="$(basename "$root_dir")"
local metapackage_name="odoo-apps-$(echo "$server_name" | sed 's/_/-/g')"
oca-gen-metapackage "$metapackage_name"
local addons=()
mapfile -t addons < <(find . -maxdepth 2 -type f -name 'pyproject.toml' | xargs dirname | sed 's|^\./||')
for addon in "${addons[@]}"; do
cd "$root_dir/$addon"
echo "Building $addon"
uv build
cp dist/*.whl "$publish_dir/"
cp dist/*.tar.gz "$publish_dir/"
cd "$root_dir"
done
echo 'Installing local wheels for metapackage resolution...'
uv pip install "$publish_dir"/*.whl 2>/dev/null || true
cd "$metapackage_dir"
echo "Building $metapackage_name"
uv build
cp dist/*.whl "$publish_dir/"
cp dist/*.tar.gz "$publish_dir/"
ls "$publish_dir/"
}
publish() {
source .venv/bin/activate
local root_dir="$(pwd)"
local publish_dir="$root_dir/dist"
set +e
echo "Publishing from $publish_dir to PyPI..."
for wheel in "$publish_dir"/*.whl; do
if [[ ! -f "$wheel" ]]; then
continue
fi
echo "Publishing: $wheel"
uv publish "$wheel" --username '__token__' --password "$PYPI_TOKEN"
if (( $? != 0 )); then
echo "Failed to publish $wheel."
fi
done
echo 'All wheels published successfully.'
}
docs() {
source .venv/bin/activate
echo 'Update index.html for all modules'
for module in ./*; do
if [[ -f "$module/README.rst" ]]; then
cd "$module" || exit
rst2html5 README.rst static/description/index.html
cd .. || exit
fi
done
# Find marker in readme and clear content after
echo 'Clear modules table in README.md'
local marker='## Available modules'
sed -i "/$marker/Q" 'README.md'
echo "$marker" >> 'README.md'
echo '' >> 'README.md'
echo '| Module | Summary |' >> 'README.md'
echo '| --- | --- |' >> 'README.md'
local manifest_files='./*/__manifest__.py'
for manifest_file in $manifest_files; do
local module_dir=$(dirname "$manifest_file")
local module_name=$(basename "$module_dir")
echo "Add summary of $module_name to readme file."
local summary=$(grep 'summary' "$manifest_file" -A 1 | tail -1)
echo "| [$module_name]($module_name) | $summary |" >> 'README.md'
done
}
if declare -f "$1" > /dev/null; then
"$1" "${@:2}"
else
case "$1" in
all)
install
lint
docs
build
;;
*)
echo "Unknown command: $1"
help task
exit 1
;;
esac
fi