diff --git a/.clang-tidy b/.clang-tidy index 474b68ecc..c5809dfc2 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -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: '*' diff --git a/.github/actions/clang_tidy/action.yml b/.github/actions/clang_tidy/action.yml new file mode 100644 index 000000000..c71d6cc2c --- /dev/null +++ b/.github/actions/clang_tidy/action.yml @@ -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 diff --git a/.github/actions/prepare_runner/action.yml b/.github/actions/prepare_runner/action.yml index 33f450cad..886af350c 100644 --- a/.github/actions/prepare_runner/action.yml +++ b/.github/actions/prepare_runner/action.yml @@ -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' }} diff --git a/.github/actions/restore_cache/action.yml b/.github/actions/restore_cache/action.yml index d3aa24a28..efe55421a 100644 --- a/.github/actions/restore_cache/action.yml +++ b/.github/actions/restore_cache/action.yml @@ -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 }} diff --git a/.github/workflows/clang-tidy.yml b/.github/workflows/clang-tidy.yml new file mode 100644 index 000000000..e798de131 --- /dev/null +++ b/.github/workflows/clang-tidy.yml @@ -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