hoge #23
Workflow file for this run
This file contains 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
name: cppcheck | |
on: | |
pull_request: | |
jobs: | |
cppcheck: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v2 | |
- name: Install Cppcheck and htmlreport | |
run: | | |
sudo apt-get update | |
sudo apt-get install -y cppcheck python3-lxml | |
- name: Get changed files | |
id: changed-files | |
run: | | |
git fetch origin ${{ github.base_ref }} --depth=1 | |
git diff --name-only FETCH_HEAD ${{ github.sha }} > changed_files.txt | |
cat changed_files.txt | |
- 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 --xml $files 2> cppcheck-report.xml | |
cppcheck-htmlreport --file=cppcheck-report.xml --report-dir=cppcheck-html | |
else | |
echo "No C++ files changed." | |
fi | |
shell: bash | |
- name: Upload Cppcheck HTML Report | |
if: failure() | |
uses: actions/upload-artifact@v2 | |
with: | |
name: cppcheck-html-report | |
path: cppcheck-html | |
- name: Post results as comment | |
if: failure() && ${{ github.event_name == 'pull_request' }} | |
uses: actions/github-script@v6 | |
with: | |
script: | | |
const fs = require('fs'); | |
const path = 'cppcheck-html/index.html'; | |
const htmlReport = fs.readFileSync(path, { encoding: 'utf8' }); | |
const comment = `Cppcheck Analysis:\n\n${htmlReport}`; | |
github.rest.issues.createComment({ | |
issue_number: context.issue.number, | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
body: comment | |
}); |