Skip to content

Commit

Permalink
Add clang-tidy workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
kuznetsss committed Dec 7, 2023
1 parent e863739 commit 0740956
Show file tree
Hide file tree
Showing 5 changed files with 103 additions and 3 deletions.
4 changes: 2 additions & 2 deletions .clang-tidy
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,8 @@ CheckOptions:
readability-braces-around-statements.ShortStatementLines: 2
bugprone-unsafe-functions.ReportMoreUnsafeFunctions: true
bugprone-unused-return-value.CheckedReturnTypes: ::std::error_code;::std::error_condition;::std::errc;::std::expected
misc-include-cleaner.IgnoreHeaders: ".*/(detail|impl)/.*"
misc-include-cleaner.IgnoreHeaders: '.*/(detail|impl)/.*'

HeaderFilterRegex: '^.*/(src|unitests)/.*\.(h|hpp)$'
HeaderFilterRegex: '^.*/(src|unittests)/.*\.(h|hpp)$'
WarningsAsErrors: '*'

51 changes: 51 additions & 0 deletions .github/actions/clang_tidy/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name: Run clang-tidy
description: Build clio in build directory
runs:
using: composite
steps:
- name: Get number of threads
uses: ./.github/actions/get_number_of_threads
id: number_of_threads

- name: Run clang-tidy
shell: bash
id: run_clang_tidy
run: |
run-clang-tidy -p build -j ${{ steps.number_of_threads.outputs.threads_number }} -fix -quiet 1>output.txt
if [[ "$?" != 0 ]]; then
echo 'clang_tidy_failed=true' >> $GITHUB_OUTPUT
fi
sed -i '/error\||/!d' ./output.txt
- name: Print issues found
shell: bash
run: cat output.txt

- name: Create an issue
if: ${{ steps.run_clang_tidy.outputs.clang_tidy_failed == 'true' }}
id: create_issue
shell: bash
run: |
echo -e 'Clang-tidy found issues in the code:\n' > issue.md
echo -e "List of the issues found: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}/job/${{ gihub.job_id }}" >> issue.md
gh issue create --assignee 'cindyyan317,godexsoft,kuznetsss' --label bug --title 'Clang-tidy found bugs in code🐛' --body-file ./issue.md > create_issue.log
created_issue=$(cat create_issue.log | sed 's|.*/||')
echo "created_issue=$created_issue" >> $GITHUB_OUTPUT
- name: Create PR with fixes
if: ${{ steps.run_clang_tidy.outputs.clang_tidy_failed == 'true' }}
uses: peter-evans/create-pull-request@v5
with:
commit-message: '[CI]: clang-tidy auto fixes'
branch: 'clang_tidy/autofix'
branch-suffix: timestamp
delete-branch: true
title: '[CI]: clang-tidy auto fixes'
body: 'Fixes #${{ steps.create_issue.outputs.created_issue }}. Please review and commit clang-tidy fixes'
reviewers: 'cindyyan317,godexsoft,kuznetsss'

- name: Fail the job if issues found
if: ${{ steps.run_clang_tidy.outputs.clang_tidy_failed == 'true' }}
shell: bash
run: exit 1
2 changes: 1 addition & 1 deletion .github/actions/prepare_runner/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ runs:
echo 'deb http://apt.llvm.org/focal/ llvm-toolchain-focal-17 main' >> /etc/apt/sources.list
wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | apt-key add -
apt update -qq
apt install -y jq clang-tidy-17
apt install -y jq clang-tidy-17 clang-tools-17
- name: Install ccache on Linux
if: ${{ runner.os == 'Linux' && inputs.disable_ccache != 'true' }}
Expand Down
1 change: 1 addition & 0 deletions .github/actions/restore_cache/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ runs:
- name: Restore ccache cache
uses: actions/cache/restore@v3
id: ccache_cache
if: ${{ env.CCACHE_DISABLE != '1' }}
with:
path: ${{ inputs.ccache_dir }}
key: clio-ccache-${{ runner.os }}-develop-${{ steps.git_common_ancestor.outputs.commit }}
48 changes: 48 additions & 0 deletions .github/workflows/clang-tidy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
name: Clang-tidy check
on:
schedule:
- cron: '0 6 * * 1-5'
workflow_dispatch:
pull_request:
branches: [develop]

jobs:
build:
runs-on: [self-hosted, Linux]
container:
image: conanio/gcc11:1.61.0
options: --user root
permissions:
contents: write
pull-requests: write

steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Prepare runner
uses: ./.github/actions/prepare_runner
with:
disable_ccache: true

- name: Setup conan
uses: ./.github/actions/setup_conan
id: conan

- name: Restore cache
uses: ./.github/actions/restore_cache
id: restore_cache
with:
conan_dir: ${{ env.CONAN_USER_HOME }}/.conan
ccache_dir: ${{ env.CCACHE_DIR }}

- name: Run conan and cmake
uses: ./.github/actions/generate
with:
conan_profile: ${{ steps.conan.outputs.conan_profile }}
conan_cache_hit: ${{ steps.restore_cache.outputs.conan_cache_hit }}
build_type: Release

- name: Run clang-tidy
uses: ./.github/actions/clang_tidy

0 comments on commit 0740956

Please sign in to comment.