@@ -14,7 +14,7 @@ cd -- "$(dirname -- "$0")"/..
1414# - git 1.8+
1515# - jq 1.6+
1616# - npm (node 18+)
17- # - python 3.5.3+
17+ # - python 3.6+ and pipx
1818# - shfmt
1919# - shellcheck
2020# - cargo, rustfmt (if Rust code exists)
@@ -69,7 +69,11 @@ check_diff() {
6969 should_fail=1
7070 fi
7171 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 '
7377 should_fail=1
7478 fi
7579 fi
@@ -119,15 +123,6 @@ check_hidden() {
119123sed_rhs_escape () {
120124 sed ' s/\\/\\\\/g; s/\&/\\\&/g; s/\//\\\//g' <<< " $1"
121125}
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- }
131126
132127if [[ $# -gt 0 ]]; then
133128 cat << EOF
@@ -137,19 +132,15 @@ EOF
137132 exit 1
138133fi
139134
140- exe=' '
141135py_suffix=' '
142136if type -P python3 > /dev/null; then
143137 py_suffix=3
144138fi
145- venv_bin=.venv/bin
146139yq () {
147- venv_install_yq
148- " ${venv_bin} /yq${exe} " " $@ "
140+ pipx run yq " $@ "
149141}
150142tomlq () {
151- venv_install_yq
152- " ${venv_bin} /tomlq${exe} " " $@ "
143+ pipx run --spec yq tomlq " $@ "
153144}
154145case " $( uname -s) " in
155146 Linux)
@@ -187,8 +178,6 @@ case "$(uname -s)" in
187178 ;;
188179 MINGW* | MSYS* | CYGWIN* | Windows_NT)
189180 ostype=windows
190- exe=.exe
191- venv_bin=.venv/Scripts
192181 if type -P jq > /dev/null; then
193182 # https://github.com/jqlang/jq/issues/1854
194183 _tmp=$( jq -r .a <<< ' {}' )
@@ -200,12 +189,10 @@ case "$(uname -s)" in
200189 jq () { command jq " $@ " | tr -d ' \r' ; }
201190 fi
202191 yq () {
203- venv_install_yq
204- " ${venv_bin} /yq${exe} " " $@ " | tr -d ' \r'
192+ pipx run yq " $@ " | tr -d ' \r'
205193 }
206194 tomlq () {
207- venv_install_yq
208- " ${venv_bin} /tomlq${exe} " " $@ " | tr -d ' \r'
195+ pipx run --spec yq tomlq " $@ " | tr -d ' \r'
209196 }
210197 fi
211198 fi
@@ -219,7 +206,7 @@ exclude_from_ls_files=()
219206# - `git submodule status` lists submodules. Use sed to remove the first character indicates status ( |+|-).
220207# - `git ls-files --deleted` lists removed files.
221208while 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-
223210 git submodule status | sed ' s/^.//' | cut -d' ' -f2
224211 git ls-files --deleted
225212} | LC_ALL=C sort -u)
@@ -242,7 +229,7 @@ if [[ -n "$(ls_files '*.rs')" ]]; then
242229 info " checking Rust code style"
243230 check_config .rustfmt.toml " ; consider adding with reference to https://github.com/taiki-e/cargo-hack/blob/HEAD/.rustfmt.toml"
244231 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
246233 # `cargo fmt` cannot recognize files not included in the current workspace and modules
247234 # defined inside macros, so run rustfmt directly.
248235 # We need to use nightly rustfmt because we use the unstable formatting options of rustfmt.
@@ -597,7 +584,7 @@ if [[ -n "${res}" ]]; then
597584 print_fenced " ${res} " $' \n '
598585fi
599586# 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)
601588if [[ -n " ${res} " ]]; then
602589 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"
603590 print_fenced " ${res} " $' \n '
@@ -800,7 +787,7 @@ elif check_install shellcheck; then
800787 # Exclude SC2096 due to the way the temporary script is created.
801788 shellcheck_exclude=SC2086,SC2096,SC2129
802789 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
804791 shellcheck_for_gha () {
805792 local text=$1
806793 local shell=$2
968955if [[ -f .cspell.json ]]; then
969956 info " spell checking"
970957 project_dictionary=.github/.cspell/project-dictionary.txt
971- if check_install npm jq python3; then
958+ if check_install npm jq python3 pipx ; then
972959 has_rust=' '
973960 if [[ -n " $( ls_files ' *Cargo.toml' ) " ]]; then
974961 has_rust=1
0 commit comments