Require fixed version of clang-format (#3454)

* 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
This commit is contained in:
theohax 2021-09-17 14:15:55 +03:00 committed by GitHub
commit 89e6f44f61
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
13 changed files with 92 additions and 69 deletions

View file

@ -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

View file

@ -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
@ -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

View file

@ -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]
@ -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:

View file

@ -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:

View file

@ -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
@ -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

View file

@ -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
@ -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

View file

@ -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 }}

View file

@ -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

View file

@ -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

View file

@ -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
ci/common.sh Normal file
View file

@ -0,0 +1,5 @@
#!/usr/bin/env bash
set -e
REPO_ROOT=$(git rev-parse --show-toplevel)

41
ci/detect-clang-format.sh Normal file
View file

@ -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

View file

@ -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'