Clang-tidy warning: "Could not find conditions to run tool clang-tidy"

Hello,

I’m using Codacy Analysis CLI GitHub Action to run client-side tools (clang-tidy in this case), here’s my codacy-analysis.yml:

name: Codacy Analysis CLI

on:
  push:
    branches: [main]
  pull_request:
    branches: [main]

jobs:
  codacy-analysis-cli:
    name: Codacy Analysis CLI
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2

      - name: Run Codacy Analysis CLI
        uses: codacy/codacy-analysis-cli-action@master
        with:
          tool: clang-tidy
          project-token: ${{ secrets.CODACY_PROJECT_TOKEN }}
          upload: true
          max-allowed-issues: 2147483647
          clang-tidy-output: "clang-tidy-output"

The output of the github action seems to be valid:

> Run codacy/codacy-analysis-cli-action@master
+ '[' '' == true ']'
+ echo 'Skipping GoSec'
Skipping GoSec
+ '[' '' == true ']'
+ echo 'Skipping StaticCheck'
Skipping StaticCheck
+ '[' -n clang-tidy-output ']'
+ cd /tmp
+ grep browser_download_url
+ xargs -L 1 curl -fsSL -o /tmp/codacy-clang-tidy
+ cut -d '"' -f 4
+ curl -fsSL https://api.github.com/repos/codacy/codacy-clang-tidy/releases/latest
+ grep -v 'browser_download_url.*jar'
+ chmod +x /tmp/codacy-clang-tidy
/home/runner/work/Chess/Chess
+ cd -
+ /tmp/codacy-clang-tidy
+ '[' true = true ']'
+ curl -XPOST -L -H 'project-token: ***' -H 'Content-type: application/json' --data-binary @/tmp/codacy-out.json https://api.codacy.com/2.0/gh/TurtleSmoke/Chess/commit/84741788f113f5d5b524c4216c734ab87df8d21e/issuesRemoteResults
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed

  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
100  1926  100    44  100  1882     89   3848 --:--:-- --:--:-- --:--:--  3946
{"success":"Results received successfully."}
+ '[' -n '' ']'
Skipping Faux Pas
+ echo 'Skipping Faux Pas'
--2021-08-15 13:37:54--  https://raw.githubusercontent.com/codacy/codacy-analysis-cli/7.0.0/bin/codacy-analysis-cli.sh
Resolving raw.githubusercontent.com (raw.githubusercontent.com)... 185.199.110.133, 185.199.111.133, 185.199.108.133, ...
Connecting to raw.githubusercontent.com (raw.githubusercontent.com)|185.199.110.133|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 3107 (3.0K) [text/plain]
Saving to: ‘STDOUT’

     0K ...                                                   100% 23.0M=0s

2021-08-15 13:37:55 (23.0 MB/s) - written to stdout [3107/3107]

Unable to find image 'codacy/codacy-analysis-cli:7.0.0' locally
7.0.0: Pulling from codacy/codacy-analysis-cli
e7c96db7181b: Pulling fs layer
f910a506b6cb: Pulling fs layer
b6abafe80f63: Pulling fs layer
53b306f43648: Pulling fs layer
ec3463ff97d0: Pulling fs layer
11c06604ee9a: Pulling fs layer
53b306f43648: Waiting
ec3463ff97d0: Waiting
11c06604ee9a: Waiting
f910a506b6cb: Verifying Checksum
f910a506b6cb: Download complete
e7c96db7181b: Verifying Checksum
e7c96db7181b: Download complete
ec3463ff97d0: Verifying Checksum
ec3463ff97d0: Download complete
e7c96db7181b: Pull complete
b6abafe80f63: Verifying Checksum
b6abafe80f63: Download complete
11c06604ee9a: Verifying Checksum
11c06604ee9a: Download complete
f910a506b6cb: Pull complete
53b306f43648: Verifying Checksum
53b306f43648: Download complete
b6abafe80f63: Pull complete
53b306f43648: Pull complete
ec3463ff97d0: Pull complete
11c06604ee9a: Pull complete
Digest: sha256:2d985dc736bca9c6e82c6da824d1212489c032ab1f497caba066bb09ac03eed7
Status: Downloaded newer image for codacy/codacy-analysis-cli:7.0.0
Starting analysis ...
Analysis complete
Uploading results for gh/TurtleSmoke/Chess commit 84741788f113f5d5b524c4216c734ab87df8d21e
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed

  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
100    55  100    55    0     0    170      0 --:--:-- --:--:-- --:--:--   170
{"success":"Final notification received successfully."}

But when I look at the codacy website, in the commit category, everything is fine except clang-tidy:

Could not find conditions to run tool clang-tidy

I also tried to follow the codacy-clang-tidy guide but the issue was the same.

Does anyone have an answer?

Hey there, there are a couple things that we need to clarify and align before moving forward. As you saw when adding clang-tidy-output field, this is a special tool that only runs on the cli-action, but not as part of the CLI itself. Quoting the document that you mentioned:

Due to the complex orchestration of the tools Clang-Tidy and Faux Pas, in this case the action can receive instead the output files of the tools and uploads them to Codacy

When you specified tool: clang-tidy the analysis-cli will try to warn you on the UI that it was not able to run it, because the CLI is not ready to run that tool. Meaning that this action does not run clang-tidy, this action grabs clang-tidy output, convert it to Codacy format, and uploads it.

That said, in practice, what you need to pass to the action is:

  • clang-tidy-output: The path to the output of your run of clang-tidy
  • project-token: The project token that you already have defined
  • upload: true So it uploads to Codacy
  • run-docker-tools: "false" So it does not run the analysis-cli

Meaning that, if you want to parse and upload the results of your run of clang-tidy, you can rely on this action with those fields. So please make sure that:

  • You remove the tool: clang-tidy
  • The path that you pass to the clang-tidy-output is a valid output of clang-tidy

Let us know how it goes.

2 Likes

First of all, thank you for your reply and sorry for the late reply.

When you specified tool: clang-tidy the analysis-cli will try to warn you on the UI that it was not able to run it, because the CLI is not ready to run that tool. Meaning that this action does not run clang-tidy, this action grabs clang-tidy output, convert it to Codacy format, and uploads it .

I have already tried without this option, and the result is the following error:

Could not find conditions to run tool clang-tidy

But adding:

run-docker-tools: "false"

Resolve the problem. I thought that adding this line would remove all other checks, but it seems that is not the case.

Actually, I no longer have any error with clang-tidy (Thank you :D), but something is bothering me. Even if clang-tidy returns errors, they are not displayed on the website. Using codacy-clang-tidy-1.2.5 gives the following output:

[{“tool”:“clang-tidy”,“issues”:{“Success”:{“results”:[{“filename”:“test/test.cc”,“results”:[{“Issue”:{“patternId”:{“value”:“ClangTidy_cppcoreguidelines-owning-memory”},“filename”:“test/test.cc”,“message”:{“text”:“initializing non-owner argument of type ‘testing::internal::TestFactoryBase *’ with a newly created ‘gsl::owner<>’”},“level”:“Error”,“location”:{“FullLocation”:{“line”:3,“column”:1}}}},{“Issue”:{“patternId”:{“value”:“ClangTidy_fuchsia-default-arguments-calls”},“filename”:“test/test.cc”,“message”:{“text”:“calling a function that uses a default argument is disallowed”},“level”:“Error”,“location”:{“FullLocation”:{“line”:3,“column”:1}}}},{“Issue”:{“patternId”:{“value”:“ClangTidy_fuchsia-statically-constructed-objects”},“filename”:“test/test.cc”,“message”:{“text”:“static objects are disallowed; if possible, use a constexpr constructor instead”},“level”:“Error”,“location”:{“FullLocation”:{“line”:3,“column”:1}}}},{“Issue”:{“patternId”:{“value”:“ClangTidy_cert-err58-cpp”},“filename”:“test/test.cc”,“message”:{“text”:“initialization of ‘test_info_’ with static storage duration may throw an exception that cannot be caught”},“level”:“Error”,“location”:{“FullLocation”:{“line”:3,“column”:1}}}},{“Issue”:{“patternId”:{“value”:“ClangTidy_fuchsia-default-arguments-calls”},“filename”:“test/test.cc”,“message”:{“text”:“calling a function that uses a default argument is disallowed”},“level”:“Error”,“location”:{“FullLocation”:{“line”:4,“column”:5}}}}]}]}}}]```

Even with 5 errors (in fact, they are warning treated as error thanks to the option warnings-as-errors in clang-tidy) it’s considered as a “Success”.

Did I make some mistakes in some configurations?

(Should i create another topic?)

Hey there, glad that we’ve got that working for you, on the action side.

Regarding the issues not appearing, seems that the file that you uploaded had ../../../../../mnt/c/... on the filenames. The uploaded file should look more like that one that you shared on the thread.

As an example using a fork of your repository, if you remove the prefixes of the filenames as done on this commit, fix: Make the paths of the clang-tidy-output relative · troubleshoot-codacy/Chess@ceb54da · GitHub you should be able to see the issues on the Issue view on Codacy side Chess - Codacy - Issues

The issues were indeed due to the absolute path, I could not find an option in clang-tidy to make the path relative. I just had to do it the ninja-way using sed :

sed -i ‘s?`pwd`/’??g’ clang-tidy-output

Thanks again, it works perfectly right now! :smiley: