Skip to content

Commit

Permalink
Require fixed version of clang-format (#3454)
Browse files Browse the repository at this point in the history
* Force a fixed required version of clang-format

* Update github action to install clang-format 12 instead of 10

* Update GitHub actions agent OS to Ubuntu 20.04 instead of 18.04

* More verbose CI script
  • Loading branch information
theohax authored Sep 17, 2021
1 parent 75149ef commit 89e6f44
Show file tree
Hide file tree
Showing 13 changed files with 92 additions and 69 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/analyzers.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@ on: [push, pull_request]

jobs:
clang_format:
runs-on: ubuntu-18.04
runs-on: ubuntu-20.04
if: github.event_name == 'push' || github.event.pull_request.head.repo.full_name != github.repository
steps:
- uses: actions/checkout@50fbc622fc4ef5163becd7fab6573eac35f8462e
- name: Installing clang-format 10
- name: Installing clang-format 12
env:
DEBIAN_FRONTEND: noninteractive
run: sudo apt-get install clang-format-10
run: sudo apt-get install clang-format-12
- name: Clang Format
run: ci/check-commit-format.sh

cmake_format:
runs-on: ubuntu-18.04
runs-on: ubuntu-20.04
if: github.event_name == 'push' || github.event.pull_request.head.repo.full_name != github.repository
steps:
- uses: actions/checkout@50fbc622fc4ef5163becd7fab6573eac35f8462e
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/beta_artifacts.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ jobs:
AWS_DEFAULT_REGION: us-east-2

linux_job:
runs-on: ubuntu-18.04
runs-on: ubuntu-20.04
timeout-minutes: 90
steps:
- name: tag
Expand All @@ -66,7 +66,7 @@ jobs:
AWS_DEFAULT_REGION: us-east-2

linux_docker_job:
runs-on: ubuntu-18.04
runs-on: ubuntu-20.04
timeout-minutes: 90
steps:
- name: tag
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
LCOV: 1
COMPILER: gcc
BOOST_ROOT: /tmp/boost
runs-on: ubuntu-18.04
runs-on: ubuntu-20.04
strategy:
matrix:
TEST_USE_ROCKSDB: [0, 1]
Expand Down Expand Up @@ -48,7 +48,7 @@ jobs:
parallel: true
finish:
needs: coverage_test
runs-on: ubuntu-18.04
runs-on: ubuntu-20.04
steps:
- uses: coverallsapp/github-action@8cbef1dea373ebce56de0a14c68d6267baa10b44
with:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/develop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ on:
- develop
jobs:
linux_job:
runs-on: ubuntu-18.04
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@5a4ac9002d0be2fb38bd78e4b4dbde5606d7042f
with:
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/live_artifacts.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ jobs:
AWS_DEFAULT_REGION: us-east-2

linux_job:
runs-on: ubuntu-18.04
runs-on: ubuntu-20.04
timeout-minutes: 90
steps:
- name: tag
Expand All @@ -65,7 +65,7 @@ jobs:
AWS_DEFAULT_REGION: us-east-2

linux_docker_job:
runs-on: ubuntu-18.04
runs-on: ubuntu-20.04
timeout-minutes: 90
steps:
- name: tag
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/test_network_artifacts.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ jobs:
AWS_DEFAULT_REGION: us-east-2

linux_job:
runs-on: ubuntu-18.04
runs-on: ubuntu-20.04
timeout-minutes: 90
steps:
- name: tag
Expand All @@ -66,7 +66,7 @@ jobs:
AWS_DEFAULT_REGION: us-east-2

linux_docker_job:
runs-on: ubuntu-18.04
runs-on: ubuntu-20.04
timeout-minutes: 90
steps:
- name: tag
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ jobs:
COMPILER: [gcc, clang-6]
RELEASE:
- ${{ startsWith(github.ref, 'refs/tags/') }}
runs-on: ubuntu-18.04
runs-on: ubuntu-20.04
env:
COMPILER: ${{ matrix.COMPILER }}
TEST_USE_ROCKSDB: ${{ matrix.TEST_USE_ROCKSDB }}
Expand Down
44 changes: 8 additions & 36 deletions ci/check-commit-format.sh
Original file line number Diff line number Diff line change
@@ -1,44 +1,16 @@
#!/usr/bin/env bash

FOUND=0
set -e

# hard requirement of clang-format 10.0.0
CF_EXECUTABLE='
clang-format-10.0.0
clang-format-10.0
clang-format-10
clang-format
'
source "$(dirname "$BASH_SOURCE")/detect-clang-format.sh"
source "$(dirname "$BASH_SOURCE")/common.sh"

# check different executable strings
for executable in $CF_EXECUTABLE; do
if type -p "$executable" >/dev/null; then
clang_format="$executable"
FOUND=1
break
fi
done
"$REPO_ROOT/ci/update-clang-format"

# alert if not installed
if [ $FOUND == 0 ]; then
echo "clang-format not found, please install 10.0.0 first"
exit 1
fi

# check if old version is found
if ! "$clang_format" --version | grep '10.0.0' &>/dev/null; then
echo "clang-format version 10.0.0 is required, please update it"
exit 1
fi


REPO_ROOT=$(git rev-parse --show-toplevel)

"${REPO_ROOT}/ci/update-clang-format"

RESULT=$(python $REPO_ROOT/ci/git-clang-format.py --diff --extensions "hpp,cpp")
if [ "$RESULT" != "no modified files to format" ] && [ "$RESULT" != "clang-format did not modify any files" ]; then
python $REPO_ROOT/ci/git-clang-format.py --diff --extensions "hpp,cpp"
clang_format_result=$(python "$REPO_ROOT/ci/git-clang-format.py" --diff --extensions "hpp,cpp")
if [[ $clang_format_result != "no modified files to format" ]] &&
[[ $clang_format_result != "clang-format did not modify any files" ]]; then
python "$REPO_ROOT/ci/git-clang-format.py" --diff --extensions "hpp,cpp"
echo
echo "Code formatting differs from expected - please run ci/clang-format-all.sh"
exit 1
Expand Down
17 changes: 7 additions & 10 deletions ci/clang-format-all.sh
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
#!/bin/bash
#!/usr/bin/env bash

set -e

CLANG_FORMAT="clang-format"
if [ $(builtin type -p "$CLANG_FORMAT") ]; then
REPO_ROOT=$(git rev-parse --show-toplevel)
cd "$REPO_ROOT"
./ci/update-clang-format
find nano -iname '*.h' -o -iname '*.hpp' -o -iname '*.cpp' | xargs "$CLANG_FORMAT" -i
else
echo "'$CLANG_FORMAT' could not be detected in your PATH. Do you have it installed?"
fi
source $(dirname $BASH_SOURCE)/detect-clang-format.sh
source $(dirname $BASH_SOURCE)/common.sh

cd "$REPO_ROOT"
./ci/update-clang-format
find nano -iname '*.h' -o -iname '*.hpp' -o -iname '*.cpp' | xargs "$CLANG_FORMAT" -i
18 changes: 13 additions & 5 deletions ci/cmake-format-all.sh
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
#!/bin/bash
#!/usr/bin/env bash

set -e

if ! command -v cmake-format &>/dev/null; then
source "$(dirname "$BASH_SOURCE")/common.sh"

if ! [[ $(builtin type -p cmake-format) ]]; then
echo "pip install cmake-format to continue"
exit 1
fi
REPO_ROOT=$(git rev-parse --show-toplevel)
cd "${REPO_ROOT}"
find "${REPO_ROOT}" -iwholename "${REPO_ROOT}/nano/*/CMakeLists.txt" -o -iwholename "${REPO_ROOT}/CMakeLists.txt" -o -iwholename "${REPO_ROOT}/coverage/CMakeLists.txt" | xargs cmake-format -i

cd "$REPO_ROOT"

find "$REPO_ROOT" -iwholename "$REPO_ROOT/nano/*/CMakeLists.txt" \
-o \
-iwholename "$REPO_ROOT/CMakeLists.txt" \
-o \
-iwholename "$REPO_ROOT/coverage/CMakeLists.txt" \
| xargs -i{} cmake-format -i {}
5 changes: 5 additions & 0 deletions ci/common.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env bash

set -e

REPO_ROOT=$(git rev-parse --show-toplevel)
41 changes: 41 additions & 0 deletions ci/detect-clang-format.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!/usr/bin/env bash

set -e

is_clang_format_usable()
{
if [[ $(builtin type -p $1) ]]; then
local output=$($1 --version)
if [[ $output =~ ^(.)*clang-format\ version\ $2(.)*$ ]]; then
echo "0"
else
echo $output
fi
else
echo "1"
fi
}

CLANG_FORMAT=""
CLANG_FORMAT_VERSION="12"

clang_format_attempts=("clang-format"
"clang-format-$CLANG_FORMAT_VERSION")

for itr in ${clang_format_attempts[@]}; do
result=$(is_clang_format_usable $itr $CLANG_FORMAT_VERSION)
if [[ $result == "0" ]]; then
CLANG_FORMAT=$itr
break
elif [[ $result == "1" ]]; then
continue
else
echo "Detected '$itr' with version '$result' " \
"(different than '$CLANG_FORMAT_VERSION'), skipping it."
fi
done

if [[ -z $CLANG_FORMAT ]]; then
echo "No 'clang-format' of version '$CLANG_FORMAT_VERSION' could be detected in your PATH."
exit 1
fi
8 changes: 4 additions & 4 deletions ci/update-clang-format
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#! /usr/bin/env bash

ci_dir="$(dirname "${BASH_SOURCE[0]}")"
#!/usr/bin/env bash

set -e

cd "${ci_dir}/.."
source "$(dirname "$BASH_SOURCE")/common.sh"

cd "$REPO_ROOT"

retval='1'

Expand Down

0 comments on commit 89e6f44

Please sign in to comment.