diff --git a/.tool-versions b/.tool-versions index 1bc6b84c..12e6edce 100644 --- a/.tool-versions +++ b/.tool-versions @@ -13,8 +13,6 @@ golang 1.23.4 # The most common case is nodejs. ## <> # The below tools are used by all repositories when using devbase -shellcheck 0.9.0 -shfmt 3.7.0 goreleaser 1.20.0 terraform 1.4.4 ## <> diff --git a/shell/lib/asdf.sh b/shell/lib/asdf.sh index c7df770e..17a48d59 100644 --- a/shell/lib/asdf.sh +++ b/shell/lib/asdf.sh @@ -58,43 +58,6 @@ asdf_get_version_from_devbase() { grep -E "^$tool_name " "$devbase_dir/.tool-versions" | head -n1 | awk '{print $2}' } -# asdf_devbase_exec runs asdf_devbase_run but execs the command instead -# of running it as a subprocess. -asdf_devbase_exec() { - asdf_tool_env_var "$1" - exec "$@" -} - -# asdf_devbase_run executes a command with the versions from the devbase -# .tool-versions file. This will fail if the tool isn't installed, so callers -# should invoke asdf_devbase_ensure first. -asdf_devbase_run() { - asdf_tool_env_var "$1" - "$@" -} - -# asdf_tool_env_var exports an environment variable to have the provided -# tool version be used in asdf. This mutates the current shell's -# environment variables by exporting the variable. -# -# See: https://asdf-vm.com/manage/versions.html#set-current-version -asdf_tool_env_var() { - local tool="$1" - # Why: We're OK with this being the way it is. - # shellcheck disable=SC2155 - local tool_env_var="$(tr '[:lower:]-' '[:upper:]_' <<<"$tool")" - - # Why: We're OK with this being the way it is. - # shellcheck disable=SC2155 - local version="$(asdf_get_version_from_devbase "$tool")" - if [[ -z $version ]]; then - echo "No version found for $tool in devbase .tool-versions file" - return 1 - fi - - export "ASDF_${tool_env_var}_VERSION"="${version}" -} - # asdf_devbase_ensure ensures that all versions of tools are installed from # .tool-version files in the current directory and all subdirectories. asdf_devbase_ensure() { diff --git a/shell/lib/mise.sh b/shell/lib/mise.sh index 65c3ca0a..da74c9f2 100644 --- a/shell/lib/mise.sh +++ b/shell/lib/mise.sh @@ -252,6 +252,14 @@ mise_exec_tool_with_bin() { shift local binName="$1" shift + + # asdf shims take precedence in the PATH, + # so remove it in CI before execution. + local asdfShim="${ASDF_DIR:-$HOME/.asdf}/shims/$binName" + if in_ci_environment && [[ -f $asdfShim ]]; then + rm "$asdfShim" + fi + local version version="$(get_tool_version "$binName")" MISE_GITHUB_TOKEN=$(github_token) run_mise exec "$toolName@$version" -- "$binName" "$@" diff --git a/shell/linters/bash.sh b/shell/linters/bash.sh index 9d982531..03468fa1 100644 --- a/shell/linters/bash.sh +++ b/shell/linters/bash.sh @@ -16,15 +16,19 @@ find_shell_files() { } shellcheck_linter() { - find_shell_files | xargs -n40 "$SHELLCHECKPATH" -x -P SCRIPTDIR + # Wrapper script already sets external sources & script directory + # source path. + find_shell_files | xargs -n40 "$SHELLCHECKPATH" } shellfmt_linter() { - find_shell_files | xargs -n40 "$SHELLFMTPATH" -s -d + # Wrapper script already sets --simplify + find_shell_files | xargs -n40 "$SHELLFMTPATH" --diff } shellfmt_formatter() { - find_shell_files | xargs -n40 "$SHELLFMTPATH" -w -l + # Wrapper script already sets --simplify + find_shell_files | xargs -n40 "$SHELLFMTPATH" --write --list } linter() { diff --git a/shell/shellcheck.sh b/shell/shellcheck.sh index 7b9903be..2f68b1b0 100755 --- a/shell/shellcheck.sh +++ b/shell/shellcheck.sh @@ -1,14 +1,15 @@ #!/usr/bin/env bash -# This is a wrapper around asdf to run shellcheck. +# This is a wrapper around mise to run shellcheck. # Useful for using the correct version of shellcheck # with your editor. set -e DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)" -# shellcheck source=./lib/asdf.sh -source "$DIR/lib/asdf.sh" +# shellcheck source=./lib/mise/stub.sh +source "$DIR/lib/mise/stub.sh" # Always set the correct script directory. -args=("-P" "SCRIPTDIR" "-x" "$@") -asdf_devbase_exec shellcheck "${args[@]}" +args=(--external-sources --source-path=SCRIPTDIR "$@") + +mise_exec_tool shellcheck "${args[@]}" diff --git a/shell/shfmt.sh b/shell/shfmt.sh index 6faa653c..73a655c8 100755 --- a/shell/shfmt.sh +++ b/shell/shfmt.sh @@ -1,15 +1,15 @@ #!/usr/bin/env bash -# This is a wrapper around asdf to run shfmt. +# This is a wrapper around mise to run shfmt. # Useful for using the correct version of shfmt # with your editor. set -e DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)" -# shellcheck source=./lib/asdf.sh -source "$DIR/lib/asdf.sh" +# shellcheck source=./lib/mise/stub.sh +source "$DIR/lib/mise/stub.sh" # Always set simplify mode. -args=("-s" "$@") +args=("--simplify" "$@") -asdf_devbase_exec shfmt "${args[@]}" +mise_exec_tool shfmt "${args[@]}" diff --git a/versions.yaml b/versions.yaml index ea8c35cc..d1d5b403 100644 --- a/versions.yaml +++ b/versions.yaml @@ -13,6 +13,9 @@ mage: 1.14.0 ## Sync with templates/scripts/devbase.sh.tpl gojq: v0.12.18 +shellcheck: 0.9.0 +shfmt: 3.7.0 + # protobuf formatters/plugins/tools/etc buf: 1.60.0 protoc-gen-validate: 0.6.7