-
Notifications
You must be signed in to change notification settings - Fork 13.5k
[workflows] Add post-commit job that periodically runs the clang static analyzer #94106
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
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
2a7b8b7
[workflows] Add post-commit job that runs the clang static analyzer
tstellar fe82839
Use apt.llvm.org for the latest packages
tstellar ac70506
Run workflow on pushes when the workflow file itself is modified.
tstellar 3019e70
Also test clang
tstellar 5b25b45
Replace scan-build with a simple script
tstellar 31b147e
Fix artifact path
tstellar 05aca63
No longer need to install dependencies
tstellar 43e286c
Run job on prs that modify clang
tstellar f6e92d7
Run the analyzer after the build
tstellar 24d616f
Fix python formatting
tstellar 4c79c2e
Run on PR's that touch the python script
tstellar 7b8e023
Fix formatting
tstellar c5bdc29
Use scan-build from the containre
tstellar 385a18f
Merge branch 'main' into ci-static-analysis
tstellar File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import json | ||
import multiprocessing | ||
import os | ||
import re | ||
import subprocess | ||
import sys | ||
|
||
|
||
def run_analyzer(data): | ||
os.chdir(data["directory"]) | ||
command = ( | ||
data["command"] | ||
+ f" --analyze --analyzer-output html -o analyzer-results -Xclang -analyzer-config -Xclang max-nodes=75000" | ||
) | ||
print(command) | ||
subprocess.run(command, shell=True, check=True) | ||
|
||
|
||
def pool_error(e): | ||
print("Error analyzing file:", e) | ||
|
||
|
||
def main(): | ||
db_path = sys.argv[1] | ||
database = json.load(open(db_path)) | ||
|
||
with multiprocessing.Pool() as pool: | ||
pool.map_async(run_analyzer, [k for k in database], error_callback=pool_error) | ||
pool.close() | ||
pool.join() | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
name: Post-Commit Static Analyzer | ||
|
||
permissions: | ||
contents: read | ||
|
||
on: | ||
push: | ||
branches: | ||
- 'release/**' | ||
paths: | ||
- 'clang/**' | ||
- 'llvm/**' | ||
haoNoQ marked this conversation as resolved.
Show resolved
Hide resolved
|
||
- '.github/workflows/ci-post-commit-analyzer.yml' | ||
pull_request: | ||
types: | ||
- opened | ||
- synchronize | ||
- reopened | ||
- closed | ||
paths: | ||
- '.github/workflows/ci-post-commit-analyzer.yml' | ||
- '.github/workflows/ci-post-commit-analyzer-run.py' | ||
schedule: | ||
- cron: '30 0 * * *' | ||
|
||
concurrency: | ||
group: >- | ||
llvm-project-${{ github.workflow }}-${{ github.event_name == 'pull_request' && | ||
( github.event.pull_request.number || github.ref) }} | ||
cancel-in-progress: ${{ startsWith(github.ref, 'refs/pull/') }} | ||
|
||
jobs: | ||
post-commit-analyzer: | ||
if: >- | ||
github.repository_owner == 'llvm' && | ||
github.event.action != 'closed' | ||
runs-on: ubuntu-22.04 | ||
container: | ||
image: 'ghcr.io/llvm/ci-ubuntu-22.04:latest' | ||
env: | ||
LLVM_VERSION: 18 | ||
steps: | ||
- name: Checkout Source | ||
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 | ||
|
||
- name: Setup ccache | ||
uses: hendrikmuhs/ccache-action@v1 | ||
with: | ||
# A full build of llvm, clang, lld, and lldb takes about 250MB | ||
# of ccache space. There's not much reason to have more than this, | ||
# because we usually won't need to save cache entries from older | ||
# builds. Also, there is an overall 10GB cache limit, and each | ||
# run creates a new cache entry so we want to ensure that we have | ||
# enough cache space for all the tests to run at once and still | ||
# fit under the 10 GB limit. | ||
# Default to 2G to workaround: https://github.com/hendrikmuhs/ccache-action/issues/174 | ||
max-size: 2G | ||
key: post-commit-analyzer | ||
variant: sccache | ||
|
||
- name: Configure | ||
run: | | ||
cmake -B build -S llvm -G Ninja \ | ||
haoNoQ marked this conversation as resolved.
Show resolved
Hide resolved
|
||
-DLLVM_ENABLE_ASSERTIONS=ON \ | ||
-DLLVM_ENABLE_PROJECTS=clang \ | ||
-DLLVM_BUILD_LLVM_DYLIB=ON \ | ||
-DLLVM_LINK_LLVM_DYLIB=ON \ | ||
boomanaiden154 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
-DCMAKE_CXX_COMPILER=clang++ \ | ||
-DCMAKE_C_COMPILER=clang \ | ||
-DCMAKE_CXX_COMPILER_LAUNCHER=sccache \ | ||
-DCMAKE_C_COMPILER_LAUNCHER=sccache \ | ||
-DCMAKE_EXPORT_COMPILE_COMMANDS=ON \ | ||
-DLLVM_INCLUDE_TESTS=OFF \ | ||
-DCLANG_INCLUDE_TESTS=OFF \ | ||
-DCMAKE_BUILD_TYPE=Release | ||
|
||
- name: Build | ||
run: | | ||
# FIXME: We need to build all the generated header files in order to be able to run | ||
# the analyzer on every file. Building libLLVM and libclang is probably overkill for | ||
# this, but it's better than building every target. | ||
ninja -v -C build libLLVM.so libclang.so | ||
|
||
# Run the analyzer. | ||
python3 .github/workflows/ci-post-commit-analyzer-run.py build/compile_commands.json | ||
|
||
scan-build --generate-index-only build/analyzer-results | ||
|
||
- name: Upload Results | ||
uses: actions/upload-artifact@26f96dfa697d77e81fd5907df203aa23a56210a8 #v4.3.0 | ||
if: always() | ||
with: | ||
name: analyzer-results | ||
path: 'build/analyzer-results/*' | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.