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 GitHub cpp-linter-action #20

Merged
merged 5 commits into from
Jan 9, 2025
Merged

Add GitHub cpp-linter-action #20

merged 5 commits into from
Jan 9, 2025

Conversation

wgtmac
Copy link
Member

@wgtmac wgtmac commented Dec 27, 2024

image

@wgtmac
Copy link
Member Author

wgtmac commented Dec 27, 2024

Is this something worth adding? @Fokko @raulcd @zhjwpku

@zhjwpku
Copy link
Contributor

zhjwpku commented Dec 27, 2024

Is this something worth adding? @Fokko @raulcd @zhjwpku

+1

Is there something wrong with github? I see you are putting cpp-linter in pre-commit.yml while pre-commit in cpp-linter.yml

@wgtmac
Copy link
Member Author

wgtmac commented Dec 27, 2024

Oops, my bad. I just copied pre-commit.yml and edited the wrong file. Now it is fixed :)

@wgtmac wgtmac marked this pull request as ready for review December 27, 2024 06:31
Copy link
Contributor

@Fokko Fokko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like it, and I think it is worth a try 🙌

@lidavidm
Copy link
Member

Hmm, in that screenshot, 'memory not found' seems like a spurious error? Will this be noisy?

@wgtmac
Copy link
Member Author

wgtmac commented Dec 29, 2024

Hmm, in that screenshot, 'memory not found' seems like a spurious error? Will this be noisy?

I have also noticed that. I need to learn more about its configuration and improve it gradually.

Copy link
Member

@raulcd raulcd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can add it and see if it's helpful. If we find too many spurious errors we can try to fine tune it or remove it if not helpful.
Maybe we want to add extra-args: '-std=c++20 -Wall'?
https://cpp-linter.github.io/cpp-linter-action/inputs-outputs/#extra-args

.github/workflows/cpp-linter.yml Show resolved Hide resolved
@wgtmac
Copy link
Member Author

wgtmac commented Dec 30, 2024

https://github.com/apache/iceberg-cpp/actions/runs/12544655200

cpp-linter/[email protected] is not allowed to be used in apache/iceberg-cpp.

@raulcd
Copy link
Member

raulcd commented Dec 30, 2024

cpp-linter/[email protected] is not allowed to be used in apache/iceberg-cpp.

Thanks for trying!

@@ -20,15 +20,24 @@
#pragma once

#include <memory>
#include <string_view>

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@raulcd It seems that this issue still exists.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've been able to reproduce the memory error locally:

$ clang-tidy-18 -p ../iceberg-cpp -checks=file  --format-style file ../iceberg-cpp/api/iceberg/table.h --extra-arg=-std=c++17 --enable-module-headers-parsing 
Error while trying to load a compilation database:
Could not auto-detect compilation database from directory "../iceberg-cpp"
No compilation database found in /home/raulcd/code/arrow/../iceberg-cpp or any parent directory
fixed-compilation-database: Error while opening fixed database: No such file or directory
json-compilation-database: Error while opening JSON database: No such file or directory
Running without flags.
/home/raulcd/code/arrow/.clang-tidy:30:1: error: unknown key 'AnalyzeTemporaryDtors'
AnalyzeTemporaryDtors: true
^~~~~~~~~~~~~~~~~~~~~
Error parsing /home/raulcd/code/arrow/.clang-tidy: Invalid argument
/home/raulcd/code/arrow/.clang-tidy:30:1: error: unknown key 'AnalyzeTemporaryDtors'
AnalyzeTemporaryDtors: true
^~~~~~~~~~~~~~~~~~~~~
Error parsing /home/raulcd/code/arrow/.clang-tidy: Invalid argument
/home/raulcd/code/arrow/.clang-tidy:30:1: error: unknown key 'AnalyzeTemporaryDtors'
AnalyzeTemporaryDtors: true
^~~~~~~~~~~~~~~~~~~~~
Error parsing /home/raulcd/code/arrow/.clang-tidy: Invalid argument
/home/raulcd/code/arrow/.clang-tidy:30:1: error: unknown key 'AnalyzeTemporaryDtors'
AnalyzeTemporaryDtors: true
^~~~~~~~~~~~~~~~~~~~~
Error parsing /home/raulcd/code/arrow/.clang-tidy: Invalid argument
2 errors generated.
Error while processing /home/raulcd/code/arrow/../iceberg-cpp/api/iceberg/table.h.
error: invalid argument '-std=c++17' not allowed with 'C' [clang-diagnostic-error]
/home/raulcd/code/arrow/../iceberg-cpp/api/iceberg/table.h:22:10: error: 'memory' file not found [clang-diagnostic-error]
   22 | #include <memory>
      |          ^~~~~~~~
Found compiler error(s).

We might need to generate a compilation database first and use the database attribute: https://cpp-linter.github.io/cpp-linter-action/inputs-outputs/#database. It seems like it is detecting as if it's a C project by default without it.
If I build and use the build folder with -p it is successful:

$ clang-tidy-18 -p /home/raulcd/code/iceberg-cpp/build -checks=file  --format-style file ../api/iceberg/table.h --extra-arg=-std=c++17 --enable-module-headers-parsing

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have inserted a build step before the cpp-linter to create the compile_commands.json. Now it seems working.

@lidavidm
Copy link
Member

It appears either the token doesn't have comment permissions or the token isn't being passed into the action

@wgtmac
Copy link
Member Author

wgtmac commented Dec 31, 2024

It appears either the token doesn't have comment permissions or the token isn't being passed into the action

I have added permission for pull-requests: write but still hit the following error:

ERROR:CPP Linter:response returned 403 from POST https://api.github.com/repos/apache/iceberg-cpp/issues/20/comments with message: {"message":"Resource not accessible by integration","documentation_url":"https://docs.github.com/rest/issues/comments#create-an-issue-comment","status":"403"}
  Traceback (most recent call last):
    File "/home/runner/work/_actions/cpp-linter/cpp-linter-action/v2.13.3/venv/bin/cpp-linter", line 8, in <module>
      sys.exit(main())
    File "/home/runner/work/_actions/cpp-linter/cpp-linter-action/v2.13.3/venv/lib/python3.10/site-packages/cpp_linter/__init__.py", line 81, in main
      rest_api_client.post_feedback(files=files, args=args, clang_versions=clang_versions)
    File "/home/runner/work/_actions/cpp-linter/cpp-linter-action/v2.13.3/venv/lib/python3.10/site-packages/cpp_linter/rest_api/github_api.py", line 264, in post_feedback
      self.update_comment(
    File "/home/runner/work/_actions/cpp-linter/cpp-linter-action/v2.13.3/venv/lib/python3.10/site-packages/cpp_linter/rest_api/github_api.py", line [361](https://github.com/apache/iceberg-cpp/actions/runs/12554533849/job/35003344629?pr=20#step:4:369), in update_comment
      self.api_request(url=comments_url, method=req_meth, data=payload)
    File "/home/runner/work/_actions/cpp-linter/cpp-linter-action/v2.13.3/venv/lib/python3.10/site-packages/cpp_linter/rest_api/__init__.py", line 124, in api_request
      response.raise_for_status()
    File "/home/runner/work/_actions/cpp-linter/cpp-linter-action/v2.13.3/venv/lib/python3.10/site-packages/requests/models.py", line 1024, in raise_for_status
      raise HTTPError(http_error_msg, response=self)
  requests.exceptions.HTTPError: 403 Client Error: Forbidden for url: https://api.github.com/repos/apache/iceberg-cpp/issues/20/comments

@lidavidm
Copy link
Member

@lidavidm
Copy link
Member

It seems since the PR comes from a fork, Github will never let you get anything but read access. https://docs.github.com/en/actions/security-for-github-actions/security-guides/automatic-token-authentication#permissions-for-the-github_token

I think you'd either have to somehow make this work with pull_request_target (can be tricky) or just give up on the comment functionality.

@lidavidm
Copy link
Member

Note that pull_request_target (1) only runs from the base branch, not the PR and (2) doesn't check out the PR HEAD (it gets the base branch) so it's not suitable for this by default. (You can manually check out the PR HEAD but it gets easy to have accidental vulnerabilities this way)

@wgtmac
Copy link
Member Author

wgtmac commented Dec 31, 2024

Thanks @lidavidm for providing the detail! After reading relevant documentation, I agree that it is really tricky to workaround the token permission. Without comments on PR, the cpp-linter action seems not that useful because we already have the pre-commit check to do similar things.

Is it possible to elevate permission on a specific token? @Fokko

@lidavidm
Copy link
Member

I think it's a security issue: the write permission doesn't discriminate between who opened the PR or where you can write to, so someone could open a malicious PR to write to the repository.

pre-commit only runs clang-format, not clang-tidy - I think it'd still be useful even without the PR comment?

@wgtmac
Copy link
Member Author

wgtmac commented Dec 31, 2024

pre-commit only runs clang-format, not clang-tidy - I think it'd still be useful even without the PR comment?

That makes sense! Let me enable it for now. We can improve or discard it after we have experience with more PRs.

@wgtmac
Copy link
Member Author

wgtmac commented Jan 9, 2025

I think this PR is ready to merge. @Fokko @Xuanwo

Copy link
Member

@Xuanwo Xuanwo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @wgtmac for this. This changes look nice to me, I will merge it to unblock the future developement.

@Xuanwo Xuanwo merged commit 12da1ce into apache:main Jan 9, 2025
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants