|
2 | 2 |
|
3 | 3 | Run [SpotBugs](https://spotbugs.readthedocs.io/en/latest/) as a Github action. |
4 | 4 |
|
| 5 | +## Inputs |
| 6 | + |
| 7 | +### outputType |
| 8 | + |
| 9 | +Output type for the report. It can be 'xml', 'html', 'sarif', 'emacs' |
| 10 | +or 'xdocs'. Default value is 'sarif' as it is the used by GitHub Advanced |
| 11 | +Security. |
| 12 | + |
| 13 | +> default: 'sarif' <br/> |
| 14 | +> required: true |
| 15 | +
|
| 16 | +### packages |
| 17 | + |
| 18 | +Comma separated list of packages to scan. It will fill the |
| 19 | +-onlyAnalyze parameter in spotbugs. It can contain the wildcards '\*' and |
| 20 | +'-': com.example.\* for single package or com.example.- for all |
| 21 | +subpackages. |
| 22 | + |
| 23 | +> If not specified, it will scan all packages. |
| 24 | +
|
| 25 | +See more at https://spotbugs.readthedocs.io/en/stable/running.html#text-ui-options |
| 26 | + |
| 27 | +### arguments |
| 28 | + |
| 29 | +A string with any additional command arguments to be sent to [spotbugs](https://spotbugs.readthedocs.io/en/stable/running.html#text-ui-options) |
| 30 | + |
| 31 | +### output |
| 32 | + |
| 33 | +The output filename. If not specified, it will use the default name 'results.[EXTENSION]' |
| 34 | + |
| 35 | +### target |
| 36 | + |
| 37 | +It can be a file or a directory, it is usually the ./target folder where you compiled your project. |
| 38 | + |
| 39 | +### dependenciesPath |
| 40 | + |
| 41 | +Path to the dependencies folder. For example, for Maven it is usually stored |
| 42 | +in the `~/.m2` folder. |
| 43 | + |
| 44 | +### basePath |
| 45 | + |
| 46 | +The basePath is used as a prefix in the sarif file to help GitHub find the |
| 47 | +right file of the issue. It is tipically something like 'src/main/java'. |
| 48 | + |
| 49 | +## Example usage |
| 50 | + |
| 51 | +This workflow would analyze a Java application that builds a set of |
| 52 | +packages under the com.example package name and outputs the results in |
| 53 | +sarif format to upload it to the GitHub Security tab: |
| 54 | + |
5 | 55 | ```yaml |
6 | 56 | name: SpotBugs |
7 | 57 |
|
8 | 58 | on: [push, pull_request] |
9 | 59 |
|
10 | 60 | jobs: |
11 | | - spotbugs-analyze: |
| 61 | + spotbugs-analyze: |
12 | 62 | name: Analyze |
13 | 63 | runs-on: ubuntu-latest |
14 | | - steps: |
| 64 | + steps: |
| 65 | + |
| 66 | + # checkout and build the project |
15 | 67 | - name: Checkout code |
16 | | - uses: actions/checkout@v2 |
| 68 | + uses: actions/checkout@v3 |
| 69 | + |
| 70 | + - name: Set up JDK 11 |
| 71 | + uses: actions/setup-java@v3 |
| 72 | + with: |
| 73 | + java-version: '11' |
| 74 | + distribution: 'temurin' |
| 75 | + cache: maven |
| 76 | + - name: Build with Maven |
| 77 | + run: mvn clean package -B -Dmaven.test.skip |
17 | 78 |
|
18 | | - - name: Run SpotBugs |
19 | | - uses: spotbugs/spotbugs-github-action@v1 |
| 79 | + # Run SpotBugs and upload the SARIF file |
| 80 | + - name: Run SpotBugs action |
| 81 | + if: always() |
| 82 | + uses: abirismyname/spotbugs-github-action@v2 |
20 | 83 | with: |
21 | | - arguments: '-sarif' |
22 | | - target: './HelloWorld.jar' |
23 | | - output: 'results.sarif' |
24 | | - spotbugs-version: 'latest' |
| 84 | + packages: com.example.- |
| 85 | + target: ./target |
| 86 | + dependenciesPath: ~/.m2 |
| 87 | + basePath: src/main/java |
25 | 88 |
|
26 | 89 | - name: Upload analysis results to GitHub Security tab |
27 | | - uses: github/codeql-action/upload-sarif@v1 |
| 90 | + uses: github/codeql-action/upload-sarif@v2 |
28 | 91 | with: |
29 | 92 | sarif_file: ${{github.workspace}}/results.sarif |
30 | 93 | ``` |
0 commit comments