├── .eslintrc.js
├── .gitattributes
├── .github
└── workflows
│ ├── build.yml
│ ├── codeql-analysis.yml
│ └── test.yml
├── .gitignore
├── .vscode
└── tasks.json
├── LICENSE
├── README.md
├── action.yml
├── dist
├── index.js
├── licenses.txt
├── messages
│ └── messages.json
├── sarif-pro.xsl
└── sarif.xsl
├── package-lock.json
├── package.json
├── samples
├── cpptest-cmake.yml
├── cpptest-make.yml
├── cpptest-pro-make.yml
├── sarif-pro.xsl
└── sarif.xsl
├── src
├── main.ts
├── messages.ts
├── messages
│ └── messages.json
└── runner.ts
├── tests
├── main.tests.ts
├── messages.tests.ts
└── runner.tests.ts
└── tsconfig.json
/.eslintrc.js:
--------------------------------------------------------------------------------
1 |
2 | // This file is should be included by .eslintrc.js in extension root, like this:
3 | // module.exports = require("./vscode-common/eslintrc");
4 |
5 | module.exports = {
6 | "root": true, // Stop eslint from searching for config files up to filesystem root folder
7 | "env": {
8 | "es6": true,
9 | "node": true
10 | },
11 | "parser": "@typescript-eslint/parser",
12 | "parserOptions": {
13 | "sourceType": "module"
14 | },
15 | "plugins": [
16 | "@typescript-eslint"
17 | ],
18 | "extends": [
19 | "eslint:recommended",
20 | "plugin:@typescript-eslint/recommended",
21 | ],
22 | "rules": {
23 | "@typescript-eslint/explicit-module-boundary-types": "off",
24 | "@typescript-eslint/no-explicit-any": "off",
25 | "@typescript-eslint/no-non-null-assertion": "off",
26 | }
27 | };
--------------------------------------------------------------------------------
/.gitattributes:
--------------------------------------------------------------------------------
1 | * text=auto
2 | *.sh eol=lf
3 |
--------------------------------------------------------------------------------
/.github/workflows/build.yml:
--------------------------------------------------------------------------------
1 | name: "Build"
2 |
3 | on:
4 | push:
5 | branches: [ master ]
6 | pull_request:
7 | # The branches below must be a subset of the branches above
8 | branches: [ master ]
9 |
10 | jobs:
11 | build:
12 | runs-on: ubuntu-latest
13 | steps:
14 | - uses: actions/checkout@v4
15 | - run: |
16 | npm install
17 | - run: |
18 | npm run compile
19 | - run: |
20 | npm run package
21 |
--------------------------------------------------------------------------------
/.github/workflows/codeql-analysis.yml:
--------------------------------------------------------------------------------
1 | # For most projects, this workflow file will not need changing; you simply need
2 | # to commit it to your repository.
3 | #
4 | # You may wish to alter this file to override the set of languages analyzed,
5 | # or to provide custom queries or build logic.
6 | #
7 | # ******** NOTE ********
8 | # We have attempted to detect the languages in your repository. Please check
9 | # the `language` matrix defined below to confirm you have the correct set of
10 | # supported CodeQL languages.
11 | #
12 | name: "CodeQL"
13 |
14 | on:
15 | push:
16 | branches: [ master ]
17 | pull_request:
18 | # The branches below must be a subset of the branches above
19 | branches: [ master ]
20 | schedule:
21 | - cron: '38 19 * * 1'
22 |
23 | jobs:
24 | analyze:
25 | name: Analyze
26 | runs-on: ubuntu-latest
27 |
28 | strategy:
29 | fail-fast: false
30 | matrix:
31 | language: [ 'javascript' ]
32 | # CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python' ]
33 | # Learn more:
34 | # https://docs.github.com/en/free-pro-team@latest/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-code-scanning#changing-the-languages-that-are-analyzed
35 |
36 | steps:
37 | - name: Checkout repository
38 | uses: actions/checkout@v4
39 |
40 | # Initializes the CodeQL tools for scanning.
41 | - name: Initialize CodeQL
42 | uses: github/codeql-action/init@v3
43 | with:
44 | languages: ${{ matrix.language }}
45 | # If you wish to specify custom queries, you can do so here or in a config file.
46 | # By default, queries listed here will override any specified in a config file.
47 | # Prefix the list here with "+" to use these queries and those in the config file.
48 | # queries: ./path/to/local/query, your-org/your-repo/queries@main
49 |
50 | # Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
51 | # If this step fails, then you should remove it and run the build manually (see below)
52 | - name: Autobuild
53 | uses: github/codeql-action/autobuild@v3
54 |
55 | # ℹ️ Command-line programs to run using the OS shell.
56 | # 📚 https://git.io/JvXDl
57 |
58 | # ✏️ If the Autobuild fails above, remove it and uncomment the following three lines
59 | # and modify them (or add more) to build your code if your project
60 | # uses a compiled language
61 |
62 | #- run: |
63 | # make bootstrap
64 | # make release
65 |
66 | - name: Perform CodeQL Analysis
67 | uses: github/codeql-action/analyze@v3
68 |
--------------------------------------------------------------------------------
/.github/workflows/test.yml:
--------------------------------------------------------------------------------
1 | name: "Test"
2 |
3 | on:
4 | push:
5 | branches: [ master ]
6 | pull_request:
7 | # The branches below must be a subset of the branches above
8 | branches: [ master ]
9 |
10 | jobs:
11 | test:
12 | runs-on: ubuntu-latest
13 | steps:
14 | - uses: actions/checkout@v4
15 | - run: |
16 | npm install
17 | - run: |
18 | npm run compile
19 | - run: |
20 | npm run test
21 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | .DS_Store/
2 | .nyc_output/
3 | lib/
4 | node_modules/
--------------------------------------------------------------------------------
/.vscode/tasks.json:
--------------------------------------------------------------------------------
1 | // See https://go.microsoft.com/fwlink/?LinkId=733558
2 | // for the documentation about the tasks.json format
3 | {
4 | "version": "2.0.0",
5 | "tasks": [
6 | {
7 | "type": "npm",
8 | "script": "watch",
9 | "problemMatcher": "$tsc-watch",
10 | "isBackground": true,
11 | "presentation": {
12 | "reveal": "never"
13 | },
14 | "group": {
15 | "kind": "build",
16 | "isDefault": true
17 | }
18 | },
19 | {
20 | "type": "npm",
21 | "script": "compile",
22 | "problemMatcher": "$tsc",
23 | "isBackground": false,
24 | "presentation": {
25 | "reveal": "always"
26 | },
27 | "group": {
28 | "kind": "build",
29 | "isDefault": true
30 | }
31 | }
32 | ]
33 | }
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Apache License
2 | Version 2.0, January 2004
3 | http://www.apache.org/licenses/
4 |
5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6 |
7 | 1. Definitions.
8 |
9 | "License" shall mean the terms and conditions for use, reproduction,
10 | and distribution as defined by Sections 1 through 9 of this document.
11 |
12 | "Licensor" shall mean the copyright owner or entity authorized by
13 | the copyright owner that is granting the License.
14 |
15 | "Legal Entity" shall mean the union of the acting entity and all
16 | other entities that control, are controlled by, or are under common
17 | control with that entity. For the purposes of this definition,
18 | "control" means (i) the power, direct or indirect, to cause the
19 | direction or management of such entity, whether by contract or
20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
21 | outstanding shares, or (iii) beneficial ownership of such entity.
22 |
23 | "You" (or "Your") shall mean an individual or Legal Entity
24 | exercising permissions granted by this License.
25 |
26 | "Source" form shall mean the preferred form for making modifications,
27 | including but not limited to software source code, documentation
28 | source, and configuration files.
29 |
30 | "Object" form shall mean any form resulting from mechanical
31 | transformation or translation of a Source form, including but
32 | not limited to compiled object code, generated documentation,
33 | and conversions to other media types.
34 |
35 | "Work" shall mean the work of authorship, whether in Source or
36 | Object form, made available under the License, as indicated by a
37 | copyright notice that is included in or attached to the work
38 | (an example is provided in the Appendix below).
39 |
40 | "Derivative Works" shall mean any work, whether in Source or Object
41 | form, that is based on (or derived from) the Work and for which the
42 | editorial revisions, annotations, elaborations, or other modifications
43 | represent, as a whole, an original work of authorship. For the purposes
44 | of this License, Derivative Works shall not include works that remain
45 | separable from, or merely link (or bind by name) to the interfaces of,
46 | the Work and Derivative Works thereof.
47 |
48 | "Contribution" shall mean any work of authorship, including
49 | the original version of the Work and any modifications or additions
50 | to that Work or Derivative Works thereof, that is intentionally
51 | submitted to Licensor for inclusion in the Work by the copyright owner
52 | or by an individual or Legal Entity authorized to submit on behalf of
53 | the copyright owner. For the purposes of this definition, "submitted"
54 | means any form of electronic, verbal, or written communication sent
55 | to the Licensor or its representatives, including but not limited to
56 | communication on electronic mailing lists, source code control systems,
57 | and issue tracking systems that are managed by, or on behalf of, the
58 | Licensor for the purpose of discussing and improving the Work, but
59 | excluding communication that is conspicuously marked or otherwise
60 | designated in writing by the copyright owner as "Not a Contribution."
61 |
62 | "Contributor" shall mean Licensor and any individual or Legal Entity
63 | on behalf of whom a Contribution has been received by Licensor and
64 | subsequently incorporated within the Work.
65 |
66 | 2. Grant of Copyright License. Subject to the terms and conditions of
67 | this License, each Contributor hereby grants to You a perpetual,
68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69 | copyright license to reproduce, prepare Derivative Works of,
70 | publicly display, publicly perform, sublicense, and distribute the
71 | Work and such Derivative Works in Source or Object form.
72 |
73 | 3. Grant of Patent License. Subject to the terms and conditions of
74 | this License, each Contributor hereby grants to You a perpetual,
75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76 | (except as stated in this section) patent license to make, have made,
77 | use, offer to sell, sell, import, and otherwise transfer the Work,
78 | where such license applies only to those patent claims licensable
79 | by such Contributor that are necessarily infringed by their
80 | Contribution(s) alone or by combination of their Contribution(s)
81 | with the Work to which such Contribution(s) was submitted. If You
82 | institute patent litigation against any entity (including a
83 | cross-claim or counterclaim in a lawsuit) alleging that the Work
84 | or a Contribution incorporated within the Work constitutes direct
85 | or contributory patent infringement, then any patent licenses
86 | granted to You under this License for that Work shall terminate
87 | as of the date such litigation is filed.
88 |
89 | 4. Redistribution. You may reproduce and distribute copies of the
90 | Work or Derivative Works thereof in any medium, with or without
91 | modifications, and in Source or Object form, provided that You
92 | meet the following conditions:
93 |
94 | (a) You must give any other recipients of the Work or
95 | Derivative Works a copy of this License; and
96 |
97 | (b) You must cause any modified files to carry prominent notices
98 | stating that You changed the files; and
99 |
100 | (c) You must retain, in the Source form of any Derivative Works
101 | that You distribute, all copyright, patent, trademark, and
102 | attribution notices from the Source form of the Work,
103 | excluding those notices that do not pertain to any part of
104 | the Derivative Works; and
105 |
106 | (d) If the Work includes a "NOTICE" text file as part of its
107 | distribution, then any Derivative Works that You distribute must
108 | include a readable copy of the attribution notices contained
109 | within such NOTICE file, excluding those notices that do not
110 | pertain to any part of the Derivative Works, in at least one
111 | of the following places: within a NOTICE text file distributed
112 | as part of the Derivative Works; within the Source form or
113 | documentation, if provided along with the Derivative Works; or,
114 | within a display generated by the Derivative Works, if and
115 | wherever such third-party notices normally appear. The contents
116 | of the NOTICE file are for informational purposes only and
117 | do not modify the License. You may add Your own attribution
118 | notices within Derivative Works that You distribute, alongside
119 | or as an addendum to the NOTICE text from the Work, provided
120 | that such additional attribution notices cannot be construed
121 | as modifying the License.
122 |
123 | You may add Your own copyright statement to Your modifications and
124 | may provide additional or different license terms and conditions
125 | for use, reproduction, or distribution of Your modifications, or
126 | for any such Derivative Works as a whole, provided Your use,
127 | reproduction, and distribution of the Work otherwise complies with
128 | the conditions stated in this License.
129 |
130 | 5. Submission of Contributions. Unless You explicitly state otherwise,
131 | any Contribution intentionally submitted for inclusion in the Work
132 | by You to the Licensor shall be under the terms and conditions of
133 | this License, without any additional terms or conditions.
134 | Notwithstanding the above, nothing herein shall supersede or modify
135 | the terms of any separate license agreement you may have executed
136 | with Licensor regarding such Contributions.
137 |
138 | 6. Trademarks. This License does not grant permission to use the trade
139 | names, trademarks, service marks, or product names of the Licensor,
140 | except as required for reasonable and customary use in describing the
141 | origin of the Work and reproducing the content of the NOTICE file.
142 |
143 | 7. Disclaimer of Warranty. Unless required by applicable law or
144 | agreed to in writing, Licensor provides the Work (and each
145 | Contributor provides its Contributions) on an "AS IS" BASIS,
146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147 | implied, including, without limitation, any warranties or conditions
148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149 | PARTICULAR PURPOSE. You are solely responsible for determining the
150 | appropriateness of using or redistributing the Work and assume any
151 | risks associated with Your exercise of permissions under this License.
152 |
153 | 8. Limitation of Liability. In no event and under no legal theory,
154 | whether in tort (including negligence), contract, or otherwise,
155 | unless required by applicable law (such as deliberate and grossly
156 | negligent acts) or agreed to in writing, shall any Contributor be
157 | liable to You for damages, including any direct, indirect, special,
158 | incidental, or consequential damages of any character arising as a
159 | result of this License or out of the use or inability to use the
160 | Work (including but not limited to damages for loss of goodwill,
161 | work stoppage, computer failure or malfunction, or any and all
162 | other commercial damages or losses), even if such Contributor
163 | has been advised of the possibility of such damages.
164 |
165 | 9. Accepting Warranty or Additional Liability. While redistributing
166 | the Work or Derivative Works thereof, You may choose to offer,
167 | and charge a fee for, acceptance of support, warranty, indemnity,
168 | or other liability obligations and/or rights consistent with this
169 | License. However, in accepting such obligations, You may act only
170 | on Your own behalf and on Your sole responsibility, not on behalf
171 | of any other Contributor, and only if You agree to indemnify,
172 | defend, and hold each Contributor harmless for any liability
173 | incurred by, or claims asserted against, such Contributor by reason
174 | of your accepting any such warranty or additional liability.
175 |
176 | END OF TERMS AND CONDITIONS
177 |
178 | APPENDIX: How to apply the Apache License to your work.
179 |
180 | To apply the Apache License to your work, attach the following
181 | boilerplate notice, with the fields enclosed by brackets "[]"
182 | replaced with your own identifying information. (Don't include
183 | the brackets!) The text should be enclosed in the appropriate
184 | comment syntax for the file format. We also recommend that a
185 | file or class name and description of purpose be included on the
186 | same "printed page" as the copyright notice for easier
187 | identification within third-party archives.
188 |
189 | Copyright 2021 Parasoft Corp.
190 |
191 | Licensed under the Apache License, Version 2.0 (the "License");
192 | you may not use this file except in compliance with the License.
193 | You may obtain a copy of the License at
194 |
195 | http://www.apache.org/licenses/LICENSE-2.0
196 |
197 | Unless required by applicable law or agreed to in writing, software
198 | distributed under the License is distributed on an "AS IS" BASIS,
199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200 | See the License for the specific language governing permissions and
201 | limitations under the License.
202 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Run Parasoft C/C++test
2 |
3 | [](https://github.com/parasoft/run-cpptest-action/actions/workflows/build.yml)
4 | [](https://github.com/parasoft/run-cpptest-action/actions/workflows/codeql-analysis.yml)
5 | [](https://github.com/parasoft/run-cpptest-action/actions/workflows/test.yml)
6 |
7 | This action enables you to run code analysis with Parasoft C/C++test Standard and review analysis results directly on GitHub. To run code analysis with C/C++test Professional, this action must be customized with additional options; see [Customizing the Action to Run C/C++test Professional](#customizing-the-action-to-run-cctest-professional).
8 |
9 | Parasoft C/C++test uses a comprehensive set of analysis techniques, including pattern-based static analysis, dataflow analysis, metrics, code coverage, unit testing, and more, to help you verify code quality and ensure compliance with industry standards, such as MISRA, AUTOSAR, and CERT.
10 | - Request [a free trial](https://www.parasoft.com/products/parasoft-c-ctest/try/) to receive access to Parasoft C/C++test's features and capabilities.
11 | - See the [user guide](https://docs.parasoft.com/display/CPPTEST20251) for information about Parasoft C/C++test's capabilities and usage.
12 |
13 | Please visit the [official Parasoft website](http://www.parasoft.com) for more information about Parasoft C/C++test and other Parasoft products.
14 |
15 | - [Quick start](#quick-start)
16 | - [Example Workflows](#example-workflows)
17 | - [Configuring Analysis with C/C++test](#configuring-analysis-with-cctest)
18 | - [Action Parameters](#action-parameters)
19 | - [Customizing the Action to Run C/C++test Professional](#customizing-the-action-to-run-cctest-professional)
20 |
21 |
22 | ## Quick start
23 |
24 | To analyze your code with Parasoft C/C++test and review analysis results on GitHub, you need to customize your GitHub workflow to include:
25 | - Integration with your C/C++ build to determine the scope of analysis.
26 | - The action to run C/C++test.
27 | - The action to upload the C/C++test analysis report in the SARIF format to GitHub.
28 | - The action to upload the C/C++test analysis reports in other formats (XML, HTML, etc.) to GitHub as workflow artifacts.
29 |
30 | ### Prerequisites
31 | This action requires Parasoft C/C++test with a valid Parasoft license.
32 |
33 | We recommend that you run Parasoft C/C++test on a self-hosted rather than GitHub-hosted runner.
34 |
35 | ### Adding the Run C/C++test Action to a GitHub Workflow
36 | Add the `Run C/C++test` action to your workflow to launch code analysis with Parasoft C/C++test.
37 |
38 | Depending on the project type and the build system you are using (Make, CMake, etc.), you may need to adjust the workflow to collect the required input data for C/C++test. See the [C/C++test User Guide](https://docs.parasoft.com/display/CPPTEST20251/Running+Static+Analysis+1) for details.
39 |
40 | ```yaml
41 | # Runs code analysis with C/C++test.
42 | - name: Run C/C++test
43 | uses: parasoft/run-cpptest-action@2.0.2
44 | with:
45 | input: build/compile_commands.json
46 | testConfig: 'builtin://MISRA C 2012'
47 | compilerConfig: 'clang_10_0'
48 | ```
49 |
50 | ### Uploading Analysis Results to GitHub
51 | By default, the `Run C/C++test` action generates analysis reports in the SARIF, XML, and HTML format (if you are using a C/C++test version earlier than 2021.1, see [Generating SARIF Reports with C/C++test 2020.2 or Earlier](#generating-sarif-reports-with-cctest-20202-or-earlier)).
52 |
53 | When you upload the SARIF report to GitHub, the results will be presented as GitHub code scanning alerts. This allows you to review the results of code analysis with Parasoft C/C++test directly on GitHub as part of your project.
54 | To upload the SARIF report to GitHub, modify your workflow by adding the `upload-sarif` action.
55 |
56 | ```yaml
57 | # Uploads analysis results in the SARIF format, so that they are displayed as GitHub code scanning alerts.
58 | - name: Upload results (SARIF)
59 | if: always()
60 | uses: github/codeql-action/upload-sarif@v3
61 | with:
62 | sarif_file: reports/report.sarif
63 | ```
64 |
65 | To upload reports in other formats, modify your workflow by adding the `upload-artifact` action.
66 |
67 | ```yaml
68 | # Uploads an archive that includes all report files (.xml, .html, .sarif).
69 | - name: Archive reports
70 | if: always()
71 | uses: actions/upload-artifact@v4
72 | with:
73 | name: CpptestReports
74 | path: reports/*.*
75 | ```
76 |
77 | ## Example Workflows
78 | The following examples show simple workflows made up of one job "Analyze project with C/C++test" for Make and CMake-based projects. The examples assume that C/C++test is run on a self-hosted runner and the path to the `cpptestcli` executable is available on `$PATH`.
79 |
80 | #### Run C/C++test with CMake project
81 |
82 | ```yaml
83 |
84 | # This is a basic workflow to help you get started with the Run C/C++test action for a CMake-based project.
85 | name: C/C++test with CMake
86 |
87 | on:
88 | # Triggers the workflow on push or pull request events but only for the master (main) branch.
89 | push:
90 | branches: [ master, main ]
91 | pull_request:
92 | branches: [ master, main ]
93 |
94 | # Allows you to run this workflow manually from the Actions tab.
95 | workflow_dispatch:
96 |
97 | # A workflow run is made up of one or more jobs that can run sequentially or in parallel.
98 | jobs:
99 | run-cpptest-make:
100 | name: Analyze project with C/C++test
101 |
102 | # Specifies required permissions for upload-sarif action
103 | permissions:
104 | # required for all workflows
105 | security-events: write
106 | # only required for workflows in private repositories
107 | actions: read
108 | contents: read
109 |
110 | # Specifies the type of runner that the job will run on.
111 | runs-on: self-hosted
112 |
113 | # Steps represent a sequence of tasks that will be executed as part of the job.
114 | steps:
115 |
116 | # Checks out your repository under $GITHUB_WORKSPACE, so that your job can access it.
117 | - name: Checkout code
118 | uses: actions/checkout@v4
119 |
120 | # Configures your CMake project. Be sure the compile_commands.json file is created.
121 | - name: Configure project
122 | run: cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=1 -S . -B build
123 |
124 | # Builds your CMake project. (This step is optional, as it is not required for code analysis).
125 | - name: Build project (optional)
126 | run: cmake --build build
127 |
128 | # Runs code analysis with C/C++test.
129 | - name: Run C/C++test
130 | # Use the 'run-cpptest-action' GitHub action.
131 | uses: parasoft/run-cpptest-action@2.0.2
132 | # Optional parameters for 'run-cpptest-action'.
133 | with:
134 | # For CMake-based projects, use a compile_commands.json file as the input for analysis.
135 | input: build/compile_commands.json
136 | # Uncomment if you are using C/C++test 2020.2 to generate a SARIF report:
137 | # reportFormat: xml,html,custom
138 | # additionalParams: '-property report.custom.extension=sarif -property report.custom.xsl.file=${PARASOFT_SARIF_XSL}'
139 |
140 | # Uploads analysis results in the SARIF format, so that they are displayed as GitHub code scanning alerts.
141 | - name: Upload results (SARIF)
142 | if: always()
143 | uses: github/codeql-action/upload-sarif@v3
144 | with:
145 | sarif_file: reports/report.sarif
146 |
147 | # Uploads an archive that includes all report files (.xml, .html, .sarif).
148 | - name: Archive reports
149 | if: always()
150 | uses: actions/upload-artifact@v4
151 | with:
152 | name: CpptestReports
153 | path: reports/*.*
154 |
155 | ```
156 |
157 | #### Run C/C++test with Make project
158 |
159 | ```yaml
160 |
161 | # This is a basic workflow to help you get started with the Run C/C++test action for Make-based project.
162 | name: C/C++test with Make
163 |
164 | on:
165 | # Triggers the workflow on push or pull request events but only for the master (main) branch.
166 | push:
167 | branches: [ master, main ]
168 | pull_request:
169 | branches: [ master, main ]
170 |
171 | # Allows you to run this workflow manually from the Actions tab.
172 | workflow_dispatch:
173 |
174 | # A workflow run is made up of one or more jobs that can run sequentially or in parallel.
175 | jobs:
176 | run-cpptest-make:
177 | name: Analyze project with C/C++test
178 |
179 | # Specifies the type of runner that the job will run on.
180 | runs-on: self-hosted
181 |
182 | # Specifies required permissions for upload-sarif action
183 | permissions:
184 | # required for all workflows
185 | security-events: write
186 | # only required for workflows in private repositories
187 | actions: read
188 | contents: read
189 |
190 | # Steps represent a sequence of tasks that will be executed as part of the job.
191 | steps:
192 |
193 | # Checks out your repository under $GITHUB_WORKSPACE, so that your job can access it.
194 | - name: Checkout code
195 | uses: actions/checkout@v4
196 |
197 | # Builds your Make project using 'cpptesttrace' to collect input data for code analysis.
198 | # Be sure 'cpptesttrace' is available on $PATH.
199 | - name: Build project
200 | run: cpptesttrace make clean all
201 |
202 | # Runs code analysis with C/C++test.
203 | - name: Run C/C++test
204 | # Use the 'run-cpptest-action' GitHub action.
205 | uses: parasoft/run-cpptest-action@2.0.2
206 | # Uncomment if you are using C/C++test 2020.2 to generate a SARIF report:
207 | # with:
208 | # reportFormat: xml,html,custom
209 | # additionalParams: '-property report.custom.extension=sarif -property report.custom.xsl.file=${PARASOFT_SARIF_XSL}'
210 |
211 | # Uploads analysis results in the SARIF format, so that they are displayed as GitHub code scanning alerts.
212 | - name: Upload results (SARIF)
213 | if: always()
214 | uses: github/codeql-action/upload-sarif@v3
215 | with:
216 | sarif_file: reports/report.sarif
217 |
218 | # Uploads an archive that includes all report files (.xml, .html, .sarif).
219 | - name: Archive reports
220 | if: always()
221 | uses: actions/upload-artifact@v4
222 | with:
223 | name: CpptestReports
224 | path: reports/*.*
225 |
226 | ```
227 | ## Configuring Analysis with C/C++test
228 | You can configure analysis with Parasoft C/C++test in the following ways:
229 | - By customizing the `Run C/C++test` action directly in your GitHub workflow. See [Action Parameters](#action-parameters) for a complete list of available parameters.
230 | - By configuring options in Parasoft C/C++test tool. We recommend creating a `cpptestcli.properties` file that includes all the configuration options and adding the file to C/C++test's working directory - typically, the root directory of your repository. This allows C/C++test to automatically read all the configuration options from that file. See [Parasoft C/C++test User Guide](https://docs.parasoft.com/display/CPPTEST20251/Configuration+1) for details.
231 |
232 | ### Examples
233 | This section includes practical examples of how the `Run C/C++test` action can be customized directly in the YAML file of your workflow.
234 |
235 | #### Configuring the Path to the C/C++test Installation Directory
236 | If `cpptestcli` executable is not on `$PATH`, you can configure the path to the installation directory of Parasoft C/C++test, by configuring the `installDir` parameter:
237 |
238 | ```yaml
239 | - name: Run C/C++test
240 | uses: parasoft/run-cpptest-action@2.0.2
241 | with:
242 | installDir: '/opt/parasoft/cpptest'
243 | ```
244 |
245 | #### Defining the Scope of Analysis
246 | You can configure the `input` parameter to provide the path to a file that defines the scope of analysis (includes a list of source files and compile commands). This parameter depends on the project type and the build system you are using. See the [C/C++test User Guide](https://docs.parasoft.com/display/CPPTEST20251/Running+Static+Analysis+1) for details.
247 | ```yaml
248 | - name: Run C/C++test
249 | uses: parasoft/run-cpptest-action@2.0.2
250 | with:
251 | input: 'build/compile_commands.json'
252 | ```
253 |
254 | #### Configuring a C/C++test Test Configuration
255 | Code analysis with C/C++test is performed by using a test configuration - a set of static analysis rules that enforce best coding practices or compliance guidelines. Parasoft C/C++test ships with a wide range of [built-in test configurations](https://docs.parasoft.com/display/CPPTEST20251/Builtin+Test+Configurations).
256 | To specify a test configuration directly in your workflow, add the `testConfig` parameter to the `Run C/C++test` action and specify the URL of the test configuration you want to use:
257 | ```yaml
258 | - name: Run C/C++test
259 | uses: parasoft/run-cpptest-action@2.0.2
260 | with:
261 | testConfig: 'builtin://MISRA C 2012'
262 | ```
263 |
264 | #### Configuring a C/C++test Compiler Configuration
265 | In order to run analysis, C/C++test needs to be configured for a specific compiler. You need to specify the configuration that matches your compiler with the `compilerConfig` parameter. See [Supported Compilers](https://docs.parasoft.com/display/CPPTEST20251/Supported+Compilers) for information about supported compilers.
266 | ```yaml
267 | - name: Run C/C++test
268 | uses: parasoft/run-cpptest-action@2.0.2
269 | with:
270 | compilerConfig: 'clang_10_0'
271 | ```
272 |
273 | #### Generating SARIF Reports with C/C++test 2020.2 or Earlier
274 | Generating reports in the SARIF format is available in C/C++test since version 2021.1. If you are using an earlier C/C++test version, you need to customize the `Run C/C++test` action to enable generating SARIF reports:
275 | ```yaml
276 | - name: Run C/C++test
277 | uses: parasoft/run-cpptest-action@2.0.2
278 | with:
279 | reportFormat: xml,html,custom
280 | additionalParams: '-property report.custom.extension=sarif -property report.custom.xsl.file=${PARASOFT_SARIF_XSL}'
281 | ```
282 |
283 | #### Baselining Static Analysis Results in Pull Requests
284 | In GitHub, when a pull request is created, static analysis results generated for the branch to be merged are compared with the results generated for the integration branch. As a result, only new violations are presented, allowing developers to focus on the relevant problems for their code changes.
285 | For this baselining to succeed, make sure your static analysis workflow triggers for pull requests. For example:
286 | ```yaml
287 | on:
288 | # Triggers the workflow on push or pull request events but only for the main branch.
289 | pull_request:
290 | branches: [ main ]
291 | ```
292 |
293 | ##### Defining the Branch Protection Rule
294 | You can define a branch protection rule for your integration branch that will block pull requests due to new violations or errors. To configure this:
295 | 1. In the GitHub repository GUI, go to **Settings>Branches**.
296 | 1. Make sure your default integration branch is configured. If needed, select the appropriate branch in the **Default branch** section.
297 | 1. Define the branch protection rule. In the **Branch protection rule** section click **Add rule**. Enable the **Require status checks to pass before merging** option and specify which steps in the pipeline should block the merge. Type the status check name in the search field to select it (only the status checks run during the last week are listed).
298 | - You can specify that the merge will be blocked if any violations are found as a result of the analysis by selecting the appropriate GitHub Code Scanning tool. If the GitHub Code Scanning tool is not available, you need to run a pull request for the integration branch first.
299 | - You can specify that the merge will be blocked if any defined job is not completed because of errors in its configuration by selecting the job build name. If no jobs are available, you need to run a workflow from the integration branch first. For example, when you execute the default C/C+test pipeline, the 'Analyze project with C/C++test' job will be available and can be used as a status check.
300 |
301 | If a pull request is blocked due to failed checks, the administrator can still manually perform the merge using the **Merge without waiting for requirements to be met** option.
302 |
303 | ## Action Parameters
304 | The following inputs are available for this action:
305 | | Input | Description |
306 | | --- | --- |
307 | | `installDir` | Installation folder of Parasoft C/C++test. If not specified, the `cpptestcli` executable must be added to `$PATH`.|
308 | | `workingDir` | Working directory for running C/C++test. If not specified, `${{ github.workspace }}` will be used.|
309 | | `compilerConfig` | Identifier of a compiler configuration. Ensure you specify the configuration that matches your compiler. If not specified, the `gcc_9-64` configuration will be used.|
310 | | `testConfig` | Test configuration to be used for code analysis. The default is `builtin://Recommended Rules`.|
311 | | `reportDir` | Output folder for reports from code analysis. If not specified, report files will be created in the `reports` folder.|
312 | | `reportFormat`| Format of reports from code analysis. The default is `xml,html,sarif`.|
313 | | `input` | Input scope for analysis (typically, `cpptestscan.bdf` or `compile_commands.json`, depending on the project type and the build system). The default is `cpptestscan.bdf`.|
314 | | `additionalParams` | Additional parameters for the `cpptestcli` executable.|
315 | | `commandLinePattern` | Command line pattern for running C/C++test. It should only be modified in advanced scenarios. The default is: `${cpptestcli} -compiler "${compilerConfig}" -config "${testConfig}" -property report.format=${reportFormat} -report "${reportDir}" -module . -input "${input}" ${additionalParams}`|
316 |
317 | ## Customizing the Action to Run C/C++test Professional
318 | This section describes how to customize the `Run C/C++test` action to run code analysis with Parasoft C/C++test Professional.
319 |
320 | ### Updating the Command Line for C/C++test Professional
321 | Use the `commandLinePattern` parameter to modify the command line for `cpptestcli` executable. The command line pattern depends on your project and the setup of the workspace. Example:
322 | ```yaml
323 | - name: Run C/C++test
324 | uses: parasoft/run-cpptest-action@2.0.2
325 | with:
326 | # C/C++test workspace will be created in '../workspace'.
327 | # C/C++test will create a new project based on the provided .bdf file.
328 | commandLinePattern: '${cpptestcli} -data ../workspace -config "${testConfig}" -report "${reportDir}" -bdf "${input}" ${additionalParams}'
329 | ```
330 | Note: The `compilerConfig` and `reportFormat` action parameters are not directly applicable to the C/C++test Professional command line.
331 |
332 | ### Using Additional Configuration Options
333 | Create a `config.properties` file with additional configuration options for C/C++test Professional, such as reporting options, compiler configuration etc. Then pass the configuration file to `cpptestcli` with the `-localsettings config.properties` option:
334 | ```yaml
335 | - name: Run C/C++test
336 | uses: parasoft/run-cpptest-action@2.0.2
337 | with:
338 | # C/C++test will use options from 'config.properties'.
339 | additionalParams: '-localsettings config.properties'
340 | commandLinePattern: '${cpptestcli} -data ../workspace -config "${testConfig}" -report "${reportDir}" -bdf "${input}" ${additionalParams}'
341 | ```
342 | ### Generating SARIF Reports with C/C++test Professional
343 | To enable generating SARIF reports, add the following options to the `config.properties` file.
344 |
345 | In C/C++test Professional 2021.1 or newer:
346 | ```
347 | report.format=sarif
348 | ```
349 |
350 | In C/C++test Professional 2020.2 or earlier:
351 | ```
352 | report.format=custom
353 | report.custom.extension=sarif
354 | report.custom.xsl.file=${PARASOFT_SARIF_PRO_XSL}
355 | report.location_details=true
356 | ```
357 |
--------------------------------------------------------------------------------
/action.yml:
--------------------------------------------------------------------------------
1 | name: 'Run Parasoft C/C++test'
2 | description: 'A GitHub Action for running Parasoft C/C++test to ensure code quality and compliance with MISRA, AUTOSAR, CERT, and more.'
3 | author: 'Parasoft'
4 | branding:
5 | icon: 'aperture'
6 | color: 'blue'
7 | inputs:
8 | installDir:
9 | description: 'Installation folder of Parasoft C/C++test. If not specified, the cpptestcli executable must be added to $PATH.'
10 | required: false
11 | workingDir:
12 | description: 'Working directory for running C/C++test.'
13 | required: false
14 | default: ${{ github.workspace }}
15 | compilerConfig:
16 | description: 'Identifier of a compiler configuration. Ensure you specify the configuration that matches your compiler.'
17 | required: false
18 | default: 'gcc_9-64'
19 | testConfig:
20 | description: 'Test configuration to be used for code analysis.'
21 | required: false
22 | default: 'builtin://Recommended Rules'
23 | reportDir:
24 | description: 'Output folder for reports from code analysis.'
25 | required: false
26 | default: 'reports'
27 | reportFormat:
28 | description: 'Format of reports from code analysis.'
29 | required: false
30 | default: 'xml,html,sarif'
31 | input:
32 | description: 'Input scope for analysis (typically, cpptestscan.bdf or compile_commands.json, depending on the project type and the build system).'
33 | required: false
34 | default: 'cpptestscan.bdf'
35 | additionalParams:
36 | description: 'Additional parameters for the cpptestcli executable.'
37 | required: false
38 | default: ''
39 | commandLinePattern:
40 | description: 'Command line pattern for running C/C++test.'
41 | required: false
42 | default: '${cpptestcli} -compiler "${compilerConfig}" -config "${testConfig}" -property report.format=${reportFormat} -report "${reportDir}" -module . -input "${input}" ${additionalParams}'
43 | runs:
44 | using: 'node20'
45 | main: 'dist/index.js'
46 |
--------------------------------------------------------------------------------
/dist/licenses.txt:
--------------------------------------------------------------------------------
1 | @actions/core
2 | MIT
3 | The MIT License (MIT)
4 |
5 | Copyright 2019 GitHub
6 |
7 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
8 |
9 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
10 |
11 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
12 |
13 | @actions/http-client
14 | MIT
15 | Actions Http Client for Node.js
16 |
17 | Copyright (c) GitHub, Inc.
18 |
19 | All rights reserved.
20 |
21 | MIT License
22 |
23 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
24 | associated documentation files (the "Software"), to deal in the Software without restriction,
25 | including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
26 | and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
27 | subject to the following conditions:
28 |
29 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
30 |
31 | THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
32 | LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
33 | NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
34 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
35 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
36 |
37 |
38 | tunnel
39 | MIT
40 | The MIT License (MIT)
41 |
42 | Copyright (c) 2012 Koichi Kobayashi
43 |
44 | Permission is hereby granted, free of charge, to any person obtaining a copy
45 | of this software and associated documentation files (the "Software"), to deal
46 | in the Software without restriction, including without limitation the rights
47 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
48 | copies of the Software, and to permit persons to whom the Software is
49 | furnished to do so, subject to the following conditions:
50 |
51 | The above copyright notice and this permission notice shall be included in
52 | all copies or substantial portions of the Software.
53 |
54 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
55 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
56 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
57 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
58 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
59 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
60 | THE SOFTWARE.
61 |
62 |
63 | uuid
64 | MIT
65 | The MIT License (MIT)
66 |
67 | Copyright (c) 2010-2020 Robert Kieffer and other contributors
68 |
69 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
70 |
71 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
72 |
73 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
74 |
--------------------------------------------------------------------------------
/dist/messages/messages.json:
--------------------------------------------------------------------------------
1 | {
2 | "run_started": "Running C/C++test in ",
3 | "run_failed": "Failed to run C/C++test",
4 | "exit_code": "C/C++test run finished with code ",
5 | "failed_run_non_zero": "C/C++test run failed with a non-zero exit code: ",
6 | "wrk_dir_not_exist": "Working directory does not exist: ",
7 | "cmd_cannot_be_empty": "Command line cannot be empty."
8 | }
9 |
--------------------------------------------------------------------------------
/dist/sarif-pro.xsl:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | true
7 | true
8 | true
9 |
10 | "
11 | true
12 | true
13 |
14 |
15 |
16 |
17 | { "$schema": "https://raw.githubusercontent.com/oasis-tcs/sarif-spec/master/Schemata/sarif-schema-2.1.0.json", "version": "2.1.0", "runs": [ {
18 | "tool": { "driver": {
19 | "name": "C/C++test",
20 | "semanticVersion": "",
21 |
22 | "rules": [
23 |
24 | ] } }, "results": [
25 |
26 |
27 | ] } ] }
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 | false
69 |
70 |
71 | ,
72 |
73 |
74 |
75 | {
76 | "id": ""
77 | , "shortDescription": { "text": "
78 |
79 | " }
80 | , "fullDescription": { "text": "
81 |
82 | []
83 | " }
84 | , "defaultConfiguration": {
85 |
86 |
87 |
88 | }
89 | , "help": { "text": "
90 |
91 | []
92 | " }
93 | , "properties": { "tags": [ ] }
94 | }
95 |
96 |
97 |
98 | true
99 |
100 |
101 |
102 |
103 | false
104 |
105 |
106 | ,
107 |
108 |
109 |
110 |
111 |
112 |
113 |
114 | {
115 | "ruleId": ""
116 | ,
117 |
118 |
119 |
120 | , "message": { "text": "
121 |
122 | " }
123 | , "partialFingerprints": {
124 |
127 | }
128 | , "locations": [
129 |
130 |
131 |
132 |
133 |
134 |
135 |
136 | { }
137 |
138 |
139 | ]
140 |
141 |
142 | , "codeFlows": [ {
143 | "threadFlows": [ { "locations": [
144 | true
145 |
146 |
147 |
148 | 0
149 |
150 | ]
151 | } ] } ]
152 |
153 |
154 |
155 | , "suppressions": [ { "kind": "external" } ]
156 |
157 | }
158 |
159 |
160 |
161 | "physicalLocation": {
162 |
163 | ,
164 |
165 |
166 |
167 |
168 |
169 |
170 | }
171 |
172 |
173 |
174 |
175 |
176 | true
177 |
178 |
179 |
180 | false
181 |
182 |
183 | ,
184 |
185 |
186 | { }
187 |
188 |
189 |
190 |
191 |
192 |
193 |
194 |
195 |
196 |
197 |
198 | false
199 |
200 |
201 | ,
202 |
203 |
204 |
205 |
206 |
207 |
208 |
209 |
210 |
211 |
212 |
213 |
214 |
215 |
216 |
217 |
218 |
219 |
220 |
221 | { "location": {
222 |
223 |
224 |
225 |
226 | }, "nestingLevel":
227 | }
228 |
229 |
230 |
231 | "physicalLocation": {
232 |
233 | ,
234 |
235 |
236 |
237 |
238 |
239 |
240 | }
241 |
242 |
243 |
244 |
245 |
246 |
247 |
248 | , "message": { "text": "Review duplicate in" }
249 |
250 |
251 |
252 | , "message": { "text": "
253 |
254 |
255 | Violation Cause -
256 |
257 |
258 |
259 | Violation Point -
260 |
261 |
262 |
263 |
264 |
265 | ***
266 |
267 |
268 |
269 | " }
270 |
271 |
272 |
273 |
274 |
275 |
276 | "artifactLocation": { "uri": "
277 |
278 |
279 |
280 |
281 |
282 |
283 |
284 |
285 |
286 |
287 |
288 |
289 |
290 |
291 |
292 | file://
293 |
294 |
295 |
296 | file://
297 |
298 |
299 |
300 | file://
301 |
302 |
303 |
304 |
305 | " }
306 |
307 |
308 |
309 |
310 |
311 |
312 |
313 |
314 |
315 |
316 | "region": { "startLine":
317 |
318 |
319 | , "startColumn":
320 |
321 |
322 |
323 |
324 |
325 | 1
326 |
327 |
328 |
329 |
330 |
331 |
332 | , "endLine":
333 |
334 |
335 |
336 |
337 |
338 | , "endLine":
339 |
340 |
341 |
342 |
343 |
344 |
345 | , "endColumn":
346 |
347 |
348 | }
349 |
350 |
351 |
352 |
353 |
354 |
355 |
356 |
357 |
358 |
359 |
360 |
361 |
362 |
363 |
364 |
365 |
366 | \
367 |
368 |
369 |
370 |
371 |
372 |
373 |
374 |
375 |
376 |
377 |
378 |
379 |
380 |
381 |
382 |
383 |
384 |
385 | "level": "
386 |
387 |
388 | error
389 |
390 |
391 | warning
392 |
393 |
394 | note
395 |
396 |
397 | none
398 |
399 |
400 | "
401 |
402 |
403 |
--------------------------------------------------------------------------------
/dist/sarif.xsl:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 | true
8 | true
9 | true
10 |
11 | "
12 | true
13 | true
14 |
15 |
16 |
17 |
18 | { "$schema": "https://raw.githubusercontent.com/oasis-tcs/sarif-spec/master/Schemata/sarif-schema-2.1.0.json", "version": "2.1.0", "runs": [ {
19 | "tool": { "driver": {
20 | "name": "",
21 | "semanticVersion": "",
22 |
23 | "rules": [
24 |
25 | ] } }, "results": [
26 |
27 |
28 | ] } ] }
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 | false
70 |
71 |
72 | ,
73 |
74 |
75 |
76 | {
77 | "id": ""
78 | , "shortDescription": { "text": "
79 |
80 | " }
81 | , "fullDescription": { "text": "
82 |
83 | []
84 | " }
85 | , "defaultConfiguration": {
86 |
87 |
88 |
89 | }
90 | , "help": { "text": "
91 |
92 |
93 | []
94 |
95 | " }
96 | , "properties": { "tags": [ ] }
97 | }
98 |
99 |
100 |
101 | true
102 |
103 |
104 |
105 |
106 | false
107 |
108 |
109 | ,
110 |
111 |
112 |
113 |
114 |
115 |
116 |
117 |
118 | {
119 | "ruleId": ""
120 | ,
121 |
122 |
123 |
124 | , "message": { "text": "
125 |
126 | " }
127 | , "partialFingerprints": {
128 |
129 | "lineHash": ""
130 |
131 | }
132 | , "locations": [
133 |
134 |
135 |
136 |
137 |
138 |
139 |
140 | { }
141 |
142 |
143 | ]
144 |
145 |
146 | , "codeFlows": [ {
147 | "threadFlows": [ { "locations": [
148 | true
149 |
150 |
151 |
152 | 0
153 |
154 | ]
155 | } ] } ]
156 |
157 |
158 |
159 | , "suppressions": [ { "kind": "external" } ]
160 |
161 | }
162 |
163 |
164 |
165 | "physicalLocation": {
166 |
167 | ,
168 |
169 |
170 |
171 |
172 |
173 |
174 | }
175 |
176 |
177 |
178 |
179 |
180 | true
181 |
182 |
183 |
184 | false
185 |
186 |
187 | ,
188 |
189 |
190 | { }
191 |
192 |
193 |
194 |
195 |
196 |
197 |
198 |
199 |
200 |
201 |
202 |
203 |
204 |
205 | false
206 |
207 |
208 | ,
209 |
210 |
211 |
212 |
213 |
214 |
215 |
216 |
217 |
218 |
219 |
220 |
221 |
222 |
223 |
224 |
225 |
226 |
227 |
228 |
229 |
230 |
231 |
232 |
233 |
234 |
235 |
236 |
237 | { "location": {
238 |
239 |
240 |
241 |
242 | }, "nestingLevel":
243 | }
244 |
245 |
246 |
247 | "physicalLocation": {
248 |
249 | ,
250 |
251 |
252 |
253 |
254 |
255 |
256 | }
257 |
258 |
259 |
260 |
261 |
262 |
263 |
264 | , "message": { "text": "Review duplicate in" }
265 |
266 |
267 |
268 | , "message": { "text": "
269 |
270 |
271 | Violation Cause -
272 |
273 |
274 |
275 | Violation Point -
276 |
277 |
278 |
279 |
280 |
281 | ***
282 |
283 |
284 |
285 | " }
286 |
287 |
288 |
289 |
290 |
291 |
292 | "artifactLocation": { "uri": "
293 |
294 |
295 |
296 |
297 |
298 |
299 |
300 |
301 |
302 |
303 |
304 |
305 |
306 |
307 |
308 | " }
309 |
310 |
311 |
312 |
313 |
314 |
315 |
316 |
317 |
318 |
319 | "region": { "startLine":
320 |
321 |
322 | , "startColumn":
323 |
324 |
325 |
326 |
327 |
328 | 1
329 |
330 |
331 |
332 |
333 |
334 |
335 | , "endLine":
336 |
337 |
338 |
339 |
340 |
341 | , "endLine":
342 |
343 |
344 |
345 |
346 |
347 |
348 | , "endColumn":
349 |
350 |
351 | }
352 |
353 |
354 |
355 |
356 |
357 |
358 |
359 |
360 |
361 |
362 |
363 |
364 |
365 |
366 |
367 |
368 |
369 | \
370 |
371 |
372 |
373 |
374 |
375 |
376 |
377 |
378 |
379 |
380 |
381 |
382 |
383 |
384 |
385 |
386 |
387 |
388 | "level": "
389 |
390 |
391 | error
392 |
393 |
394 | warning
395 |
396 |
397 | note
398 |
399 |
400 | none
401 |
402 |
403 | "
404 |
405 |
406 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "run-cpptest-action",
3 | "version": "2.0.3",
4 | "private": true,
5 | "description": "A GitHub Action for running Parasoft C/C++test analysis",
6 | "main": "lib/main.js",
7 | "scripts": {
8 | "compile": "tsc -p ./",
9 | "watch": "tsc -watch -p ./",
10 | "lint": "eslint --ext .ts .",
11 | "test": "nyc mocha -u tdd -r ts-node/register 'tests/**/*.ts'",
12 | "package": "ncc build --license licenses.txt && copyfiles --flat ./src/messages/*.json ./dist/messages && copyfiles --flat ./samples/*.xsl ./dist",
13 | "clean": "rimraf dist",
14 | "all": "npm run clean && npm run compile && npm run lint && npm run test && npm run package"
15 | },
16 | "repository": {
17 | "type": "git",
18 | "url": "git+https://github.com/parasoft/run-cpptest-action.git"
19 | },
20 | "author": {
21 | "name": "Parasoft Corp.",
22 | "url": "https://github.com/parasoft"
23 | },
24 | "license": "Apache-2.0",
25 | "bugs": {
26 | "url": "https://github.com/parasoft/run-cpptest-action/issues"
27 | },
28 | "homepage": "https://github.com/parasoft/run-cpptest-action#readme",
29 | "dependencies": {
30 | "@actions/core": "^1.10.0",
31 | "@actions/exec": "^1.1.1",
32 | "@actions/github": "^6.0.0",
33 | "@actions/http-client": "1.0.11",
34 | "@actions/io": "^1.1.2"
35 | },
36 | "devDependencies": {
37 | "@types/chai": "^4.3.4",
38 | "@types/mocha": "^9.1.1",
39 | "@types/node": "^20.12.12",
40 | "@types/sinon": "^10.0.13",
41 | "@typescript-eslint/eslint-plugin": "^4.33.0",
42 | "@typescript-eslint/parser": "^4.33.0",
43 | "@vercel/ncc": "^0.36.1",
44 | "chai": "^4.3.7",
45 | "copyfiles": "^2.4.1",
46 | "cross-env": "^7.0.3",
47 | "eslint": "^7.32.0",
48 | "fs-extra": "^10.1.0",
49 | "mocha": "^10.4.0",
50 | "nyc": "^15.1.0",
51 | "sinon": "^15.0.1",
52 | "ts-node": "^10.9.2",
53 | "typescript": "^4.9.4",
54 | "typescript-eslint": "0.0.1-alpha.0"
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/samples/cpptest-cmake.yml:
--------------------------------------------------------------------------------
1 | # This is a basic workflow to help you get started with the Run C/C++test action for a CMake-based project.
2 | name: C/C++test with CMake
3 |
4 | on:
5 | # Triggers the workflow on push or pull request events but only for the master (main) branch.
6 | push:
7 | branches: [ master, main ]
8 | pull_request:
9 | branches: [ master, main ]
10 |
11 | # Allows you to run this workflow manually from the Actions tab.
12 | workflow_dispatch:
13 |
14 | # A workflow run is made up of one or more jobs that can run sequentially or in parallel.
15 | jobs:
16 | run-cpptest-make:
17 | name: Analyze project with C/C++test
18 |
19 | # Specifies required permissions for upload-sarif action
20 | permissions:
21 | # required for all workflows
22 | security-events: write
23 | # only required for workflows in private repositories
24 | actions: read
25 | contents: read
26 |
27 | # Specifies the type of runner that the job will run on.
28 | runs-on: self-hosted
29 |
30 | # Steps represent a sequence of tasks that will be executed as part of the job.
31 | steps:
32 |
33 | # Checks out your repository under $GITHUB_WORKSPACE, so that your job can access it.
34 | - name: Checkout code
35 | uses: actions/checkout@v4
36 |
37 | # Configures your CMake project. Be sure the compile_commands.json file is created.
38 | - name: Configure project
39 | run: cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=1 -S . -B build
40 |
41 | # Builds your CMake project. (This step is optional, as it is not required for code analysis).
42 | - name: Build project (optional)
43 | run: cmake --build build
44 |
45 | # Runs code analysis with C/C++test.
46 | - name: Run C/C++test
47 | # Use the 'run-cpptest-action' GitHub action.
48 | uses: parasoft/run-cpptest-action@2.0.2
49 | # Optional parameters for 'run-cpptest-action'.
50 | with:
51 | # For CMake-based projects, use a compile_commands.json file as the input for analysis.
52 | input: build/compile_commands.json
53 | # Uncomment if you are using C/C++test 2020.2 to generate a SARIF report:
54 | # reportFormat: xml,html,custom
55 | # additionalParams: '-property report.custom.extension=sarif -property report.custom.xsl.file=${PARASOFT_SARIF_XSL}'
56 |
57 | # Uploads analysis results in the SARIF format, so that they are displayed as GitHub code scanning alerts.
58 | - name: Upload results (SARIF)
59 | if: always()
60 | uses: github/codeql-action/upload-sarif@v3
61 | with:
62 | sarif_file: reports/report.sarif
63 |
64 | # Uploads an archive that includes all report files (.xml, .html, .sarif).
65 | - name: Archive reports
66 | if: always()
67 | uses: actions/upload-artifact@v4
68 | with:
69 | name: Static analysis reports
70 | path: reports/*.*
71 |
--------------------------------------------------------------------------------
/samples/cpptest-make.yml:
--------------------------------------------------------------------------------
1 | # This is a basic workflow to help you get started with the Run C/C++test action for Make-based project.
2 | name: C/C++test with Make
3 |
4 | on:
5 | # Triggers the workflow on push or pull request events but only for the master (main) branch.
6 | push:
7 | branches: [ master, main ]
8 | pull_request:
9 | branches: [ master, main ]
10 |
11 | # Allows you to run this workflow manually from the Actions tab.
12 | workflow_dispatch:
13 |
14 | # A workflow run is made up of one or more jobs that can run sequentially or in parallel.
15 | jobs:
16 | run-cpptest-make:
17 | name: Analyze project with C/C++test
18 |
19 | # Specifies required permissions for upload-sarif action
20 | permissions:
21 | # required for all workflows
22 | security-events: write
23 | # only required for workflows in private repositories
24 | actions: read
25 | contents: read
26 |
27 | # Specifies the type of runner that the job will run on.
28 | runs-on: self-hosted
29 |
30 | # Steps represent a sequence of tasks that will be executed as part of the job.
31 | steps:
32 |
33 | # Checks out your repository under $GITHUB_WORKSPACE, so that your job can access it.
34 | - name: Checkout code
35 | uses: actions/checkout@v4
36 |
37 | # Builds your Make project using 'cpptesttrace' to collect input data for code analysis.
38 | # Be sure 'cpptesttrace' is available on $PATH.
39 | - name: Build project
40 | run: cpptesttrace make clean all
41 |
42 | # Runs code analysis with C/C++test.
43 | - name: Run C/C++test
44 | # Use the 'run-cpptest-action' GitHub action.
45 | uses: parasoft/run-cpptest-action@2.0.2
46 | # Uncomment if you are using C/C++test 2020.2 to generate a SARIF report:
47 | # with:
48 | # reportFormat: xml,html,custom
49 | # additionalParams: '-property report.custom.extension=sarif -property report.custom.xsl.file=${PARASOFT_SARIF_XSL}'
50 |
51 | # Uploads analysis results in the SARIF format, so that they are displayed as GitHub code scanning alerts.
52 | - name: Upload results (SARIF)
53 | if: always()
54 | uses: github/codeql-action/upload-sarif@v3
55 | with:
56 | sarif_file: reports/report.sarif
57 |
58 | # Uploads an archive that includes all report files (.xml, .html, .sarif).
59 | - name: Archive reports
60 | if: always()
61 | uses: actions/upload-artifact@v4
62 | with:
63 | name: Static analysis reports
64 | path: reports/*.*
65 |
--------------------------------------------------------------------------------
/samples/cpptest-pro-make.yml:
--------------------------------------------------------------------------------
1 | # This is a basic workflow to help you get started with the Run C/C++test action
2 | # for Make-based project for C/C++test Professional.
3 | name: C/C++test with Make
4 |
5 | on:
6 | # Triggers the workflow on push or pull request events but only for the master (main) branch.
7 | push:
8 | branches: [ master, main ]
9 | pull_request:
10 | branches: [ master, main ]
11 |
12 | # Allows you to run this workflow manually from the Actions tab.
13 | workflow_dispatch:
14 |
15 | # A workflow run is made up of one or more jobs that can run sequentially or in parallel.
16 | jobs:
17 | run-cpptest-make:
18 | name: Analyze project with C/C++test
19 |
20 | # Specifies required permissions for upload-sarif action
21 | permissions:
22 | # required for all workflows
23 | security-events: write
24 | # only required for workflows in private repositories
25 | actions: read
26 | contents: read
27 |
28 | # Specifies the type of runner that the job will run on.
29 | runs-on: self-hosted
30 |
31 | # Steps represent a sequence of tasks that will be executed as part of the job.
32 | steps:
33 |
34 | # Checks out your repository under $GITHUB_WORKSPACE, so that your job can access it.
35 | - name: Checkout code
36 | uses: actions/checkout@v4
37 |
38 | # Builds your Make project using 'cpptesttrace' to collect input data for code analysis.
39 | # Be sure 'cpptesttrace' is available on $PATH.
40 | - name: Build project
41 | run: cpptesttrace make clean all
42 |
43 | # Runs code analysis with C/C++test.
44 | - name: Run C/C++test
45 | # Use the 'run-cpptest-action' GitHub action.
46 | uses: parasoft/run-cpptest-action@2.0.2
47 | with:
48 | # To enable SARIF reporting, put additional configuration entries into config.properties file:
49 | # - for C/C++test 2021.1 or newer - using built-in SARIF reporting:
50 | # report.format=sarif
51 | # - for older versions of C/C++test - using legacy SARIF reporting:
52 | # report.format=custom
53 | # report.custom.extension=sarif
54 | # report.custom.xsl.file=${PARASOFT_SARIF_PRO_XSL}
55 | # report.location_details=true
56 | additionalParams: '-localsettings config.properties'
57 | commandLinePattern: '${cpptestcli} -data ../workspace -config "${testConfig}" -report "${reportDir}" -bdf "${input}" ${additionalParams}'
58 |
59 | # Uploads analysis results in the SARIF format, so that they are displayed as GitHub code scanning alerts.
60 | - name: Upload results (SARIF)
61 | if: always()
62 | uses: github/codeql-action/upload-sarif@v3
63 | with:
64 | sarif_file: reports/report.sarif
65 |
66 | # Uploads an archive that includes all report files (.xml, .html, .sarif).
67 | - name: Archive reports
68 | if: always()
69 | uses: actions/upload-artifact@v4
70 | with:
71 | name: Static analysis reports
72 | path: reports/*.*
73 |
--------------------------------------------------------------------------------
/samples/sarif-pro.xsl:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | true
7 | true
8 | true
9 |
10 | "
11 | true
12 | true
13 |
14 |
15 |
16 |
17 | { "$schema": "https://raw.githubusercontent.com/oasis-tcs/sarif-spec/master/Schemata/sarif-schema-2.1.0.json", "version": "2.1.0", "runs": [ {
18 | "tool": { "driver": {
19 | "name": "C/C++test",
20 | "semanticVersion": "",
21 |
22 | "rules": [
23 |
24 | ] } }, "results": [
25 |
26 |
27 | ] } ] }
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 | false
69 |
70 |
71 | ,
72 |
73 |
74 |
75 | {
76 | "id": ""
77 | , "shortDescription": { "text": "
78 |
79 | " }
80 | , "fullDescription": { "text": "
81 |
82 | []
83 | " }
84 | , "defaultConfiguration": {
85 |
86 |
87 |
88 | }
89 | , "help": { "text": "
90 |
91 | []
92 | " }
93 | , "properties": { "tags": [ ] }
94 | }
95 |
96 |
97 |
98 | true
99 |
100 |
101 |
102 |
103 | false
104 |
105 |
106 | ,
107 |
108 |
109 |
110 |
111 |
112 |
113 |
114 | {
115 | "ruleId": ""
116 | ,
117 |
118 |
119 |
120 | , "message": { "text": "
121 |
122 | " }
123 | , "partialFingerprints": {
124 |
127 | }
128 | , "locations": [
129 |
130 |
131 |
132 |
133 |
134 |
135 |
136 | { }
137 |
138 |
139 | ]
140 |
141 |
142 | , "codeFlows": [ {
143 | "threadFlows": [ { "locations": [
144 | true
145 |
146 |
147 |
148 | 0
149 |
150 | ]
151 | } ] } ]
152 |
153 |
154 |
155 | , "suppressions": [ { "kind": "external" } ]
156 |
157 | }
158 |
159 |
160 |
161 | "physicalLocation": {
162 |
163 | ,
164 |
165 |
166 |
167 |
168 |
169 |
170 | }
171 |
172 |
173 |
174 |
175 |
176 | true
177 |
178 |
179 |
180 | false
181 |
182 |
183 | ,
184 |
185 |
186 | { }
187 |
188 |
189 |
190 |
191 |
192 |
193 |
194 |
195 |
196 |
197 |
198 | false
199 |
200 |
201 | ,
202 |
203 |
204 |
205 |
206 |
207 |
208 |
209 |
210 |
211 |
212 |
213 |
214 |
215 |
216 |
217 |
218 |
219 |
220 |
221 | { "location": {
222 |
223 |
224 |
225 |
226 | }, "nestingLevel":
227 | }
228 |
229 |
230 |
231 | "physicalLocation": {
232 |
233 | ,
234 |
235 |
236 |
237 |
238 |
239 |
240 | }
241 |
242 |
243 |
244 |
245 |
246 |
247 |
248 | , "message": { "text": "Review duplicate in" }
249 |
250 |
251 |
252 | , "message": { "text": "
253 |
254 |
255 | Violation Cause -
256 |
257 |
258 |
259 | Violation Point -
260 |
261 |
262 |
263 |
264 |
265 | ***
266 |
267 |
268 |
269 | " }
270 |
271 |
272 |
273 |
274 |
275 |
276 | "artifactLocation": { "uri": "
277 |
278 |
279 |
280 |
281 |
282 |
283 |
284 |
285 |
286 |
287 |
288 |
289 |
290 |
291 |
292 | file://
293 |
294 |
295 |
296 | file://
297 |
298 |
299 |
300 | file://
301 |
302 |
303 |
304 |
305 | " }
306 |
307 |
308 |
309 |
310 |
311 |
312 |
313 |
314 |
315 |
316 | "region": { "startLine":
317 |
318 |
319 | , "startColumn":
320 |
321 |
322 |
323 |
324 |
325 | 1
326 |
327 |
328 |
329 |
330 |
331 |
332 | , "endLine":
333 |
334 |
335 |
336 |
337 |
338 | , "endLine":
339 |
340 |
341 |
342 |
343 |
344 |
345 | , "endColumn":
346 |
347 |
348 | }
349 |
350 |
351 |
352 |
353 |
354 |
355 |
356 |
357 |
358 |
359 |
360 |
361 |
362 |
363 |
364 |
365 |
366 | \
367 |
368 |
369 |
370 |
371 |
372 |
373 |
374 |
375 |
376 |
377 |
378 |
379 |
380 |
381 |
382 |
383 |
384 |
385 | "level": "
386 |
387 |
388 | error
389 |
390 |
391 | warning
392 |
393 |
394 | note
395 |
396 |
397 | none
398 |
399 |
400 | "
401 |
402 |
403 |
--------------------------------------------------------------------------------
/samples/sarif.xsl:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 | true
8 | true
9 | true
10 |
11 | "
12 | true
13 | true
14 |
15 |
16 |
17 |
18 | { "$schema": "https://raw.githubusercontent.com/oasis-tcs/sarif-spec/master/Schemata/sarif-schema-2.1.0.json", "version": "2.1.0", "runs": [ {
19 | "tool": { "driver": {
20 | "name": "",
21 | "semanticVersion": "",
22 |
23 | "rules": [
24 |
25 | ] } }, "results": [
26 |
27 |
28 | ] } ] }
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 | false
70 |
71 |
72 | ,
73 |
74 |
75 |
76 | {
77 | "id": ""
78 | , "shortDescription": { "text": "
79 |
80 | " }
81 | , "fullDescription": { "text": "
82 |
83 | []
84 | " }
85 | , "defaultConfiguration": {
86 |
87 |
88 |
89 | }
90 | , "help": { "text": "
91 |
92 |
93 | []
94 |
95 | " }
96 | , "properties": { "tags": [ ] }
97 | }
98 |
99 |
100 |
101 | true
102 |
103 |
104 |
105 |
106 | false
107 |
108 |
109 | ,
110 |
111 |
112 |
113 |
114 |
115 |
116 |
117 |
118 | {
119 | "ruleId": ""
120 | ,
121 |
122 |
123 |
124 | , "message": { "text": "
125 |
126 | " }
127 | , "partialFingerprints": {
128 |
129 | "lineHash": ""
130 |
131 | }
132 | , "locations": [
133 |
134 |
135 |
136 |
137 |
138 |
139 |
140 | { }
141 |
142 |
143 | ]
144 |
145 |
146 | , "codeFlows": [ {
147 | "threadFlows": [ { "locations": [
148 | true
149 |
150 |
151 |
152 | 0
153 |
154 | ]
155 | } ] } ]
156 |
157 |
158 |
159 | , "suppressions": [ { "kind": "external" } ]
160 |
161 | }
162 |
163 |
164 |
165 | "physicalLocation": {
166 |
167 | ,
168 |
169 |
170 |
171 |
172 |
173 |
174 | }
175 |
176 |
177 |
178 |
179 |
180 | true
181 |
182 |
183 |
184 | false
185 |
186 |
187 | ,
188 |
189 |
190 | { }
191 |
192 |
193 |
194 |
195 |
196 |
197 |
198 |
199 |
200 |
201 |
202 |
203 |
204 |
205 | false
206 |
207 |
208 | ,
209 |
210 |
211 |
212 |
213 |
214 |
215 |
216 |
217 |
218 |
219 |
220 |
221 |
222 |
223 |
224 |
225 |
226 |
227 |
228 |
229 |
230 |
231 |
232 |
233 |
234 |
235 |
236 |
237 | { "location": {
238 |
239 |
240 |
241 |
242 | }, "nestingLevel":
243 | }
244 |
245 |
246 |
247 | "physicalLocation": {
248 |
249 | ,
250 |
251 |
252 |
253 |
254 |
255 |
256 | }
257 |
258 |
259 |
260 |
261 |
262 |
263 |
264 | , "message": { "text": "Review duplicate in" }
265 |
266 |
267 |
268 | , "message": { "text": "
269 |
270 |
271 | Violation Cause -
272 |
273 |
274 |
275 | Violation Point -
276 |
277 |
278 |
279 |
280 |
281 | ***
282 |
283 |
284 |
285 | " }
286 |
287 |
288 |
289 |
290 |
291 |
292 | "artifactLocation": { "uri": "
293 |
294 |
295 |
296 |
297 |
298 |
299 |
300 |
301 |
302 |
303 |
304 |
305 |
306 |
307 |
308 | " }
309 |
310 |
311 |
312 |
313 |
314 |
315 |
316 |
317 |
318 |
319 | "region": { "startLine":
320 |
321 |
322 | , "startColumn":
323 |
324 |
325 |
326 |
327 |
328 | 1
329 |
330 |
331 |
332 |
333 |
334 |
335 | , "endLine":
336 |
337 |
338 |
339 |
340 |
341 | , "endLine":
342 |
343 |
344 |
345 |
346 |
347 |
348 | , "endColumn":
349 |
350 |
351 | }
352 |
353 |
354 |
355 |
356 |
357 |
358 |
359 |
360 |
361 |
362 |
363 |
364 |
365 |
366 |
367 |
368 |
369 | \
370 |
371 |
372 |
373 |
374 |
375 |
376 |
377 |
378 |
379 |
380 |
381 |
382 |
383 |
384 |
385 |
386 |
387 |
388 | "level": "
389 |
390 |
391 | error
392 |
393 |
394 | warning
395 |
396 |
397 | note
398 |
399 |
400 | none
401 |
402 |
403 | "
404 |
405 |
406 |
--------------------------------------------------------------------------------
/src/main.ts:
--------------------------------------------------------------------------------
1 | import * as core from "@actions/core";
2 |
3 | import { messages } from './messages';
4 | import * as runner from './runner';
5 |
6 | export async function run() {
7 | try {
8 |
9 | const runOptions: runner.RunOptions = {
10 | installDir: core.getInput("installDir", { required: false }),
11 | workingDir: core.getInput("workingDir", { required: false }),
12 | compilerConfig: core.getInput("compilerConfig", { required: false }),
13 | testConfig: core.getInput("testConfig", { required: false }),
14 | reportDir: core.getInput("reportDir", { required: false }),
15 | reportFormat: core.getInput("reportFormat", { required: false }),
16 | input: core.getInput("input", { required: false }),
17 | additionalParams: core.getInput("additionalParams", { required: false }),
18 | commandLinePattern: core.getInput("commandLinePattern", { required: false }),
19 | };
20 |
21 | core.info(messages.run_started + runOptions.workingDir);
22 |
23 | const theRunner = new runner.AnalysisRunner();
24 | const outcome = await theRunner.run(runOptions);
25 |
26 | if (outcome.exitCode != 0) {
27 | core.setFailed(messages.failed_run_non_zero + outcome.exitCode);
28 | } else {
29 | core.info(messages.exit_code + outcome.exitCode);
30 | }
31 |
32 | } catch (error) {
33 | core.error(messages.run_failed);
34 | if (error instanceof Error) {
35 | core.error(error);
36 | core.setFailed(error.message);
37 | }
38 | }
39 | }
40 |
41 | if (require.main === module) {
42 | run();
43 | }
--------------------------------------------------------------------------------
/src/messages.ts:
--------------------------------------------------------------------------------
1 | import * as fs from 'fs';
2 | import * as pt from 'path';
3 |
4 | interface ISerializable {
5 | deserialize(jsonPath: string): T;
6 | }
7 |
8 | class Messages implements ISerializable
9 | {
10 | run_started!: string;
11 | run_failed!: string;
12 | exit_code!: string;
13 | failed_run_non_zero!: string;
14 | wrk_dir_not_exist!: string;
15 | cmd_cannot_be_empty!: string;
16 |
17 | deserialize(jsonPath: string) : Messages {
18 | const buf = fs.readFileSync(jsonPath);
19 | const json = JSON.parse(buf.toString('utf-8'));
20 | return json as Messages;
21 | }
22 | }
23 |
24 | const jsonPath = pt.join(__dirname, 'messages/messages.json');
25 | export const messages = new Messages().deserialize(jsonPath);
26 |
--------------------------------------------------------------------------------
/src/messages/messages.json:
--------------------------------------------------------------------------------
1 | {
2 | "run_started": "Running C/C++test in ",
3 | "run_failed": "Failed to run C/C++test",
4 | "exit_code": "C/C++test run finished with code ",
5 | "failed_run_non_zero": "C/C++test run failed with a non-zero exit code: ",
6 | "wrk_dir_not_exist": "Working directory does not exist: ",
7 | "cmd_cannot_be_empty": "Command line cannot be empty."
8 | }
9 |
--------------------------------------------------------------------------------
/src/runner.ts:
--------------------------------------------------------------------------------
1 | import * as cp from 'child_process';
2 | import * as fs from 'fs';
3 | import * as pt from 'path';
4 | import * as core from "@actions/core";
5 |
6 | import { messages } from './messages'
7 |
8 | export interface RunDetails
9 | {
10 | exitCode : number
11 | }
12 |
13 | export interface RunOptions
14 | {
15 | /* Working directory for running C/C++test. */
16 | workingDir: string;
17 |
18 | /* Installation folder of Parasoft C/C++test. */
19 | installDir: string;
20 |
21 | /* Identifier of a compiler configuration. */
22 | compilerConfig: string;
23 |
24 | /* Test configuration to be used when running code analysis. */
25 | testConfig: string;
26 |
27 | /* Output folder for analysis reports. */
28 | reportDir: string;
29 |
30 | /* Format of analysis reports. */
31 | reportFormat: string;
32 |
33 | /* Input scope for analysis - usually cpptestscan.bdf or compile_commands.json. */
34 | input: string;
35 |
36 | /* Additional parameters for cpptestcli executable. */
37 | additionalParams: string;
38 |
39 | /* Command line pattern for running C/C++test. */
40 | commandLinePattern: string
41 | }
42 |
43 | export class AnalysisRunner
44 | {
45 |
46 | async run(runOptions : RunOptions) : Promise
47 | {
48 | if (!fs.existsSync(runOptions.workingDir)) {
49 | return Promise.reject(messages.wrk_dir_not_exist + runOptions.workingDir);
50 | }
51 | const commandLine = this.createCommandLine(runOptions).trim();
52 | if (commandLine.length === 0) {
53 | return Promise.reject(messages.cmd_cannot_be_empty);
54 | }
55 |
56 | core.info(commandLine);
57 |
58 | const runPromise = new Promise((resolve, reject) =>
59 | {
60 | const cliEnv = this.createEnvironment();
61 | const cliProcess = cp.spawn(`${commandLine}`, { cwd: runOptions.workingDir, env: cliEnv, shell: true, windowsHide: true });
62 |
63 | cliProcess.stdout?.on('data', (data) => { core.info(`${data}`.replace(/\s+$/g, '')); });
64 | cliProcess.stderr?.on('data', (data) => { core.info(`${data}`.replace(/\s+$/g, '')); });
65 | cliProcess.on('close', (code) => {
66 | const result : RunDetails = {
67 | exitCode : (code != null) ? code : 150 // 150 = signal received
68 | };
69 | resolve(result);
70 | });
71 | cliProcess.on("error", (err) => { reject(err); });
72 | });
73 |
74 | return runPromise;
75 | }
76 |
77 | private createCommandLine(runOptions : RunOptions) : string
78 | {
79 | let cpptestcli = 'cpptestcli';
80 | if (runOptions.installDir) {
81 | cpptestcli = '"' + pt.join(runOptions.installDir, cpptestcli) + '"';
82 | }
83 |
84 | const commandLine = `${runOptions.commandLinePattern}`.
85 | replace('${cpptestcli}', `${cpptestcli}`).
86 | replace('${workingDir}', `${runOptions.workingDir}`).
87 | replace('${installDir}', `${runOptions.installDir}`).
88 | replace('${compilerConfig}', `${runOptions.compilerConfig}`).
89 | replace('${testConfig}', `${runOptions.testConfig}`).
90 | replace('${reportDir}', `${runOptions.reportDir}`).
91 | replace('${reportFormat}', `${runOptions.reportFormat}`).
92 | replace('${input}', `${runOptions.input}`).
93 | replace('${additionalParams}', `${runOptions.additionalParams}`);
94 |
95 | return commandLine;
96 | }
97 |
98 | private createEnvironment() : NodeJS.ProcessEnv
99 | {
100 | const environment: NodeJS.ProcessEnv = {};
101 | environment['PARASOFT_SARIF_XSL'] = pt.join(__dirname, "sarif.xsl");
102 | environment['PARASOFT_SARIF_PRO_XSL'] = pt.join(__dirname, "sarif-pro.xsl");
103 | let isEncodingVariableDefined = false;
104 | for (const varName in process.env) {
105 | if (Object.prototype.hasOwnProperty.call(process.env, varName)) {
106 | environment[varName] = process.env[varName];
107 | if (varName.toLowerCase() === 'parasoft_console_encoding') {
108 | isEncodingVariableDefined = true;
109 | }
110 | }
111 | }
112 | if (!isEncodingVariableDefined) {
113 | environment['PARASOFT_CONSOLE_ENCODING'] = 'utf-8';
114 | }
115 | return environment;
116 | }
117 |
118 | }
--------------------------------------------------------------------------------
/tests/main.tests.ts:
--------------------------------------------------------------------------------
1 | import * as assert from 'assert';
2 | import * as sinon from 'sinon';
3 |
4 | import * as core from "@actions/core";
5 | import * as main from '../src/main';
6 | import * as runner from '../src/runner';
7 | import { messages } from '../src/messages';
8 |
9 | suite('run-cpptest-action/main', function() {
10 |
11 | const sandbox = sinon.createSandbox();
12 |
13 | let coreSetFailed : sinon.SinonSpy;
14 | let coreInfo : sinon.SinonSpy;
15 | let coreError : sinon.SinonSpy;
16 |
17 | setup(function() {
18 | coreSetFailed = sandbox.fake();
19 | sandbox.replace(core, 'setFailed', coreSetFailed);
20 | coreInfo = sandbox.fake();
21 | sandbox.replace(core, 'info', coreInfo);
22 | coreError = sandbox.fake();
23 | sandbox.replace(core, 'error', coreError);
24 | });
25 |
26 | teardown(function() {
27 | sandbox.restore();
28 | });
29 |
30 | test('Run with exit code 0', async function() {
31 | const runnerExitCode = 0;
32 | const runnerRun = sandbox.fake.resolves( { exitCode: runnerExitCode } );
33 | sandbox.replace(runner.AnalysisRunner.prototype, 'run', runnerRun);
34 |
35 | await main.run();
36 |
37 | assert(coreSetFailed.notCalled);
38 | assert(coreInfo.calledTwice);
39 | assert.strictEqual(coreInfo.args[1][0], messages.exit_code + `${runnerExitCode}`);
40 | });
41 |
42 | test('Run with exit code non-0', async function() {
43 | const runnerExitCode = 123;
44 | const runnerRun = sandbox.fake.resolves( { exitCode: runnerExitCode } );
45 | sandbox.replace(runner.AnalysisRunner.prototype, 'run', runnerRun);
46 |
47 | await main.run();
48 |
49 | assert(coreSetFailed.calledOnce);
50 | assert.strictEqual(coreSetFailed.args[0][0], messages.failed_run_non_zero + `${runnerExitCode}`);
51 | });
52 |
53 | test('Run with configuration problems', async function() {
54 | const errorMessage = 'error message from runner';
55 | const runnerRun = sandbox.fake.rejects(errorMessage);
56 | sandbox.replace(runner.AnalysisRunner.prototype, 'run', runnerRun);
57 |
58 | await main.run();
59 |
60 | assert(coreSetFailed.calledOnce);
61 | assert(coreError.calledTwice);
62 | assert.strictEqual(coreError.args[0][0], messages.run_failed);
63 | assert.strictEqual(coreSetFailed.args[0][0], errorMessage);
64 | });
65 |
66 | test('Run with runtime exceptions', async function() {
67 | const errorMessage = 'error message from runner';
68 | const runnerRun = sandbox.fake.throws(errorMessage)
69 | sandbox.replace(runner.AnalysisRunner.prototype, 'run', runnerRun);
70 |
71 | await main.run();
72 |
73 | assert(coreSetFailed.calledOnce);
74 | assert(coreError.calledTwice);
75 | assert.strictEqual(coreError.args[0][0], messages.run_failed);
76 | assert.strictEqual(coreSetFailed.args[0][0], errorMessage);
77 | });
78 | });
--------------------------------------------------------------------------------
/tests/messages.tests.ts:
--------------------------------------------------------------------------------
1 | import * as assert from 'assert';
2 | import { messages } from '../src/messages'
3 |
4 | suite('run-cpptest-action/messages', function() {
5 |
6 | test('Test messages', function() {
7 | assert.strictEqual(messages.exit_code, 'C/C++test run finished with code ');
8 | assert.strictEqual(messages.run_started, 'Running C/C++test in ');
9 | assert.strictEqual(messages.run_failed, 'Failed to run C/C++test');
10 | assert.strictEqual(messages.failed_run_non_zero, 'C/C++test run failed with a non-zero exit code: ');
11 | assert.strictEqual(messages.wrk_dir_not_exist, 'Working directory does not exist: ');
12 | assert.strictEqual(messages.cmd_cannot_be_empty, 'Command line cannot be empty.');
13 | });
14 |
15 | });
--------------------------------------------------------------------------------
/tests/runner.tests.ts:
--------------------------------------------------------------------------------
1 | import * as assert from 'assert';
2 | import * as sinon from 'sinon';
3 |
4 | import * as core from "@actions/core";
5 | import * as cp from 'child_process';
6 | import * as fs from 'fs';
7 | import * as runner from '../src/runner';
8 | import { messages } from '../src/messages';
9 |
10 | suite('run-cpptest-action/runner', function() {
11 |
12 | const sandbox = sinon.createSandbox();
13 |
14 | teardown(function() {
15 | sandbox.restore();
16 | });
17 |
18 | test('Run - working dir does not exist', async function() {
19 | const fsExistsSync = sandbox.fake.returns(false);
20 | sandbox.replace(fs, 'existsSync', fsExistsSync);
21 |
22 | let runnerError: string | Error | undefined | unknown;
23 | const incorrectWorkindDir = '/incorrect/working/dir';
24 |
25 | try {
26 | const theRunner = new runner.AnalysisRunner()
27 | await theRunner.run({ workingDir : incorrectWorkindDir} as runner.RunOptions);
28 | } catch (error) {
29 | runnerError = error;
30 | }
31 |
32 | assert.strictEqual(runnerError, messages.wrk_dir_not_exist + incorrectWorkindDir);
33 | });
34 |
35 | test('Run - command line is empty', async function() {
36 | const fsExistsSync = sandbox.fake.returns(true);
37 | sandbox.replace(fs, 'existsSync', fsExistsSync);
38 |
39 | let runnerError: string | Error | undefined | unknown;
40 | try {
41 | const theRunner = new runner.AnalysisRunner()
42 | await theRunner.run({ commandLinePattern : ''} as runner.RunOptions);
43 | } catch (error) {
44 | runnerError = error;
45 | }
46 |
47 | assert.strictEqual(runnerError, messages.cmd_cannot_be_empty);
48 | });
49 |
50 | test('Run - launch cpptestcli', async function() {
51 | const fsExistsSync = sandbox.fake.returns(true);
52 | sandbox.replace(fs, 'existsSync', fsExistsSync);
53 | const coreInfo = sandbox.fake();
54 | sandbox.replace(core, 'info', coreInfo);
55 | const cpSpawn = sandbox.fake.returns( {
56 | stdout: undefined,
57 | stderr: undefined,
58 | on: function(_event: string, action : any) {
59 | action();
60 | }
61 | } as any);
62 | sandbox.replace(cp, 'spawn', cpSpawn);
63 |
64 | const expectedCommandLine = '"/opt/parasoft/cpptest/cpptestcli" -compiler "gcc_9-64" -config "builtin://Recommended Rules" -property report.format=xml -report "reportDir" -module . -input "cpptest.bdf" -property key=value';
65 | const theRunner = new runner.AnalysisRunner()
66 | await theRunner.run(
67 | {
68 | installDir: '/opt/parasoft/cpptest',
69 | compilerConfig: 'gcc_9-64',
70 | testConfig: 'builtin://Recommended Rules',
71 | reportDir: 'reportDir',
72 | reportFormat: 'xml',
73 | input: 'cpptest.bdf',
74 | additionalParams: '-property key=value',
75 | commandLinePattern: '${cpptestcli} -compiler "${compilerConfig}" -config "${testConfig}" -property report.format=${reportFormat} -report "${reportDir}" -module . -input "${input}" ${additionalParams}'
76 | } as runner.RunOptions);
77 |
78 | assert.strictEqual(cpSpawn.args[0][0], expectedCommandLine);
79 | assert.strictEqual(coreInfo.args[0][0], expectedCommandLine);
80 | });
81 |
82 | });
--------------------------------------------------------------------------------
/tsconfig.json:
--------------------------------------------------------------------------------
1 | {
2 | "compilerOptions": {
3 | "target": "es2019",
4 | "module": "commonjs",
5 | "outDir": "./lib",
6 | "rootDir": "./src",
7 | "strict": true,
8 | "noImplicitAny": false,
9 | "sourceMap": true,
10 | },
11 | "exclude": [
12 | "node_modules",
13 | "tests"
14 | ]
15 | }
16 |
--------------------------------------------------------------------------------