Skip to content

Commit 87124df

Browse files
committed
Update readme and simplify jq usage
1 parent 850705f commit 87124df

2 files changed

Lines changed: 74 additions & 12 deletions

File tree

README.md

Lines changed: 73 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,29 +2,92 @@
22

33
Run [SpotBugs](https://spotbugs.readthedocs.io/en/latest/) as a Github action.
44

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+
555
```yaml
656
name: SpotBugs
757

858
on: [push, pull_request]
959

1060
jobs:
11-
spotbugs-analyze:
61+
spotbugs-analyze:
1262
name: Analyze
1363
runs-on: ubuntu-latest
14-
steps:
64+
steps:
65+
66+
# checkout and build the project
1567
- 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
1778

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
2083
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
2588

2689
- name: Upload analysis results to GitHub Security tab
27-
uses: github/codeql-action/upload-sarif@v1
90+
uses: github/codeql-action/upload-sarif@v2
2891
with:
2992
sarif_file: ${{github.workspace}}/results.sarif
3093
```

analyze.sh

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,6 @@ eval ${CMD}
101101
if [ "$OUTPUT_TYPE" == "sarif" ] && [ "$BASE_PATH" != "" ]; then
102102
# prepend the pyhsical path
103103
echo "Transform sarif file to include the physical path"
104-
cat resultspre.sarif | jq -c "(.runs[].results[].locations[].physicalLocation.artifactLocation.uri) |=\"$BASE_PATH\"+." > resultspre2.sarif
105-
cat resultspre2.sarif | jq -c '(.runs[].invocations[].executionSuccessful)=true' > results.sarif
104+
jq -c "(.runs[].results[].locations[].physicalLocation.artifactLocation.uri) |=\"$BASE_PATH\"+." resultspre.sarif > "$OUTPUT"
106105
fi
107106

0 commit comments

Comments
 (0)