diff --git a/.github/workflows/analyzers.yml b/.github/workflows/analyzers.yml index f30a0fa3..22dc8e6a 100644 --- a/.github/workflows/analyzers.yml +++ b/.github/workflows/analyzers.yml @@ -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 diff --git a/.github/workflows/beta_artifacts.yml b/.github/workflows/beta_artifacts.yml index 4f88d957..73025532 100644 --- a/.github/workflows/beta_artifacts.yml +++ b/.github/workflows/beta_artifacts.yml @@ -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 diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml index 18d2d3ae..b0a9f5f3 100644 --- a/.github/workflows/coverage.yml +++ b/.github/workflows/coverage.yml @@ -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: diff --git a/.github/workflows/develop.yml b/.github/workflows/develop.yml index 0350abf8..a556f38f 100644 --- a/.github/workflows/develop.yml +++ b/.github/workflows/develop.yml @@ -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: diff --git a/.github/workflows/live_artifacts.yml b/.github/workflows/live_artifacts.yml index 3fd7b241..f87b98c0 100644 --- a/.github/workflows/live_artifacts.yml +++ b/.github/workflows/live_artifacts.yml @@ -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 diff --git a/.github/workflows/test_network_artifacts.yml b/.github/workflows/test_network_artifacts.yml index ce473cb9..fca13da3 100644 --- a/.github/workflows/test_network_artifacts.yml +++ b/.github/workflows/test_network_artifacts.yml @@ -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 diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 15d07029..51113507 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -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 }} diff --git a/ci/check-commit-format.sh b/ci/check-commit-format.sh index c69a18b4..a9e86492 100755 --- a/ci/check-commit-format.sh +++ b/ci/check-commit-format.sh @@ -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 diff --git a/ci/clang-format-all.sh b/ci/clang-format-all.sh index ee0b013c..c2a06655 100755 --- a/ci/clang-format-all.sh +++ b/ci/clang-format-all.sh @@ -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 diff --git a/ci/cmake-format-all.sh b/ci/cmake-format-all.sh index ea8199c0..c5bde79a 100755 --- a/ci/cmake-format-all.sh +++ b/ci/cmake-format-all.sh @@ -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 {} diff --git a/ci/common.sh b/ci/common.sh new file mode 100644 index 00000000..5205c3a1 --- /dev/null +++ b/ci/common.sh @@ -0,0 +1,5 @@ +#!/usr/bin/env bash + +set -e + +REPO_ROOT=$(git rev-parse --show-toplevel) diff --git a/ci/detect-clang-format.sh b/ci/detect-clang-format.sh new file mode 100644 index 00000000..cc2831e2 --- /dev/null +++ b/ci/detect-clang-format.sh @@ -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 diff --git a/ci/update-clang-format b/ci/update-clang-format index 4c285677..56bc73a8 100755 --- a/ci/update-clang-format +++ b/ci/update-clang-format @@ -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'