Skip to content

Commit

Permalink
Enforce formatting as part of CI. (open-telemetry#28)
Browse files Browse the repository at this point in the history
  • Loading branch information
g-easy authored Jan 22, 2020
1 parent 5241561 commit 4b9d40b
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 7 deletions.
11 changes: 11 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,16 @@ jobs:
- run: ./ci/install_bazelisk.sh
- run: ./ci/do_ci.sh bazel.asan

format:
resource_class: xlarge
docker:
- image: ubuntu:18.04
steps:
- checkout
- run: ./ci/setup_ci_environment.sh
- run: ./ci/install_format_tools.sh
- run: ./ci/do_ci.sh format

osx_test:
macos:
xcode: "11.0.0"
Expand All @@ -72,5 +82,6 @@ workflows:
- gcc_48_test
- bazel_test
- bazel_asan
- format
- osx_test
- windows
4 changes: 4 additions & 0 deletions .cmake-format.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# If comment markup is enabled, don't reflow the first comment block in
# eachlistfile. Use this to preserve formatting of your
# copyright/licensestatements.
first_comment_is_literal = True
4 changes: 3 additions & 1 deletion ci/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ ADD setup_ci_environment.sh /setup-ci
ADD setup_cmake.sh /setup-ci
ADD install_gcc48.sh /setup-ci
ADD install_bazelisk.sh /setup-ci
ADD install_format_tools.sh /setup-ci

RUN /setup-ci/setup_ci_environment.sh \
&& /setup-ci/setup_cmake.sh \
&& /setup-ci/install_gcc48.sh \
&& /setup-ci/install_bazelisk.sh
&& /setup-ci/install_bazelisk.sh \
&& /setup-ci/install_format_tools.sh
2 changes: 2 additions & 0 deletions ci/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,7 @@
CI tests can be run on docker by invoking the script `./ci/run_docker.sh ./ci/do_ci.sh <TARGET>` where the targets are
* `cmake.test` build cmake targets and run tests
* `bazel.test` build bazel targets and run tests
* `bazel.asan` build bazel targets and run tests with AddressSanitizer
* `format` use `tools/format.sh` to enforce text formatting
Additionally, `./ci/run_docker.sh` can be invoked with no arguments to get a docker shell where tests
can be run manually.
15 changes: 12 additions & 3 deletions ci/do_ci.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,16 @@ elif [[ "$1" == "bazel.test" ]]; then
elif [[ "$1" == "bazel.asan" ]]; then
bazel test --config=asan $BAZEL_TEST_OPTIONS //...
exit 0
else
echo "Invalid do_ci.sh target, see ci/README.md for valid targets."
exit 1
elif [[ "$1" == "format" ]]; then
tools/format.sh
CHANGED="$(git ls-files --modified)"
if [[ ! -z "$CHANGED" ]]; then
echo "The following files have changes:"
echo "$CHANGED"
exit 1
fi
exit 0
fi

echo "Invalid do_ci.sh target, see ci/README.md for valid targets."
exit 1
7 changes: 7 additions & 0 deletions ci/install_format_tools.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash

set -e

apt install -y clang-format-8 python3-pip golang git
pip3 install cmake_format==0.6.5
go get github.com/bazelbuild/buildtools/buildifier
12 changes: 9 additions & 3 deletions tools/format.sh
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,15 @@ else
echo " pip install --user cmake_format"
fi

if which buildifier >/dev/null; then
echo "Running buildifier."
buildifier $($FIND -name WORKSPACE -print -o -name BUILD -print -o \
if [[ -z "$BUILDIFIER" ]]; then
BUILDIFIER="$HOME/go/bin/buildifier"
if ! which "$BUILDIFIER" >/dev/null; then
BUILDIFIER=buildifier
fi
fi
if which "$BUILDIFIER" >/dev/null; then
echo "Running $BUILDIFIER"
"$BUILDIFIER" $($FIND -name WORKSPACE -print -o -name BUILD -print -o \
-name '*.bzl' -print)
else
echo "Can't find buildifier. It can be installed with:"
Expand Down

0 comments on commit 4b9d40b

Please sign in to comment.