1#!/usr/bin/env bash 2# Copyright 2023 Code Intelligence GmbH 3# 4# Licensed under the Apache License, Version 2.0 (the "License"); 5# you may not use this file except in compliance with the License. 6# You may obtain a copy of the License at 7# 8# http://www.apache.org/licenses/LICENSE-2.0 9# 10# Unless required by applicable law or agreed to in writing, software 11# distributed under the License is distributed on an "AS IS" BASIS, 12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13# See the License for the specific language governing permissions and 14# limitations under the License. 15 16 17set -euo pipefail 18 19THIS_DIR="$(pwd -P)" 20 21# Licence headers 22bazel run --config=quiet //:addlicense -- -c "Code Intelligence GmbH" -ignore '**/third_party/**' -ignore '**/.github/**' "$THIS_DIR" 23 24# C++ & Java 25find "$THIS_DIR" \( -name '*.cpp' -o -name '*.c' -o -name '*.h' -o -name '*.java' \) -print0 | xargs -0 bazel run --config=quiet //:clang-format -- -i 26 27# No need to run in CI as these formatters have corresponding Bazel tests. 28if [[ "${CI:-0}" == 0 ]]; then 29 # Kotlin 30 # Check which ktlint_tests failed and run the corresponding fix targets. This is much faster than 31 # running all ktlint_fix targets when e.g. only a few or no .kt files changed. 32 # shellcheck disable=SC2046 33 TARGETS_TO_RUN=$(bazel test --config=quiet $(bazel query --config=quiet 'kind(ktlint_test, //...)') | { grep FAILED || true; } | cut -f1 -d' ' | sed -e 's/:ktlint_test/:ktlint_fix/g') 34 if [[ -n "${TARGETS_TO_RUN}" ]]; then 35 echo "$TARGETS_TO_RUN" | xargs -n 1 bazel run --config=quiet 36 fi 37 38 # BUILD files 39 bazel run --config=quiet //:buildifier -- -r "$THIS_DIR" 40fi 41