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