


此GitHub動作是為C ++/Python項目設計的,並使用以下方式執行靜態分析。
它可以通過推和拉請求觸發。
有關設置和各種輸入的更多信息和指導,請參閱專用於每種語言的部分( C ++和Python )
創建的評論將包含具有問題描述的代碼片段。首次運行此操作時,將為當前拉的請求創建帶有初始結果的註釋。連續運行將以更新狀態編輯此註釋。
請注意,檢測到的問題的數量可能會使評論的身體大於PR評論的GitHub角色限制(65536)。在這種情況下,創建的評論將僅包含到達該點的問題,以及達到字符限制的信息。

對於非拉動請求,輸出將打印到GitHub的輸出控制台。此行為也可以通過force_console_print輸入強制強制。

雖然建議您的項目基於CMAKE,但不需要(請參見下面的輸入部分)。我們還建議在您的根目錄中使用.clang-tidy文件。如果您的項目需要安裝其他軟件包,則可以使用apt_pckgs和/或init_script輸入變量來安裝它們(請參見下面的工作流示例或輸入部分)。如果您的存儲庫允許叉子的貢獻,則必須將此操作與pull_request_target觸發事件一起使用,因為GitHub API否則不允許PR註釋。
默認情況下, cppcheck以以下標誌運行: --enable=all --suppress=missingIncludeSystem --inline-suppr --inconclusive您可以使用cppcheck_args輸入來設置自己的標誌。
Clang-Tidy在存儲庫中查找.clang-tidy文件,但是您還可以使用clang_tidy_args輸入設置檢查。
name : Static analysis
on :
# Will run on push when merging to 'branches'. The output will be shown in the console
push :
branches :
- develop
- master
- main
# 'pull_request_target' allows this Action to also run on forked repositories
# The output will be shown in PR comments (unless the 'force_console_print' flag is used)
pull_request_target :
branches :
- " * "
jobs :
static_analysis :
runs-on : ubuntu-latest
steps :
- uses : actions/checkout@v2
- name : setup init_script
shell : bash
run : |
echo "#!/bin/bash
# Input args provided by StaticAnalysis action
root_dir=${1}
build_dir=${2}
echo "Hello from the init script! First arg=${root_dir} second arg=${build_dir}"
add-apt-repository ppa:oibaf/graphics-drivers
apt update && apt upgrade
apt install -y libvulkan1 mesa-vulkan-drivers vulkan-utils" > init_script.sh
- name : Run static analysis
uses : JacobDomagala/StaticAnalysis@master
with :
language : c++
# Exclude any issues found in ${Project_root_dir}/lib
exclude_dir : lib
use_cmake : true
# Additional apt packages that need to be installed before running Cmake
apt_pckgs : software-properties-common libglu1-mesa-dev freeglut3-dev mesa-common-dev
# Additional script that will be run (sourced) AFTER 'apt_pckgs' and before running Cmake
init_script : init_script.sh
# (Optional) clang-tidy args
clang_tidy_args : -checks='*,fuchsia-*,google-*,zircon-*,abseil-*,modernize-use-trailing-return-type'
# (Optional) cppcheck args
cppcheck_args : --enable=all --suppress=missingIncludeSystem | 姓名 | 描述 | 預設值 |
|---|---|---|
github_token | GitHub令牌用於GitHub API請求 | ${{github.token}} |
pr_num | 拉的請求號碼將創建評論 | ${{github.event.pull_request.number}} |
comment_title | 標題與Raport發表評論。這應該是一個獨特的名字 | Static analysis result |
exclude_dir | 應排除在狂歡之外的目錄 | <empty> |
apt_pckgs | 需要安裝的其他(空間分離的)軟件包才能編譯項目 | <empty> |
init_script | 在配置項目之前將運行的可選外殼腳本(IE運行CMAKE命令)。當項目需要事先設置一些環境設置時,應使用此方法。腳本將使用2個參數運行: root_dir (用戶代碼的根目錄)和build_dir (為運行SA創建的構建目錄)。筆記。 apt_pckgs將在此腳本之前運行,以防萬一您需要安裝一些軟件包。此外,此腳本將在項目的根( root_dir )的根中運行 | <empty> |
cppcheck_args | 將使用的CPPCHECK(空間分離)參數 | --enable=all --suppress=missingIncludeSystem --inline-suppr --inconclusive |
clang_tidy_args | 將使用的clang-tidy參數(例如: -checks='*,fuchsia-*,google-*,zircon-*' | <empty> |
report_pr_changes_only | 僅在此拉請求中引入的更改中發現的問題。這意味著只有在更改線中發現的問題才會發布。由存儲庫中這些變化引起的任何其他問題都不會報告,因此通常您應該在整個代碼庫上進行靜態分析 | false |
use_cmake | 確定應使用cmake生成compile_commands.json文件 | true |
cmake_args | 其他CMAKE參數 | <empty> |
force_console_print | 將操作結果輸出到控制台,而不是創建註釋 | false |
注意: apt_pckgs將在init_script之前運行,以防萬一您需要在運行腳本之前安裝一些軟件包
name : Static analysis
on :
push :
branches :
- master
pull_request :
jobs :
check :
name : Run Linter
runs-on : ubuntu-20.04
steps :
- uses : actions/checkout@v3
- name : CodeQuality
uses : JacobDomagala/StaticAnalysis@master
with :
language : " Python "
pylint_args : " --rcfile=.pylintrc --recursive=true "
python_dirs : " src test " | 姓名 | 描述 | 預設值 |
|---|---|---|
github_token | GitHub令牌用於GitHub API請求 | ${{github.token}} |
pr_num | 拉的請求號碼將創建評論 | ${{github.event.pull_request.number}} |
comment_title | 標題與Raport發表評論。這應該是一個獨特的名字 | Static analysis result |
exclude_dir | 應排除在狂歡之外的目錄 | <empty> |
apt_pckgs | 需要安裝的其他(空間分離的)軟件包才能編譯項目 | <empty> |
init_script | 在配置項目之前將運行的可選外殼腳本(IE運行CMAKE命令)。當項目需要事先設置一些環境設置時,應使用此方法。腳本將使用2個參數運行: root_dir (用戶代碼的根目錄)和build_dir (為運行SA創建的構建目錄)。筆記。 apt_pckgs將在此腳本之前運行,以防萬一您需要安裝一些軟件包。此外,此腳本將在項目的根( root_dir )的根中運行 | <empty> |
pylint_args | 將使用的Pylint(空間分離)參數 | <empty> |
python_dirs | 包含要檢查Python文件的目錄 | <empty> |
report_pr_changes_only | 僅在此拉請求中引入的更改中發現的問題。這意味著只有在更改線中發現的問題才會發布。由存儲庫中這些變化引起的任何其他問題都不會報告,因此通常您應該在整個代碼庫上進行靜態分析 | false |
force_console_print | 將操作結果輸出到控制台,而不是創建註釋 | false |
注意: apt_pckgs將在init_script之前運行,以防萬一您需要在運行腳本之前安裝一些軟件包