Skip to content

Commit

Permalink
Resolves #3
Browse files Browse the repository at this point in the history
  • Loading branch information
Clint-Chester authored Aug 14, 2021
1 parent 8b9a97b commit cd6fc3b
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
14 changes: 10 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,18 @@ Features of this action include:
- Set the severity level you want rules reported at. Levels include error, warning and note (default level is warning).
- Run PMD Analyser on the files changed. File comparison can be done either based on a git diff or based on the files changed specified on the GitHub pull request.

Note that when you are running this action and making use of the SARIF uploader in the example below, if you are looking to get pull request comments then you will need to run the analyser on push events for the target branch that pull requests are targetting.

## Example GitHub Action Workflow File
```
name: PMD Static Code Analysis
on:
pull_request:
branches:
- main
push:
branches:
- main
jobs:
pmd-analyser-check:
Expand All @@ -32,7 +38,7 @@ jobs:
id: pmd-analysis
uses: synergy-au/pmd-analyser-action@v2
with:
pmd-version: '6.34.0'
pmd-version: 'latest'
file-path: './src'
rules-path: './pmd-ruleset.xml'
error-rules: 'AvoidDirectAccessTriggerMap,AvoidDmlStatementsInLoops,AvoidHardcodingId'
Expand Down Expand Up @@ -90,10 +96,10 @@ If you wish to define rules that log as a note, enter each rule name separated w

### pmd-version

The version of PMD you would like to run.
The version of PMD you would like to run. You can either specify latest to always get the newest version, or you can specify a version number like 6.37.0.

- required: true
- default: '6.33.0'
- required: false
- default: 'latest'

### rules-path

Expand Down
4 changes: 2 additions & 2 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ inputs:
description: 'If you wish to define rules that log as a note, enter each rule name separated with a comma and no spaces. Note that if a note is identified the run will not fail. e.g. ClassNamingConventions,GuardLogStatement'
required: false
pmd-version:
description: 'The version of PMD you would like to run.'
description: 'The version of PMD you would like to run. You can either specify latest to always get the newest version, or you can specify a version number like 6.37.0'
required: false
default: '6.34.0'
default: 'latest'
rules-path:
description: 'The ruleset file you want to use. PMD uses xml configuration files, called rulesets, which specify which rules to execute on your sources. You can also run a single rule by referencing it using its category and name (more details here). For example, you can check for unnecessary modifiers on Java sources with -R category/java/codestyle.xml/UnnecessaryModifier.'
required: true
Expand Down
6 changes: 6 additions & 0 deletions pmd-analyser.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# shellcheck shell=sh

# Check whether to use latest version of PMD
if [ "$PMD_VERSION" == 'latest' ]; then
LATEST_TAG="$(curl -H "Accept: application/vnd.github.v3+json" https://api.github.com/repos/pmd/pmd/releases/latest | jq --raw-output '.tag_name')"
PMD_VERSION="${LATEST_TAG#"pmd_releases/"}"
fi

# Download PMD
wget https://github.com/pmd/pmd/releases/download/pmd_releases%2F"${PMD_VERSION}"/pmd-bin-"${PMD_VERSION}".zip
unzip pmd-bin-"${PMD_VERSION}".zip
Expand Down

0 comments on commit cd6fc3b

Please sign in to comment.