Git Product home page Git Product logo

cpp-linter / cpp-linter-action Goto Github PK

View Code? Open in Web Editor NEW
84.0 4.0 19.0 1.35 MB

A Github Action for linting C/C++ code integrating clang-tidy and clang-format to collect feedback provided in the form of file-annotations, thread-comments, workflow step-summary, and Pull Request reviews.

Home Page: https://cpp-linter.github.io/cpp-linter-action/

License: MIT License

clang-tidy clang-format linter lint static-analysis github-actions hacktoberfest pull-requests push

cpp-linter-action's Introduction

C/C++ Linter Action | clang-format & clang-tidy

GitHub release (latest SemVer) Used by GitHub marketplace cpp-linter MkDocs Deploy GitHub

A Github Action for linting C/C++ code integrating clang-tidy and clang-format to collect feedback provided in the form of file-annotations, thread-comments, workflow step-summary, and Pull Request reviews (with tidy-review or format-review).

Warning

We only support Linux runners using a Debian based Linux OS (like Ubuntu and many others).

MacOS and Windows runners are supported as well.

What's New

v2

  • Change action from using docker to composite steps
    • improve workflow runs times from 1m 24s (using v1) to 6-20s (for simple workflow runs).
    • better support for the database input option (which was broken with the docker environment in v1).
    • better support cross-compilation
    • better support 3rd party libraries
  • Includes many issues and enhancements. See #87 for details.

Refer here for previous versions.

Usage

Note

Python 3.10 needs to be installed in the docker image if your workflow is running jobs in a container (see discussion in #185). Our intention is to synchronize with the default python version included with Ubuntu latest LTS releases.

Create a new GitHub Actions workflow in your project, e.g. at .github/workflows/cpp-linter.yml

The content of the file should be in the following format.

    steps:
      - uses: actions/checkout@v4
      - uses: cpp-linter/cpp-linter-action@v2
        id: linter
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        with:
          style: 'file'  # Use .clang-format config file
          tidy-checks: '' # Use .clang-tidy config file
          # only 'update' a single comment in a pull request's thread.
          thread-comments: ${{ github.event_name == 'pull_request' && 'update' }}
      - name: Fail fast?!
        if: steps.linter.outputs.checks-failed > 0
        run: exit 1

For all explanations of our available input parameters and output variables, see our Inputs and Outputs document.

See also our example recipes.

Example

Annotations

Using file-annotations:

clang-format annotations

clang-format annotations

clang-tidy annotations

clang-tidy annotations

Thread Comment

Using thread-comments:

sample thread-comment

Step Summary

Using step-summary:

step summary

Pull Request Review

Only clang-tidy

Using tidy-review:

sample tidy-review

Only clang-format

Using format-review:

sample format-review

sample format-suggestion

Add C/C++ Linter Action badge in README

You can show C/C++ Linter Action status with a badge in your repository README

Example

[![cpp-linter](https://github.com/cpp-linter/cpp-linter-action/actions/workflows/cpp-linter.yml/badge.svg)](https://github.com/cpp-linter/cpp-linter-action/actions/workflows/cpp-linter.yml)

cpp-linter

Have question or feedback?

To provide feedback (requesting a feature or reporting a bug) please post to issues.

License

The scripts and documentation in this project are released under the MIT License

cpp-linter-action's People

Contributors

2bndy5 avatar artificialamateur avatar carlosala avatar dependabot[bot] avatar dingxuefeng avatar emuplz avatar github-actions[bot] avatar jnooree avatar mirenradia avatar ppizarror avatar shenxianpeng avatar smay1613 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

cpp-linter-action's Issues

use setuptools_scm during install

I've been trying to hold off on this because it will slow the installation of this action in the docker env. But, If we decide to start distributing the python executable script to pypi, then using setuptools_scm will automatically update this action's version during install.

Uploading bdist_wheels to pypi will make installing via pip a little quicker, and this action's version number will be already set when the wheel is uploaded to pypi.

Rename action from "C/C++ Lint Action" to "C/C++ Linter"

I'm wondering whether to change this action's name in the marketplace from "C/C++ Lint Action" to "C/C++ Linter", because the following reasons.

  1. To improve the ranking (A good action should be known)
    When I search in the marketplace with the keyword "lint", our action is on the first page, but when I search with "linter", the action is on the second page, even though we have a higher start, from the search results, it should be because of not a linter in the name. (see screenshots below)
  2. Word "linter" seems used more than "lint" in the marketplace
  3. The action name and the organization name use the same suffix - linter

I also want to update the action's description

  • From "Automatically checks push & PR changes with clang-format & clang-tidy, then post annotations/comments with faulty results."
  • To "Automatically checks push/pull request changes with clang-format/clang-tidy then post annotations/comments with faulty results."

Because "&" cannot be displayed in the marketplace. Or use the following description from README to make difference with other actions forked from ArtificialAmateur/cpp-linter-action

  • "Linting C/C++ code integrating clang-tidy and clang-format to collect feedback provided in the form of thread comments and/or annotations"

screenshots

Search with "lint", our action is on page 1

image

Search with "linter", on page 1, no our action

image

We are on page 2: https://github.com/marketplace?page=2&q=linter&query=linter&type=actions

image

header file not found

I see. Thanks for answer. Thanks for this action and your time to support!

Meanwhile, I run into another issue with regard to clang tidy's database (I'm not sure to open another issue - it's at yours). My action looks like

    - name: clang-format & clang-tidy
      uses: cpp-linter/[email protected]
      id: linter
      env:
        GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
      with:
        style: file
        version: 14
        # directory containing compilation database (compile_commands.json)
        database: build/ci-linux-clang
        # don't use action's default
        tidy-checks: ''

where CMakePresets.json contains

    ...
    "configurePresets": [
        {
            "name": "use-ninja",
            "generator": "Ninja",
            "cacheVariables": { "CMAKE_EXPORT_COMPILE_COMMANDS": "ON" }
        },
        {
            "name": "default-dirs",
            "binaryDir": "${sourceDir}/build/${presetName}",
            ...
        },
    ...

The action's log shows that it fails:

Run cpp-linter/[email protected]
/usr/bin/docker run --name f1554a9d49084b68a4119971e2b6f8bf850d2_02701c --label 6f1554 --workdir /github/workspace --rm -e CONAN_V2_MODE -e GITHUB_TOKEN -e INPUT_STYLE -e INPUT_VERSION -e INPUT_DATABASE -e INPUT_TIDY-CHECKS -e INPUT_THREAD-COMMENTS -e INPUT_EXTENSIONS -e INPUT_REPO-ROOT -e INPUT_VERBOSITY -e INPUT_LINES-CHANGED-ONLY -e INPUT_FILES-CHANGED-ONLY -e INPUT_IGNORE -e HOME -e GITHUB_JOB -e GITHUB_REF -e GITHUB_SHA -e GITHUB_REPOSITORY -e GITHUB_REPOSITORY_OWNER -e GITHUB_RUN_ID -e GITHUB_RUN_NUMBER -e GITHUB_RETENTION_DAYS -e GITHUB_RUN_ATTEMPT -e GITHUB_ACTOR -e GITHUB_WORKFLOW -e GITHUB_HEAD_REF -e GITHUB_BASE_REF -e GITHUB_EVENT_NAME -e GITHUB_SERVER_URL -e GITHUB_API_URL -e GITHUB_GRAPHQL_URL -e GITHUB_REF_NAME -e GITHUB_REF_PROTECTED -e GITHUB_REF_TYPE -e GITHUB_WORKSPACE -e GITHUB_ACTION -e GITHUB_EVENT_PATH -e GITHUB_ACTION_REPOSITORY -e GITHUB_ACTION_REF -e GITHUB_PATH -e GITHUB_ENV -e GITHUB_STEP_SUMMARY -e RUNNER_OS -e RUNNER_ARCH -e RUNNER_NAME -e RUNNER_TOOL_CACHE -e RUNNER_TEMP -e RUNNER_WORKSPACE -e ACTIONS_RUNTIME_URL -e ACTIONS_RUNTIME_TOKEN -e ACTIONS_CACHE_URL -e GITHUB_ACTIONS=true -e CI=true -v "/var/run/docker.sock":"/var/run/docker.sock" -v "/home/runner/work/_temp/_github_home":"/github/home" -v "/home/runner/work/_temp/_github_workflow":"/github/workflow" -v "/home/runner/work/_temp/_runner_file_commands":"/github/file_commands" -v "/home/runner/work/gh-actions-test/gh-actions-test":"/github/workspace" 6f1554:a9d49084b68a4119971e2b6f8bf850d2  "--style=file" "--extensions=c,h,C,H,cpp,hpp,cc,hh,c++,h++,cxx,hxx" "--tidy-checks=" "--repo-root=." "--version=14" "--verbosity=10" "--lines-changed-only=false" "--files-changed-only=true" "--thread-comments=false" "--ignore=.github" "--database=build/ci-linux-clang"
INFO:CPP Linter:Ignoring the following paths/files:
	./.github
INFO:CPP Linter:processing push event
Event json from the runner
Get list of specified source files
Performing checkup on source/main.cpp
  INFO:CPP Linter:Running "clang-tidy-14 --export-fixes=clang_tidy_output.yml -p /home/runner/work/gh-actions-test/build/ci-linux-clang source/main.cpp"
  DEBUG:CPP Linter:Output from clang-tidy:
  /github/workspace/source/main.cpp:4:10: error: 'fmt/format.h' file not found [clang-diagnostic-error]

Otherwise, running VS Code's devcontainer shows relative path seems to work:

vscode ➜ /workspaces/gh-actions-test (main βœ—) $ clang-tidy-14 --export-fixes=clang_tidy_output.yml -p build/ci-linux-clang source/main.cpp
68700 warnings generated.
Suppressed 68700 warnings (68698 in non-user code, 2 with check filters).
Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.

I haven't the experience with clang-tidy using CLI arguments and python, so my guess is that's there is a wrong path (otherwise not very likely) :(

If relevant, the action is here

Originally posted by @ibis-hdl in #64 (comment)

lines-changed-only option does not work correctly

lines-changed-only option does not work correctly and sometimes complains about lines that were not changed by the PR. For example this PR:
chocolate-doom/chocolate-doom#1480

Elicited comment "File opl/opl.c (lines 42, 56): Code does not conform to Custom style guidelines."
Line 42 was not changed. Line 56 wasn't either, but line 55 was.

https://github.com/chocolate-doom/chocolate-doom/runs/7307673916

Correct(ish) option appears to have been passed to clang-format: --lines=50:58 though the range should have been 53:55. Line 42 should definitely not have raised issues.

Add support for private repos when fetching files in run.py

It does not look like the code in run.py get_list_of_changed_files fetches with the given token.

Wondering if this is a known problem and something that can be fixed?

Getting the following error when fetching files from a private repo:

  Traceback (most recent call last):
    File "/usr/lib/python3.8/runpy.py", line 194, in _run_module_as_main
      return _run_code(code, main_globals, None,
    File "/usr/lib/python3.8/runpy.py", line 87, in _run_code
      exec(code, run_globals)
    File "/usr/local/lib/python3.8/dist-packages/cpp_linter/run.py", line 764, in <module>
      main()
    File "/usr/local/lib/python3.8/dist-packages/cpp_linter/run.py", line 738, in main
      exit_early = not filter_out_non_source_files(
    File "/usr/local/lib/python3.8/dist-packages/cpp_linter/run.py", line 2[25](https://github.com/JosephDrazen/myRepo/runs/<run_id>?check_suite_focus=true#step:4:25), in filter_out_non_source_files
      os.path.splitext(file["filename"])[1][1:] in ext_list
  TypeError: string indices must be integers```

Prevent action downloading files after GH checkout action

If you require the user's repos uses GH's actions/checkout prior to the cpp-lint action, then all files are already there in a folder designated by the environment variable $GITHUB_WORKSPACE.

The JSON that the bash script is getting the list of download URLs can instead be used to get the relative path of files. This way, you'd only have to prefix the filenames with $GITHUB_WORKSPACE when passing them to clang-* tools.

Add support for other CI tools (via python package)

Hi @2bndy5 the following example you mentioned in the discussions yesterday is very instructive.

Someone who uses other CI tools like Travis CI, CircleCI, Jenkins, etc instead of GitHub Actions can also use this repo code if their code is hosted on GitHub.

I'm thinking whether updating this example code to README may help.

# Requires clang-format, clang-tidy installed

# Install linter package
python3 -m pip install git+https://github.com/shenxianpeng/cpp-linter-action

# Generate compilation database  
mkdir build && cmake -Bbuild src -DCMAKE_EXPORT_COMPILE_COMMANDS=ON

# Run linter as a package
# --version arg is useless on Windows - it will use whatever version is installed
# --ignore the build/* artifacts generated by CMake
# --database indicates the path of the generated database
python3 -m cpp_linter.run --ignore=build --database=build --thread-comments=true

# Fail fast?!
if [ $? -ne 0 ]; then
    echo "Some files failed the linting checks!"
fi

allow diff comments for PRs

I've been digging through GH's REST API, and it looks like we can do an auto-review for PRs. I have to keep digging for more details, but I'd like to switch from posting a PR comment to creating a multitude of review comments (PR-synchronize events will have to discard stale reviews from prior workflow runs). This can also be done for pushed commits πŸ˜‰

Getting line number, file paths, and suggestions from clang-tidy & clang-format can be done, but it would take some extra dependencies. Clang-format can output suggested fixes in XML (only to stdout), and clang-tidy can output fix suggestions to a specified YAML file. Again, I need to investigate the best course of parsing these outputs from bash script.

Cannot add clang-tidy lint result in when source file is .c

Refer to the screenshot. more details see this commit cpp-linter/test-cpp-linter-action@db16407

image

Here is yml file (I'm not sure if I wrote the wrong yml)

name: cpp-linter

# Triggers the workflow on push or pull request events
on:
  push:
  pull_request:
jobs:
  cpp-linter:
    name: cpp-linter
    runs-on: ubuntu-latest
    steps:
      - name: C/C++ Lint Action
        env:
            GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        uses: shenxianpeng/cpp-linter-action@master
        with:
          style: 'llvm'
          extensions: 'c'
          version: '11'
          

Expected result:

  • if list the file, should also list the formatted result.
  • otherwise do not add comment

Pass compiler options?

Is there a way to pass compiler options? The things that come after the double dash:

clang-tidy ./file.cpp --checks=* -- -I/home/include/path

Shouldn't we be checking all files in the repo?

This occurred to me when I was adding the diff-only option. If diff-only is false, then shouldn't we be examining all source files in the repo that use one of the designated file extensions? Currently, we are only examining files that have been changed despite what diff-only option is set to.

However, we can only do this if the repo is checked out before this action is run, but there's the concern of clever people also checking out their repo's submodules (which shouldn't be examined by this action). In case the repo is setup to use submodules, we can use the .gitmodules file to ignore any existing submodules. This wouldn't be hard at all since the .gitmodules file uses an ini file syntax which python's std configparser module can handle nicely.

I suppose we can use the REST API to list all files in the repo, but the REST API's responses are limited to 30 entries per page. If the repo has more than 30 files, then we'd have to subsequently keep making REST requests until we have a list of all the files in the repo. It would definitely be easier if the repo was checked out beforehand, and we use python to "walk" through the repo's files and examine any applicable source files.

`lines-changed-only` should assert `files-changed-only` implicitly

User intuition probably implies that the lines-changed-only option should implicitly mean files-changed-only is true, but this is not the case under the hood.

I think this is partially implemented in #81 (as part of the solution to #74), but it would be better to make the source explicitly change the value of files-changed-only if lines-changed-only is not disabled.

Add 'Used by' section in README.md

Since this PR #60 merged, this repo lost all the previous used by links (result is here), how about adding 'Used by' section in README.md? we could:

  • List the most famous projects like google/flatbuffers, others display links or number
  • Or display like contributor avatars as in many projects

`tidy-checks=-*` triggers false-positive

I added this action to a project I'm helping. The project's owner is still learning C++, so I thought this action would help lament best practices...

I tried to disable clang-tidy by specifying

          tidy-checks: '-*'

but clang-tidy threw some errors which triggered an empty comment.

The workflow log reveals that clang-tidy didn't like being told to do nothing. The output from clang-tidy (which in this case was the --help output) was interpreted as though the user should be notified.

Error: no checks enabled.

I'd like to add a check in the run.py (run_clang_tidy()) that allows skipping clang-tidy when all checks are disabled (when tidy-checks=-*).

Propose: add probot-stale to move forward and cleanup issues

We have several issues there are not been active for more than one month, some of them have been answered but the creator has not confirmed. stale can help us to automatically manage these issues.

Here are the settings of .github/stale.yml

# Number of days of inactivity before an issue becomes stale
daysUntilStale: 60
# Number of days of inactivity before a stale issue is closed
daysUntilClose: 7
# Issues with these labels will never be considered stale
exemptLabels:
  - pinned
  - security
  - bug
# Label to use when marking an issue as stale
staleLabel: wontfix
# Comment to post when marking an issue as stale. Set to `false` to disable
markComment: >
  This issue has been automatically marked as stale because it has not had
  recent activity. It will be closed if no further activity occurs. Thank you
  for your contributions.
# Comment to post when closing a stale issue. Set to `false` to disable
closeComment: false

Clang not installed when selecting version 14

This issur is related to this discussion. If you select clang version 14, clang is not be installed correctly on the workflow, which can cause unexpected errors like system header files that are missing.

Remove runchecks.sh

As we have used python instead of shell script to check code changes, I guess we could remove it to avoid confusion.

Posting comment(s) failed at the second run

post push comments failed when comments exist

Posting comment(s)
  INFO:CPP Linter:comments_url: https://api.github.com/repos/shenxianpeng/cpp-linter-action/commits/f4c83bab3681622d96b63bc60abeec966bdf4968/comments
  Traceback (most recent call last):
    File "/usr/lib/python3.8/runpy.py", line 194, in _run_module_as_main
      return _run_code(code, main_globals, None,
    File "/usr/lib/python3.8/runpy.py", line 87, in _run_code
      exec(code, run_globals)
    File "/github/workspace/cpp_linter/run.py", line 811, in <module>
      main()
    File "/github/workspace/cpp_linter/run.py", line 805, in main
      post_results(False)  # False is hard-coded to disable diff comments.
    File "/github/workspace/cpp_linter/run.py", line [67](https://github.com/shenxianpeng/cpp-linter-action/runs/5806368569?check_suite_focus=true#step:4:67)9, in post_results
      checks_passed = post_push_comment(base_url, user_id)
    File "/github/workspace/cpp_linter/run.py", line 541, in post_push_comment
      remove_bot_comments(comments_url, user_id)
    File "/github/workspace/cpp_linter/thread_comments.py", line 28, in remove_bot_comments
      and comment["body"].startswith("<!-- cpp linter action -->")
  KeyError: 'body'

More details https://github.com/shenxianpeng/cpp-linter-action/runs/5806368569?check_suite_focus=true

Execution of verify_files_are_present() failed

I'd like to test shenxianpeng/cpp-linter-action@master-py in my test repository test-cpp-linter-action and it failed with the following error message:

INFO:CPP Linter:File names:
	helloworld.cpp
INFO:CPP Linter:Downloading file from url: https://github.com/shenxianpeng/test-cpp-linter-action/raw/122b581c15688edbb8ba02079e8821a6725b263b/helloworld.cpp
Traceback (most recent call last):
  File "/usr/lib/python3.8/runpy.py", line 194, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/usr/lib/python3.8/runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "/usr/local/lib/python3.8/dist-packages/python_action/run.py", line 500, in <module>
    main()
  File "/usr/local/lib/python3.8/dist-packages/python_action/run.py", line 492, in main
    verify_files_are_present()
  File "/usr/local/lib/python3.8/dist-packages/python_action/run.py", line 212, in verify_files_are_present
    temp.write(download)
TypeError: write() argument must be str, not Response

The completed log can be found here: https://github.com/shenxianpeng/test-cpp-linter-action/runs/3776570178

`ignore` option's CLI default value includes repo root

I just noticed another problem when running the action as a python package. If the --ignore option is not specified then the default value is '' which gets translated as the repo root folder ./. Meaning, no files are linted when ignore is not specified to the cpp-linter executable script.

I'm opening this to add the issue to my backlog of needed changes.

By use of Python package, at action cpp-linter is not found

I followed Running without the docker container hopefully correct and in my action I have:

jobs:
  cpp-linter:
    runs-on: ubuntu-22.04
    steps:
...
    - name: Install conan package manager and cpp-linter
      run: |
        python -m pip install --upgrade pip
        pip --disable-pip-version-check --no-cache-dir install wheel conan \
          git+https://github.com/cpp-linter/cpp-linter-action@v1
...

    - name: Run cpp-linter (clang format && tidy)
      id: linter
      run: |
        cpp-linter --version=14 --style=file --tidy-checks='' --ignore=build --database=build/ci-linux-clang

which results to:

Run cpp-linter --version=14 --style=file --tidy-checks='' --ignore=build --database=build/ci-linux-clang
  cpp-linter --version=14 --style=file --tidy-checks='' --ignore=build --database=build/ci-linux-clang
  shell: /usr/bin/bash -e {0}
  env:
    CONAN_V2_MODE: 1
/home/runner/work/_temp/405c3607-29ac-42c3-af1e-b4afbe18453f.sh: line 1: cpp-linter: command not found
Error: Process completed with exit code 127.

tidy-checks always applied nevetherless local .clang-tidy

Hi,

I'm starting with this action right now. Following the action log:

Run cpp-linter/[email protected]
  with:
    style: file
    version: 14
    database: build/ci-linux-clang
    thread-comments: false
    extensions: c,h,C,H,cpp,hpp,cc,hh,c++,h++,cxx,hxx
    tidy-checks: boost-*,bugprone-*,performance-*,readability-*,portability-*,modernize-*,clang-analyzer-*,cppcoreguidelines-*
    repo-root: .
    verbosity: 10
    lines-changed-only: false
    files-changed-only: true
    ignore: .github
  env:
    CONAN_V2_MODE: 1
    GITHUB_TOKEN: ***
/usr/bin/docker run --name f1554982f9bdb02be47a699a3db07c25c8795_b963b1 --label 6f1554 --workdir /github/workspace --rm -e CONAN_V2_MODE -e GITHUB_TOKEN -e INPUT_STYLE -e INPUT_VERSION -e INPUT_DATABASE -e INPUT_THREAD-COMMENTS -e INPUT_EXTENSIONS -e INPUT_TIDY-CHECKS -e INPUT_REPO-ROOT -e INPUT_VERBOSITY -e INPUT_LINES-CHANGED-ONLY -e INPUT_FILES-CHANGED-ONLY -e INPUT_IGNORE -e HOME -e GITHUB_JOB -e GITHUB_REF -e GITHUB_SHA -e GITHUB_REPOSITORY -e GITHUB_REPOSITORY_OWNER -e GITHUB_RUN_ID -e GITHUB_RUN_NUMBER -e GITHUB_RETENTION_DAYS -e GITHUB_RUN_ATTEMPT -e GITHUB_ACTOR -e GITHUB_WORKFLOW -e GITHUB_HEAD_REF -e GITHUB_BASE_REF -e GITHUB_EVENT_NAME -e GITHUB_SERVER_URL -e GITHUB_API_URL -e GITHUB_GRAPHQL_URL -e GITHUB_REF_NAME -e GITHUB_REF_PROTECTED -e GITHUB_REF_TYPE -e GITHUB_WORKSPACE -e GITHUB_ACTION -e GITHUB_EVENT_PATH -e GITHUB_ACTION_REPOSITORY -e GITHUB_ACTION_REF -e GITHUB_PATH -e GITHUB_ENV -e GITHUB_STEP_SUMMARY -e RUNNER_OS -e RUNNER_ARCH -e RUNNER_NAME -e RUNNER_TOOL_CACHE -e RUNNER_TEMP -e RUNNER_WORKSPACE -e ACTIONS_RUNTIME_URL -e ACTIONS_RUNTIME_TOKEN -e ACTIONS_CACHE_URL -e GITHUB_ACTIONS=true -e CI=true -v "/var/run/docker.sock":"/var/run/docker.sock" -v "/home/runner/work/_temp/_github_home":"/github/home" -v "/home/runner/work/_temp/_github_workflow":"/github/workflow" -v "/home/runner/work/_temp/_runner_file_commands":"/github/file_commands" -v "/home/runner/work/gh-actions-test/gh-actions-test":"/github/workspace" 6f1554:982f9bdb02be47a699a3db07c25c8795  "--style=file" "--extensions=c,h,C,H,cpp,hpp,cc,hh,c++,h++,cxx,hxx" "--tidy-checks=boost-*,bugprone-*,performance-*,readability-*,portability-*,modernize-*,clang-analyzer-*,cppcoreguidelines-*" "--repo-root=." "--version=14" "--verbosity=10" "--lines-changed-only=false" "--files-changed-only=true" "--thread-comments=false" "--ignore=.github" "--database=build/ci-linux-clang"

the CLI tidy checks are applied

"--tidy-checks=boost-*,bugprone-*,performance-*,readability-*,portability-*,modernize-*,clang-analyzer-*,cppcoreguidelines-*"

which takes precedence over the ones in .clang-tidy follwing Clang-Tidy:

Configuration files:
  clang-tidy attempts to read configuration for each source file from a
  .clang-tidy file located in the closest parent directory of the source
  file. If InheritParentConfig is true in a config file, the configuration file
  in the parent directory (if any exists) will be taken and current config file
  will be applied on top of the parent one. If any configuration options have
  a corresponding command-line option, command-line option takes precedence.

Is this correct? Following your action: "tidy-checks ... This option's value is appended to the value of the 'Checks' option in a .clang-tidy file (if any)." which is another interpretation (IMO they are simply overwritten).

Maybe the possibility to just dumping the configs makes it clear.

Nevertheless, setting

      - uses: cpp-linter/cpp-linter-action@v1
        ...
        with:
          style: file
          tidy-checks: ''

would work for this?

Clean-up README

  • 1. The current logo on cpp-linter-action is different from the logo on Org's home page. I prefer to move the old one.
  • 2. Add an example snip about how to use cpp-linter as a package with other CI tools, like Jenkins. and which arguments they can not use. Will update the new repo of cpp-linter when it supports on-GitHub-based CI, and this repo is only used for github action.
  • 3. Replace the second used by with chocolate-doom
  • 4. Remove old and more link
  • 5. Remove Gitpod badge. it not very necessary and it appears as two lines on the marketplace page https://github.com/marketplace/actions/c-c-lint-action

clang-tidy returned non-zero status 1 cause action to fail

Running the following command has output but its return code is 1 cause the action to fail.

subprocess.CalledProcessError: Command '['clang-tidy-11', '-checks=boost-*,bugprone-*,performance-*,readability-*,portability-*,modernize-*,clang-analyzer-*,cppcoreguidelines-*', '--export-fixes=clang_tidy_output.yml', 'demo.cpp']' returned non-zero exit status 1.

More details please refer to this action https://github.com/shenxianpeng/test-cpp-linter-action/runs/3782914731

I did a manual test, it looks good, it return 0, so I was confused why it failed. any suggestions?

gitpod /workspace/test-cpp-linter-action $ clang-tidy-11 -checks=boost-*,bugprone-*,performance-*,readability-*,portability-*,modernize-*,clang-analyzer-*,cppcoreguidelines-* --export-fixes=clang_tidy_output.yml demo.cpp
957 warnings generated.
/workspace/test-cpp-linter-action/demo.cpp:3:10: warning: inclusion of deprecated C++ header 'stdio.h'; consider using 'cstdio' instead [modernize-deprecated-headers]
#include <stdio.h>
         ^~~~~~~~~
         <cstdio>
/workspace/test-cpp-linter-action/demo.cpp:8:5: warning: use a trailing return type for this function [modernize-use-trailing-return-type]
int main(){
~~~ ^
auto       -> int
/workspace/test-cpp-linter-action/demo.cpp:10:13: warning: statement should be inside braces [readability-braces-around-statements]
    for (;;) break;
            ^
             {
/workspace/test-cpp-linter-action/demo.cpp:13:5: warning: do not call c-style vararg functions [cppcoreguidelines-pro-type-vararg]
    printf("Hello world!\n");
    ^
Suppressed 953 warnings (949 in non-user code, 4 with check filters).
Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.
gitpod /workspace/test-cpp-linter-action $ echo $?
0

submodules are only ignore if `files_changed_only` is True

I noticed this on a repo I'm developing that has 4 submodules. When the CI runs

cpp-linter --files-changed-only=false

All the submodules are crawled as if they're part of the current repo's original sources.

Moving the algorithm that detects submodules from list_source_files() into parse_ignored_option() should fix this, but I have to be careful to consider if the user explicitly specifies a submodule to be not ignored.

Change action from using docker to composite steps

This will:

  1. improve workflow runs times from 1m 24s (currently) to 6-20s (as shown in proof-of-concept tests).
  2. better support for the database input option (which is currently broken with the docker env).
  3. better support cross-compilation
  4. better support 3rd party libraries

intuitive action exit code

As it is currently, the action current exits with a successful code (0) even when the run_check.sh finds problems given by clang-tidy or clang-format.

Solution

toward the end of the script, add

EXIT_CODE=0
if [ "$PAYLOAD_FORMAT" != "" && "$PAYLOAD_TIDY" != "" ]
then
  EXIT_CODE=1
fi
exit($EXIT_CODE)

Counter-argument

If the intention is to allow PRs to merge errors (ignore the warning from clang-*), then the user's workflow could handle the exit code instead of hard-coding it in the run_checks.sh. This option would require a output from this action:

jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - uses: shenxianpeng/cpp-linter-action@master
        id: linter
        with:
          style: file
          extensions: 'cpp'
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

      # If there are any comments, fail the check
      - if: steps.linter.outputs.checks-failed > 0
        run: exit 1

This would simply require a change to the above bash script suggestion

EXIT_CODE=0
if [ "$PAYLOAD_FORMAT" != "" && "$PAYLOAD_TIDY" != "" ]
then
  EXIT_CODE=1
fi
# exit($EXIT_CODE) # let action exit successfully

# set the action's `checks-failed` output
echo "::set-output name=checks-failed::$(echo $EXIT_CODE)"

open to contributions?

I'm glad to see someone taking up the torch to update ArtificialAmateur's stale action. I was wondering if you'd be open to contributions. I'd like to add an input option that makes use of clang-format's --style= arg. Also, I think there's a way to consolidate the demo repo into this one.

Remove need for GITHUB_TOKEN

Hey there,
thanks a lot for this action!
It was unclear to me why this action wants the GITHUB_TOKEN since that can be quite a bit of a security risk.
A colleague of mine had a look and he thinks it isn't actually necessary.
Since he doesn't have time to make an issue I'll summarize his points here:

That particular action could be written without the token without a problem. They use it to retrieve the changelist for the PR, which they could get easily from the local git repository just by having head and base ref.

For the annotations, you also don't need the token: see the docs for setting an error message.

You can just echo "::error file=app.js,line=1,col=5,endColumn=7::Missing semicolon" in your script and it will create an annotation in app.js, line 1 with "missing semicolon". Absolutely no need for API calls, and much easier this way.

Hope this helps you improve this action even further!

Run linter as Python package FileNotFoundError

We were using the Windows linter in our project with fix from issue #50 . However, with the latest merge, running the linter as a Python package throws the following error: FileNotFoundError: [WinError 2] The system cannot find the file specified

The first action that failed for us, can be found here: https://github.com/red-panda-productions/DAISI/runs/6963055842?check_suite_focus=true

We have fixed the issue by cloning an older version of the master branch, but just wanted to let you know about this issue!

MkDocs deploy has been failing recently

Failed jobs: https://github.com/cpp-linter/cpp-linter-action/actions/workflows/mkdocs-deploy.yml

Run git config user.name 'github-actions'
INFO     -  Cleaning site directory
INFO     -  Building documentation to directory: /home/runner/work/cpp-linter-action/cpp-linter-action/site
WARNING  -  Both index.md and readme.md found. Skipping readme.md from /home/runner/work/cpp-linter-action/cpp-linter-action/docs
ERROR    -  Error reading page 'API Reference/cpp_linter.clang_format_xml.md': No module named 'mkdocstrings.handlers.python'
Traceback (most recent call last):
  File "/opt/hostedtoolcache/Python/3.10.5/x64/lib/python3.10/site-packages/mkdocstrings/handlers/base.py", line 563, in get_handler
    module = importlib.import_module(f"mkdocstrings_handlers.{name}")
  File "/opt/hostedtoolcache/Python/3.10.5/x64/lib/python3.10/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
  File "<frozen importlib._bootstrap>", line [9](https://github.com/cpp-linter/cpp-linter-action/runs/6997858571?check_suite_focus=true#step:5:10)92, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "<frozen importlib._bootstrap>", line [10](https://github.com/cpp-linter/cpp-linter-action/runs/6997858571?check_suite_focus=true#step:5:11)50, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1004, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'mkdocstrings_handlers'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
  File "/opt/hostedtoolcache/Python/3.10.5/x64/bin/mkdocs", line 8, in <module>
    sys.exit(cli())
  File "/opt/hostedtoolcache/Python/3.10.5/x64/lib/python3.10/site-packages/click/core.py", line [11](https://github.com/cpp-linter/cpp-linter-action/runs/6997858571?check_suite_focus=true#step:5:12)30, in __call__
    return self.main(*args, **kwargs)
  File "/opt/hostedtoolcache/Python/3.10.5/x64/lib/python3.10/site-packages/click/core.py", line 1055, in main
    rv = self.invoke(ctx)
  File "/opt/hostedtoolcache/Python/3.10.5/x64/lib/python3.10/site-packages/click/core.py", line 1657, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/opt/hostedtoolcache/Python/3.10.5/x64/lib/python3.10/site-packages/click/core.py", line 1404, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/opt/hostedtoolcache/Python/3.10.5/x64/lib/python3.10/site-packages/click/core.py", line 760, in invoke
    return __callback(*args, **kwargs)
  File "/opt/hostedtoolcache/Python/3.10.5/x64/lib/python3.10/site-packages/mkdocs/__main__.py", line 215, in gh_deploy_command
    build.build(cfg, dirty=not clean)
  File "/opt/hostedtoolcache/Python/3.10.5/x64/lib/python3.10/site-packages/mkdocs/commands/build.py", line 292, in build
    _populate_page(file.page, config, files, dirty)
  File "/opt/hostedtoolcache/Python/3.10.5/x64/lib/python3.10/site-packages/mkdocs/commands/build.py", line 174, in _populate_page
    page.render(config, files)
  File "/opt/hostedtoolcache/Python/3.10.5/x64/lib/python3.10/site-packages/mkdocs/structure/pages.py", line 175, in render
    self.content = md.convert(self.markdown)
  File "/opt/hostedtoolcache/Python/3.10.5/x64/lib/python3.10/site-packages/markdown/core.py", line 264, in convert
    root = self.parser.parseDocument(self.lines).getroot()
  File "/opt/hostedtoolcache/Python/3.10.5/x64/lib/python3.10/site-packages/markdown/blockparser.py", line 90, in parseDocument
    self.parseChunk(self.root, '\n'.join(lines))
  File "/opt/hostedtoolcache/Python/3.10.5/x64/lib/python3.10/site-packages/markdown/blockparser.py", line 105, in parseChunk
    self.parseBlocks(parent, text.split('\n\n'))
  File "/opt/hostedtoolcache/Python/3.10.5/x64/lib/python3.10/site-packages/markdown/blockparser.py", line [12](https://github.com/cpp-linter/cpp-linter-action/runs/6997858571?check_suite_focus=true#step:5:13)3, in parseBlocks
    if processor.run(parent, blocks) is not False:
  File "/opt/hostedtoolcache/Python/3.10.5/x64/lib/python3.10/site-packages/mkdocstrings/extension.py", line 121, in run
    html, handler, data = self._process_block(identifier, block, heading_level)
  File "/opt/hostedtoolcache/Python/3.10.5/x64/lib/python3.10/site-packages/mkdocstrings/extension.py", line [17](https://github.com/cpp-linter/cpp-linter-action/runs/6997858571?check_suite_focus=true#step:5:18)5, in _process_block
    handler = self._handlers.get_handler(handler_name, handler_config)
  File "/opt/hostedtoolcache/Python/3.10.5/x64/lib/python3.10/site-packages/mkdocstrings/handlers/base.py", line 565, in get_handler
    module = importlib.import_module(f"mkdocstrings.handlers.{name}")
  File "/opt/hostedtoolcache/Python/3.10.5/x64/lib/python3.10/importlib/__init__.py", line 1[26](https://github.com/cpp-linter/cpp-linter-action/runs/6997858571?check_suite_focus=true#step:5:27), in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
  File "<frozen importlib._bootstrap>", line 10[27](https://github.com/cpp-linter/cpp-linter-action/runs/6997858571?check_suite_focus=true#step:5:28), in _find_and_load
  File "<frozen importlib._bootstrap>", line 1004, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'mkdocstrings.handlers.python'
Error: Process completed with exit code 1.

use only 1 bot comment

Currently, this action produces a new comment on the instigating thread for every time a workflows' run results in warning/errors found within the source code changes.

I propose that a singular comment be created at first then updated on sequential changes. This might require curl to download another event payload for PR events to fetch the number of comments and find the comment authored by the bot. The event payload describing push events already has the information needed to do this (I think).

the `latest` tag should be removed when the CI is done

Just tried to commit to my backlogged-updates branch:

> git pull --tags origin backlogged-updates
From https://github.com/cpp-linter/cpp-linter-action
 * branch            backlogged-updates -> FETCH_HEAD
 ! [rejected]        latest     -> latest  (would clobber existing tag)

After #83 was opened, the latest tag was moved to a different branch which seemed to cause conflicts when my machine tried to do git pull.

I would suggest

--- a/.github/workflows/run-test.yml
+++ b/.github/workflows/run-test.yml
@@ -23,6 +23,7 @@ jobs:
           git push origin latest
 
   test-action:
+    needs: [add-tag]
     runs-on: ubuntu-latest
     steps:
     - uses: convictional/[email protected]
@@ -38,6 +39,7 @@ jobs:
         trigger_workflow: true
         wait_workflow: true
   test-package:
+    needs: [add-tag]
     runs-on: ubuntu-latest
     steps:
     - uses: convictional/[email protected]
@@ -52,3 +54,14 @@ jobs:
         propagate_failure: true
         trigger_workflow: true
         wait_workflow: true
+  remove-tag:
+    needs: [test-action, test-package]
+    runs-on: ubuntu-latest
+    steps:
+      - name: Checkout
+        uses: actions/checkout@v3
+      - name: remove latest tag (cleanup)
+        run: |
+          git config user.name 'github-actions'
+          git config user.email '41898282+github-actions[bot]@users.noreply.github.com'    
+          git push --delete origin latest || true

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.