@@ -14,7 +14,7 @@ cd -- "$(dirname -- "$0")"/..
14
14
# - git 1.8+
15
15
# - jq 1.6+
16
16
# - npm (node 18+)
17
- # - python 3.5.3+
17
+ # - python 3.6+ and pipx
18
18
# - shfmt
19
19
# - shellcheck
20
20
# - cargo, rustfmt (if Rust code exists)
@@ -69,7 +69,11 @@ check_diff() {
69
69
should_fail=1
70
70
fi
71
71
else
72
- if ! git --no-pager diff --exit-code " $@ " & > /dev/null; then
72
+ local res
73
+ res=$( git --no-pager diff --exit-code --name-only " $@ " || true)
74
+ if [[ -n " ${res} " ]]; then
75
+ warn " please commit changes made by formatter/generator if exists on the following files"
76
+ print_fenced " ${res} " $' \n '
73
77
should_fail=1
74
78
fi
75
79
fi
@@ -119,15 +123,6 @@ check_hidden() {
119
123
sed_rhs_escape () {
120
124
sed ' s/\\/\\\\/g; s/\&/\\\&/g; s/\//\\\//g' <<< " $1"
121
125
}
122
- venv_install_yq () {
123
- if [[ ! -e " ${venv_bin} /yq${exe} " ]]; then
124
- if [[ ! -d .venv ]]; then
125
- " python${py_suffix} " -m venv .venv >&2
126
- fi
127
- info " installing yq to .venv using pip${py_suffix} "
128
- " ${venv_bin} /pip${py_suffix}${exe} " install yq >&2
129
- fi
130
- }
131
126
132
127
if [[ $# -gt 0 ]]; then
133
128
cat << EOF
@@ -137,19 +132,15 @@ EOF
137
132
exit 1
138
133
fi
139
134
140
- exe=' '
141
135
py_suffix=' '
142
136
if type -P python3 > /dev/null; then
143
137
py_suffix=3
144
138
fi
145
- venv_bin=.venv/bin
146
139
yq () {
147
- venv_install_yq
148
- " ${venv_bin} /yq${exe} " " $@ "
140
+ pipx run yq " $@ "
149
141
}
150
142
tomlq () {
151
- venv_install_yq
152
- " ${venv_bin} /tomlq${exe} " " $@ "
143
+ pipx run --spec yq tomlq " $@ "
153
144
}
154
145
case " $( uname -s) " in
155
146
Linux)
@@ -187,8 +178,6 @@ case "$(uname -s)" in
187
178
;;
188
179
MINGW* | MSYS* | CYGWIN* | Windows_NT)
189
180
ostype=windows
190
- exe=.exe
191
- venv_bin=.venv/Scripts
192
181
if type -P jq > /dev/null; then
193
182
# https://github.com/jqlang/jq/issues/1854
194
183
_tmp=$( jq -r .a <<< ' {}' )
@@ -200,12 +189,10 @@ case "$(uname -s)" in
200
189
jq () { command jq " $@ " | tr -d ' \r' ; }
201
190
fi
202
191
yq () {
203
- venv_install_yq
204
- " ${venv_bin} /yq${exe} " " $@ " | tr -d ' \r'
192
+ pipx run yq " $@ " | tr -d ' \r'
205
193
}
206
194
tomlq () {
207
- venv_install_yq
208
- " ${venv_bin} /tomlq${exe} " " $@ " | tr -d ' \r'
195
+ pipx run --spec yq tomlq " $@ " | tr -d ' \r'
209
196
}
210
197
fi
211
198
fi
@@ -219,7 +206,7 @@ exclude_from_ls_files=()
219
206
# - `git submodule status` lists submodules. Use sed to remove the first character indicates status ( |+|-).
220
207
# - `git ls-files --deleted` lists removed files.
221
208
while IFS=$' \n ' read -r line; do exclude_from_ls_files+=(" ${line} " ); done < <( {
222
- find . \! \( -name .git -prune \) \! \( -name target -prune \) \! \( -name .venv -prune \) \! \( -name tmp -prune \) -type l | cut -c3-
209
+ find . \! \( -name .git -prune \) \! \( -name target -prune \) \! \( -name tmp -prune \) -type l | cut -c3-
223
210
git submodule status | sed ' s/^.//' | cut -d' ' -f2
224
211
git ls-files --deleted
225
212
} | LC_ALL=C sort -u)
@@ -242,7 +229,7 @@ if [[ -n "$(ls_files '*.rs')" ]]; then
242
229
info " checking Rust code style"
243
230
check_config .rustfmt.toml " ; consider adding with reference to https://github.com/taiki-e/cargo-hack/blob/HEAD/.rustfmt.toml"
244
231
check_config .clippy.toml " ; consider adding with reference to https://github.com/taiki-e/cargo-hack/blob/HEAD/.clippy.toml"
245
- if check_install cargo jq python3; then
232
+ if check_install cargo jq python3 pipx ; then
246
233
# `cargo fmt` cannot recognize files not included in the current workspace and modules
247
234
# defined inside macros, so run rustfmt directly.
248
235
# We need to use nightly rustfmt because we use the unstable formatting options of rustfmt.
@@ -597,7 +584,7 @@ if [[ -n "${res}" ]]; then
597
584
print_fenced " ${res} " $' \n '
598
585
fi
599
586
# TODO: chmod|chown
600
- res=$( { grep -En ' (^|[^0-9A-Za-z\."' \' ' -])(basename|cat|cd|cp|dirname|ln|ls|mkdir|mv|pushd|rm|rmdir|tee|touch)( +-[0-9A-Za-z]+)* +[^<>\|-]' " ${bash_files[@]} " || true ; } | { grep -Ev ' ^[^ ]+: *(#|//)' || true ; } | LC_ALL=C sort)
587
+ res=$( { grep -En ' (^|[^0-9A-Za-z\."' \' ' -])(basename|cat|cd|cp|dirname|ln|ls|mkdir|mv|pushd|rm|rmdir|tee|touch|kill|trap )( +-[0-9A-Za-z]+)* +[^<>\|-]' " ${bash_files[@]} " || true ; } | { grep -Ev ' ^[^ ]+: *(#|//)' || true ; } | LC_ALL=C sort)
601
588
if [[ -n " ${res} " ]]; then
602
589
error " use \` --\` before path(s): see https://github.com/koalaman/shellcheck/issues/2707 / https://github.com/koalaman/shellcheck/issues/2612 / https://github.com/koalaman/shellcheck/issues/2305 / https://github.com/koalaman/shellcheck/issues/2157 / https://github.com/koalaman/shellcheck/issues/2121 / https://github.com/koalaman/shellcheck/issues/314 for more"
603
590
print_fenced " ${res} " $' \n '
@@ -800,7 +787,7 @@ elif check_install shellcheck; then
800
787
# Exclude SC2096 due to the way the temporary script is created.
801
788
shellcheck_exclude=SC2086,SC2096,SC2129
802
789
info " running \` shellcheck --exclude ${shellcheck_exclude} \` for scripts in .github/workflows/*.yml and **/action.yml"
803
- if check_install jq python3; then
790
+ if check_install jq python3 pipx ; then
804
791
shellcheck_for_gha () {
805
792
local text=$1
806
793
local shell=$2
968
955
if [[ -f .cspell.json ]]; then
969
956
info " spell checking"
970
957
project_dictionary=.github/.cspell/project-dictionary.txt
971
- if check_install npm jq python3; then
958
+ if check_install npm jq python3 pipx ; then
972
959
has_rust=' '
973
960
if [[ -n " $( ls_files ' *Cargo.toml' ) " ]]; then
974
961
has_rust=1
0 commit comments