Skip to content

Commit

Permalink
Add shellcheck to pre-commit and fix warnings (#772)
Browse files Browse the repository at this point in the history
`shellcheck` is a fast, static analysis tool for shell scripts. It's good at
flagging up unused variables, unintentional glob expansions, and other potential
execution and security headaches that arise from the wonders of `bash` (and
other shlangs).

This PR adds a `pre-commit` hook to run `shellcheck` on all of the `sh-lang`
files in the `ci/` directory, and the changes requested by `shellcheck` to make
the existing files pass the check.

xref: rapidsai/build-planning#135

Authors:
  - Gil Forsyth (https://github.com/gforsyth)

Approvers:
  - Vyas Ramasubramani (https://github.com/vyasr)

URL: #772
  • Loading branch information
gforsyth authored Feb 10, 2025
1 parent e1eb5fb commit d3d9a6b
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 13 deletions.
6 changes: 6 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,12 @@ repos:
meta[.]yaml$
- id: verify-codeowners
args: [--fix, --project-prefix=rapids, --no-cpp, --no-python]
- repo: https://github.com/shellcheck-py/shellcheck-py
rev: v0.10.0.1
hooks:
- id: shellcheck
args: ["--severity=warning"]
files: ^ci/

default_language_version:
python: python3
3 changes: 2 additions & 1 deletion ci/build_docs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ conda activate docs
rapids-print-env

export RAPIDS_VERSION_NUMBER="25.04"
export RAPIDS_DOCS_DIR="$(mktemp -d)"
RAPIDS_DOCS_DIR="$(mktemp -d)"
export RAPIDS_DOCS_DIR

rapids-logger "Build Sphinx docs"
pushd docs
Expand Down
8 changes: 4 additions & 4 deletions ci/checks/run-cmake-format.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash

# Copyright (c) 2021-2023, NVIDIA CORPORATION.
# Copyright (c) 2021-2025, NVIDIA CORPORATION.

# This script is a wrapper for cmakelang that may be used with pre-commit. The
# wrapping is necessary because RAPIDS libraries split configuration for
Expand All @@ -25,7 +25,7 @@
# Usage:
# bash run-cmake-format.sh {cmake-format,cmake-lint} infile [infile ...]

RAPIDS_CMAKE_ROOT="$(realpath $(dirname $0)/../..)"
RAPIDS_CMAKE_ROOT="$(realpath "$(dirname "$0")"/../..)"
DEFAULT_RAPIDS_CMAKE_FORMAT_FILE="${RAPIDS_CMAKE_ROOT}/cmake-format-rapids-cmake.json"

if [ -z ${RAPIDS_CMAKE_FORMAT_FILE:+PLACEHOLDER} ]; then
Expand All @@ -47,13 +47,13 @@ if [[ $1 == "cmake-format" ]]; then
# We cannot pass multiple input files because of a bug in cmake-format.
# See: https://github.com/cheshirekow/cmake_format/issues/284
for cmake_file in "${@:2}"; do
cmake-format --in-place --first-comment-is-literal --config-files ${RAPIDS_CMAKE_FORMAT_FILE} ${RAPIDS_CMAKE_ROOT}/ci/checks/cmake_config_format.json -- ${cmake_file}
cmake-format --in-place --first-comment-is-literal --config-files "${RAPIDS_CMAKE_FORMAT_FILE}" "${RAPIDS_CMAKE_ROOT}"/ci/checks/cmake_config_format.json -- "${cmake_file}"
done
elif [[ $1 == "cmake-lint" ]]; then
# Since the pre-commit hook is verbose, we have to be careful to only
# present cmake-lint's output (which is quite verbose) if we actually
# observe a failure.
OUTPUT=$(cmake-lint --config-files ${RAPIDS_CMAKE_FORMAT_FILE} ${RAPIDS_CMAKE_ROOT}/ci/checks/cmake_config_format.json ${RAPIDS_CMAKE_ROOT}/ci/checks/cmake_config_lint.json -- ${@:2})
OUTPUT=$(cmake-lint --config-files "${RAPIDS_CMAKE_FORMAT_FILE}" "${RAPIDS_CMAKE_ROOT}"/ci/checks/cmake_config_format.json "${RAPIDS_CMAKE_ROOT}"/ci/checks/cmake_config_lint.json -- "${@:2}")
status=$?

if ! [ ${status} -eq 0 ]; then
Expand Down
12 changes: 4 additions & 8 deletions ci/release/update-version.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/bash
# Copyright (c) 2021-2024, NVIDIA CORPORATION.
# Copyright (c) 2021-2025, NVIDIA CORPORATION.
################################
# rapids-cmake Version Updater #
################################
Expand All @@ -14,21 +14,17 @@ NEXT_FULL_TAG=$1

# Get current version
CURRENT_TAG=$(git tag --merged HEAD | grep -xE '^v.*' | sort --version-sort | tail -n 1 | tr -d 'v')
CURRENT_MAJOR=$(echo $CURRENT_TAG | awk '{split($0, a, "."); print a[1]}')
CURRENT_MINOR=$(echo $CURRENT_TAG | awk '{split($0, a, "."); print a[2]}')
CURRENT_PATCH=$(echo $CURRENT_TAG | awk '{split($0, a, "."); print a[3]}')
CURRENT_SHORT_TAG=${CURRENT_MAJOR}.${CURRENT_MINOR}

# Get <major>.<minor> for next version
NEXT_MAJOR=$(echo $NEXT_FULL_TAG | awk '{split($0, a, "."); print a[1]}')
NEXT_MINOR=$(echo $NEXT_FULL_TAG | awk '{split($0, a, "."); print a[2]}')
NEXT_MAJOR=$(echo "$NEXT_FULL_TAG" | awk '{split($0, a, "."); print a[1]}')
NEXT_MINOR=$(echo "$NEXT_FULL_TAG" | awk '{split($0, a, "."); print a[2]}')
NEXT_SHORT_TAG=${NEXT_MAJOR}.${NEXT_MINOR}

echo "Preparing release $CURRENT_TAG => $NEXT_FULL_TAG"

# Inplace sed replace; workaround for Linux and Mac
function sed_runner() {
sed -i.bak ''"$1"'' $2 && rm -f ${2}.bak
sed -i.bak ''"$1"'' "$2" && rm -f "${2}".bak
}

sed_runner 's/'"rapids-cmake-version .*)"'/'"rapids-cmake-version ${NEXT_SHORT_TAG})"'/g' RAPIDS.cmake
Expand Down

0 comments on commit d3d9a6b

Please sign in to comment.