tools: Update tidy.sh

This commit is contained in:
Taiki Endo
2026-03-29 02:56:38 +09:00
parent 0fde6d128a
commit 3eeb0f944d

View File

@@ -7,13 +7,13 @@ trap -- 'printf >&2 "%s\n" "${0##*/}: trapped SIGINT"; exit 1' SIGINT
cd -- "$(dirname -- "$0")"/.. cd -- "$(dirname -- "$0")"/..
# USAGE: # USAGE:
# GH_TOKEN=$(gh auth token) ./tools/tidy.sh # GITHUB_TOKEN=$(gh auth token) ./tools/tidy.sh
# #
# Note: This script requires the following tools: # Note: This script requires the following tools:
# - git 1.8+ # - git 1.8+
# - jq 1.6+ # - jq 1.6+
# - npm (node 18+) # - npm (node 18+)
# - python 3.6+, pipx # - python 3.6+, uv
# - shfmt # - shfmt
# - shellcheck # - shellcheck
# - zizmor # - zizmor
@@ -136,8 +136,8 @@ py_suffix=''
if type -P python3 >/dev/null; then if type -P python3 >/dev/null; then
py_suffix=3 py_suffix=3
fi fi
yq() { pipx run yq "$@"; } yq() { uvx yq "$@"; }
tomlq() { pipx run --spec yq tomlq "$@"; } tomlq() { uvx --from yq tomlq "$@"; }
case "$(uname -s)" in case "$(uname -s)" in
Linux) Linux)
if [[ "$(uname -o)" == 'Android' ]]; then if [[ "$(uname -o)" == 'Android' ]]; then
@@ -190,8 +190,8 @@ case "$(uname -s)" in
else else
jq() { command jq "$@" | tr -d '\r'; } jq() { command jq "$@" | tr -d '\r'; }
fi fi
yq() { pipx run yq "$@" | tr -d '\r'; } yq() { uvx yq "$@" | tr -d '\r'; }
tomlq() { pipx run --spec yq tomlq "$@" | tr -d '\r'; } tomlq() { uvx --from yq tomlq "$@" | tr -d '\r'; }
fi fi
fi fi
;; ;;
@@ -248,7 +248,7 @@ if [[ ${#rust_files[@]} -gt 0 ]]; then
info "checking Rust code style" info "checking Rust code style"
check_config .rustfmt.toml "; consider adding with reference to https://github.com/taiki-e/cargo-hack/blob/HEAD/.rustfmt.toml" check_config .rustfmt.toml "; consider adding with reference to https://github.com/taiki-e/cargo-hack/blob/HEAD/.rustfmt.toml"
check_config .clippy.toml "; consider adding with reference to https://github.com/taiki-e/cargo-hack/blob/HEAD/.clippy.toml" check_config .clippy.toml "; consider adding with reference to https://github.com/taiki-e/cargo-hack/blob/HEAD/.clippy.toml"
if check_install cargo jq pipx; then if check_install cargo jq uv; then
# `cargo fmt` cannot recognize files not included in the current workspace and modules # `cargo fmt` cannot recognize files not included in the current workspace and modules
# defined inside macros, so run rustfmt directly. # defined inside macros, so run rustfmt directly.
# We need to use nightly rustfmt because we use the unstable formatting options of rustfmt. # We need to use nightly rustfmt because we use the unstable formatting options of rustfmt.
@@ -833,7 +833,7 @@ elif check_install shellcheck; then
# Exclude SC2096 due to the way the temporary script is created. # Exclude SC2096 due to the way the temporary script is created.
shellcheck_exclude=SC2086,SC2096,SC2129 shellcheck_exclude=SC2086,SC2096,SC2129
info "running \`shellcheck --exclude ${shellcheck_exclude}\` for scripts in .github/workflows/*.yml and **/action.yml" info "running \`shellcheck --exclude ${shellcheck_exclude}\` for scripts in .github/workflows/*.yml and **/action.yml"
if check_install jq python3 pipx; then if check_install jq python3 uv; then
shellcheck_for_gha() { shellcheck_for_gha() {
local text=$1 local text=$1
local shell=$2 local shell=$2
@@ -988,7 +988,8 @@ if [[ ${#zizmor_targets[@]} -gt 0 ]]; then
if [[ "${ostype}" =~ ^(netbsd|openbsd|dragonfly|illumos|solaris)$ ]] && [[ -n "${CI:-}" ]] && ! type -P zizmor >/dev/null; then if [[ "${ostype}" =~ ^(netbsd|openbsd|dragonfly|illumos|solaris)$ ]] && [[ -n "${CI:-}" ]] && ! type -P zizmor >/dev/null; then
warn "this check is skipped on NetBSD/OpenBSD/Dragonfly/illumos/Solaris due to installing zizmor is hard on these platform" warn "this check is skipped on NetBSD/OpenBSD/Dragonfly/illumos/Solaris due to installing zizmor is hard on these platform"
elif check_install zizmor; then elif check_install zizmor; then
# zizmor can also be used via pipx, but old version will be installed if glibc version is old. # zizmor can also be used via uvx, but old version will be installed if glibc version is old.
# Do not use `zizmor -q .` here because it also attempts to check submodules.
IFS=' ' IFS=' '
info "running \`zizmor -q ${zizmor_targets[*]}\`" info "running \`zizmor -q ${zizmor_targets[*]}\`"
IFS=$'\n\t' IFS=$'\n\t'
@@ -1045,7 +1046,7 @@ fi
if [[ -f .cspell.json ]]; then if [[ -f .cspell.json ]]; then
info "spell checking" info "spell checking"
project_dictionary=.github/.cspell/project-dictionary.txt project_dictionary=.github/.cspell/project-dictionary.txt
if check_install npm jq pipx; then if check_install npm jq uv; then
has_rust='' has_rust=''
if [[ -n "$(ls_files '*Cargo.toml')" ]]; then if [[ -n "$(ls_files '*Cargo.toml')" ]]; then
has_rust=1 has_rust=1