From fa955fa370e063273afde26d0a34b4077431ff90 Mon Sep 17 00:00:00 2001 From: kminoda Date: Tue, 4 Jun 2024 10:00:25 +0900 Subject: [PATCH 1/8] ci: add cppcheck Signed-off-by: kminoda --- .github/workflows/cpp-check.yaml | 41 ++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 .github/workflows/cpp-check.yaml diff --git a/.github/workflows/cpp-check.yaml b/.github/workflows/cpp-check.yaml new file mode 100644 index 0000000000000..4864e3baebf3c --- /dev/null +++ b/.github/workflows/cpp-check.yaml @@ -0,0 +1,41 @@ +name: cppcheck + +on: + pull_request: + +jobs: + cppcheck: + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v2 + + - name: Install Cppcheck + run: sudo apt-get install -y cppcheck + + - name: Run Cppcheck + run: cppcheck --enable=warning,style,performance --error-exitcode=1 . + + - 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 + }); \ No newline at end of file From 5af08ec7af136e9ed0e481d8633d3e5e9acd8a85 Mon Sep 17 00:00:00 2001 From: kminoda <44218668+kminoda@users.noreply.github.com> Date: Tue, 4 Jun 2024 10:08:57 +0900 Subject: [PATCH 2/8] ci: add cppcheck (#32) Signed-off-by: kminoda --- .github/workflows/cpp-check.yaml | 41 ++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 .github/workflows/cpp-check.yaml diff --git a/.github/workflows/cpp-check.yaml b/.github/workflows/cpp-check.yaml new file mode 100644 index 0000000000000..4864e3baebf3c --- /dev/null +++ b/.github/workflows/cpp-check.yaml @@ -0,0 +1,41 @@ +name: cppcheck + +on: + pull_request: + +jobs: + cppcheck: + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v2 + + - name: Install Cppcheck + run: sudo apt-get install -y cppcheck + + - name: Run Cppcheck + run: cppcheck --enable=warning,style,performance --error-exitcode=1 . + + - 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 + }); \ No newline at end of file From 59710a02873de6fabaf2337bc8fa8e86e826963e Mon Sep 17 00:00:00 2001 From: kminoda Date: Tue, 4 Jun 2024 10:14:29 +0900 Subject: [PATCH 3/8] apply to fixed file Signed-off-by: kminoda --- .github/workflows/cpp-check.yaml | 38 ++++++++++++-------------------- 1 file changed, 14 insertions(+), 24 deletions(-) diff --git a/.github/workflows/cpp-check.yaml b/.github/workflows/cpp-check.yaml index 4864e3baebf3c..40fb4b72f4750 100644 --- a/.github/workflows/cpp-check.yaml +++ b/.github/workflows/cpp-check.yaml @@ -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 - }); \ No newline at end of file + - 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 \ No newline at end of file From 8e4b0a1898519904d3f98937eedb8b546a10af18 Mon Sep 17 00:00:00 2001 From: kminoda <44218668+kminoda@users.noreply.github.com> Date: Tue, 4 Jun 2024 10:15:22 +0900 Subject: [PATCH 4/8] Ci/add cpp check (#34) * ci: add cppcheck Signed-off-by: kminoda * apply to fixed file Signed-off-by: kminoda --------- Signed-off-by: kminoda --- .github/workflows/cpp-check.yaml | 38 ++++++++++++-------------------- 1 file changed, 14 insertions(+), 24 deletions(-) diff --git a/.github/workflows/cpp-check.yaml b/.github/workflows/cpp-check.yaml index 4864e3baebf3c..49b1ed2c60231 100644 --- a/.github/workflows/cpp-check.yaml +++ b/.github/workflows/cpp-check.yaml @@ -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 - }); \ No newline at end of file + - 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 From d4209b40f070ee60780a237e735ca9021655c555 Mon Sep 17 00:00:00 2001 From: kminoda Date: Tue, 4 Jun 2024 10:22:24 +0900 Subject: [PATCH 5/8] fix Signed-off-by: kminoda --- .github/workflows/cpp-check.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/cpp-check.yaml b/.github/workflows/cpp-check.yaml index 40fb4b72f4750..e8b9167a55895 100644 --- a/.github/workflows/cpp-check.yaml +++ b/.github/workflows/cpp-check.yaml @@ -18,7 +18,7 @@ jobs: 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 + git diff --name-only origin/${{ github.base_ref }} ${{ github.head_ref }} > changed_files.txt cat changed_files.txt - name: Run Cppcheck on changed files @@ -28,4 +28,4 @@ jobs: cppcheck --enable=warning,style,performance --error-exitcode=1 $files else echo "No C++ files changed." - shell: bash \ No newline at end of file + shell: bash From ab6ea2ad70c6b206c9e9ac7d0a997d043770865d Mon Sep 17 00:00:00 2001 From: kminoda <44218668+kminoda@users.noreply.github.com> Date: Tue, 4 Jun 2024 10:22:53 +0900 Subject: [PATCH 6/8] Ci/add cpp check (#35) * ci: add cppcheck Signed-off-by: kminoda * apply to fixed file Signed-off-by: kminoda --------- Signed-off-by: kminoda From 21b49dbfb023e993d47aed16be6a1ecc5d48c494 Mon Sep 17 00:00:00 2001 From: kminoda Date: Tue, 4 Jun 2024 11:20:50 +0900 Subject: [PATCH 7/8] add rev-list Signed-off-by: kminoda --- .github/workflows/cpp-check.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/cpp-check.yaml b/.github/workflows/cpp-check.yaml index e8b9167a55895..0edbfd9fc5e74 100644 --- a/.github/workflows/cpp-check.yaml +++ b/.github/workflows/cpp-check.yaml @@ -17,6 +17,7 @@ jobs: - name: Get changed files id: changed-files run: | + git rev-list --count origin/main..$(git branch --show-current) git fetch origin ${{ github.base_ref }} --depth=1 git diff --name-only origin/${{ github.base_ref }} ${{ github.head_ref }} > changed_files.txt cat changed_files.txt From b52f513fb0fbcd5c02ce699fbef89c6c545fec07 Mon Sep 17 00:00:00 2001 From: kminoda Date: Tue, 4 Jun 2024 11:25:32 +0900 Subject: [PATCH 8/8] fix Signed-off-by: kminoda --- .github/workflows/cpp-check.yaml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/cpp-check.yaml b/.github/workflows/cpp-check.yaml index 0edbfd9fc5e74..ddff7e001abde 100644 --- a/.github/workflows/cpp-check.yaml +++ b/.github/workflows/cpp-check.yaml @@ -9,7 +9,7 @@ jobs: steps: - name: Checkout code - uses: actions/checkout@v2 + uses: actions/checkout@v1 - name: Install Cppcheck run: sudo apt-get install -y cppcheck @@ -17,7 +17,6 @@ jobs: - name: Get changed files id: changed-files run: | - git rev-list --count origin/main..$(git branch --show-current) git fetch origin ${{ github.base_ref }} --depth=1 git diff --name-only origin/${{ github.base_ref }} ${{ github.head_ref }} > changed_files.txt cat changed_files.txt