Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add lint helper scripts #7

Merged
merged 6 commits into from
Jun 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 13 additions & 33 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,37 +8,18 @@ on:

env:
BUILD_TYPE: Release
BUILD_PATH: ${{ github.workspace}}/build
BUILD_PATH: build
BASE_TAG: ci-${{ github.run_id }}

jobs:
check-format:
name: Formatting Check
runs-on: ubuntu-latest
strategy:
matrix:
path:
- 'benchmark'
- 'include'
- 'src'
- 'test'
steps:
- uses: actions/checkout@v3

- name: Run clang-format style check for C/C++ programs.
uses: jidicula/clang-format-action@v4.10.2
with:
clang-format-version: '15'
check-path: ${{ matrix.path }}

build-image:
runs-on: ubuntu-latest
outputs:
image_name: ${{ steps.generate_docker_image_name.outputs.image_name}}
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- uses: docker/login-action@v2
- uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
Expand All @@ -55,8 +36,10 @@ jobs:
run: docker compose build base

- name: Push Docker Image
run: docker compose push base
run: docker compose push base

# TODO: Separate the build job into separate jobs, build, test, benchmark and lint-check
# after resolved the issue https://github.com/actions/upload-artifact/issues/38.
build:
needs: build-image
runs-on: ubuntu-latest
Expand All @@ -65,23 +48,20 @@ jobs:
credentials:
username: ${{ github.actor }}
password: ${{ secrets.github_token }}

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Configure CMake
run: cmake -B ${{env.BUILD_PATH}} -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -GNinja

- name: Build
run: |
ls ${{env.BUILD_PATH}}
cmake --build ${{env.BUILD_PATH}} --config ${{env.BUILD_TYPE}}

run: cmake --build ${{env.BUILD_PATH}} --config ${{env.BUILD_TYPE}}

- name: Test
run: ctest --test-dir ${{env.BUILD_PATH}} -C ${{env.BUILD_TYPE}}

- name: Linter
run: find . -type f -name "*.h" -not -path '${{env.BUILD_PATH}}/*' -or -name "*.cc" -not -path '${{env.BUILD_PATH}}/*' | xargs clang-tidy -p ${{env.BUILD_PATH}}

- name: Benchmark
run: ${{env.BUILD_PATH}}/bin/cpp-template_benchmark
run: ${{ env.BUILD_PATH }}/bin/cpp-template_benchmark

- name: Lint check
run: ./scripts/lint/check_all.sh ${{ env.BUILD_PATH }}
21 changes: 10 additions & 11 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,27 +58,26 @@ build:release:
#
# Lint
#
lint:clang-format:
.lint_base:
stage: lint
needs:
- job: build:release
artifacts: true

lint:clang-format:
extends: .lint_base
script:
- find . -type f -name "*.h" -not -path './build/*' -or -name "*.cc" -not -path './build/*' | xargs clang-format --dry-run -Werror
- ./scripts/lint/check_clang_format.sh

lint:clang-tidy:
stage: lint
needs:
- job: build:release
artifacts: true
extends: .lint_base
script:
- find . -type f -name "*.h" -not -path './build/*' -or -name "*.cc" -not -path './build/*' | xargs clang-tidy -p build
- ./scripts/lint/check_clang_tidy.sh build

lint:cmake-format:
stage: lint
needs:
- job: build:release
extends: .lint_base
script:
- find . -type f -name "CMakeLists.txt" -not -path './build/*' -or -name "*.cmake" -not -path './build/*' | xargs cmake-format --check
- ./scripts/lint/check_cmake_format.sh


#
Expand Down
2 changes: 1 addition & 1 deletion docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#
# base image
#
FROM ubuntu:22.04 AS base
FROM --platform=linux/amd64 ubuntu:22.04 AS base

ENV DEBIAN_FRONTEND=noninteractive
ENV LANG C.UTF-8
Expand Down
1 change: 1 addition & 0 deletions docker/install/install_llvm.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,4 @@ update-alternatives --install /usr/bin/clang++ clang++ /usr/bin/clang++-${major}
update-alternatives --install /usr/bin/clang-format clang-format /usr/bin/clang-format-${major} 1
update-alternatives --install /usr/bin/clangd clangd /usr/bin/clangd-${major} 1
update-alternatives --install /usr/bin/clang-tidy clang-tidy /usr/bin/clang-tidy-${major} 1
update-alternatives --install /usr/bin/run-clang-tidy run-clang-tidy /usr/bin/run-clang-tidy-${major} 1
15 changes: 15 additions & 0 deletions scripts/lint/check_all.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/bash
set -euo pipefail

if [ $# != 1 ]; then
echo "Error: Not specified <build_dir>"
echo "Usage: $0 <build_dir>"
exit 1
fi

SCRIPT_DIR=$(cd $(dirname $0); pwd)
BUILD_DIR=$1

${SCRIPT_DIR}/check_clang_format.sh
${SCRIPT_DIR}/check_clang_tidy.sh ${BUILD_DIR}
${SCRIPT_DIR}/check_cmake_format.sh
12 changes: 12 additions & 0 deletions scripts/lint/check_clang_format.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/bash
set -euo pipefail

SCRIPT_DIR=$(cd $(dirname $0); pwd)
PROJECT_DIR=${SCRIPT_DIR}/../../

find \
${PROJECT_DIR}/benchmark \
${PROJECT_DIR}/include \
${PROJECT_DIR}/src \
${PROJECT_DIR}/test \
-type f -name "*.h" -o -name "*.cc" | xargs clang-format --dry-run -Werror
22 changes: 22 additions & 0 deletions scripts/lint/check_clang_tidy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/bin/bash
set -euo pipefail

if [ $# != 1 ]; then
echo "Error: Not specified <build_dir>"
echo "Usage: $0 <build_dir>"
exit 1
fi

SCRIPT_DIR=$(cd $(dirname $0); pwd)
PROJECT_DIR=${SCRIPT_DIR}/../../
BUILD_DIR=$1
JOBS=8

FILES=`find \
benchmark \
include \
src \
test \
-type f -name "*.h" -o -name "*.cc"`

run-clang-tidy -config-file=${PROJECT_DIR}/.clang-tidy -j ${JOBS} -p ${BUILD_DIR} ${FILES}
13 changes: 13 additions & 0 deletions scripts/lint/check_cmake_format.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/bash
set -euo pipefail

SCRIPT_DIR=$(cd $(dirname $0); pwd)
PROJECT_DIR=${SCRIPT_DIR}/../../

cmake-format --check CMakeLists.txt
find \
${PROJECT_DIR}/benchmark \
${PROJECT_DIR}/include \
${PROJECT_DIR}/src \
${PROJECT_DIR}/test \
-type f -name "CMakeLists.txt" -o -name "*.cmake" | xargs cmake-format --check