Skip to content

Commit

Permalink
Ci/add cpp check (#34)
Browse files Browse the repository at this point in the history
* ci: add cppcheck

Signed-off-by: kminoda <[email protected]>

* apply to fixed file

Signed-off-by: kminoda <[email protected]>

---------

Signed-off-by: kminoda <[email protected]>
  • Loading branch information
kminoda authored Jun 4, 2024
1 parent 5af08ec commit 8e4b0a1
Showing 1 changed file with 14 additions and 24 deletions.
38 changes: 14 additions & 24 deletions .github/workflows/cpp-check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,28 +14,18 @@ jobs:
- name: Install Cppcheck
run: sudo apt-get install -y cppcheck

- name: Run Cppcheck
run: cppcheck --enable=warning,style,performance --error-exitcode=1 .
- name: Get changed files
id: changed-files
run: |
git fetch origin ${{ github.base_ref }} --depth=1
git diff --name-only ${{ github.base_ref }} ${{ github.head_ref }} > changed_files.txt
cat changed_files.txt
- name: Upload Cppcheck Report
if: failure()
uses: actions/upload-artifact@v2
with:
name: cppcheck-report
path: cppcheck-report.xml

- name: Post results as comment
if: failure()
uses: actions/github-script@v6
with:
script: |
const fs = require('fs');
const path = 'cppcheck-report.xml';
const report = fs.readFileSync(path, { encoding: 'utf8' });
const comment = `Cppcheck Analysis:\n\n\`\`\`xml\n${report}\n\`\`\``;
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: comment
});
- name: Run Cppcheck on changed files
run: |
files=$(cat changed_files.txt | grep '\.cpp$\|\.h$' | tr '\n' ' ')
if [ -n "$files" ]; then
cppcheck --enable=warning,style,performance --error-exitcode=1 $files
else
echo "No C++ files changed."
shell: bash

0 comments on commit 8e4b0a1

Please sign in to comment.