Skip to content

Commit 4784d0c

Browse files
Merge pull request #38 from hmcts/use=pmd-action
use the pmd action
2 parents dc9bda7 + 1a00ea6 commit 4784d0c

File tree

1 file changed

+12
-44
lines changed

1 file changed

+12
-44
lines changed

.github/workflows/code-analysis.yml

Lines changed: 12 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -11,51 +11,19 @@ jobs:
1111
runs-on: ubuntu-latest
1212
steps:
1313
- uses: actions/checkout@v4
14+
with:
15+
fetch-depth: 0
1416

15-
- name: Install PMD CLI
16-
env:
17-
PMD_VERSION: '7.14.0'
18-
run: |
19-
curl -L -o pmd-dist-$PMD_VERSION-bin.zip https://github.com/pmd/pmd/releases/download/pmd_releases%2F$PMD_VERSION/pmd-dist-$PMD_VERSION-bin.zip
20-
unzip pmd-dist-$PMD_VERSION-bin.zip
21-
mv pmd-bin-$PMD_VERSION /opt/pmd
22-
echo "/opt/pmd/bin" >> $GITHUB_PATH
23-
24-
- name: Run PMD CLI analysis
25-
run: |
26-
mkdir -p build/reports/pmd
27-
28-
set +e
29-
/opt/pmd/bin/pmd check \
30-
--dir src/main/java \
31-
--rulesets \
32-
.github/pmd-ruleset.xml \
33-
--format html \
34-
-r build/reports/pmd/pmd-report.html
35-
PMD_EXIT_CODE=$?
36-
set -e
37-
38-
if [[ "$PMD_EXIT_CODE" -eq 1 ]]; then
39-
echo "Unexpected internal error during PMD execution"
40-
exit 1
41-
elif [[ "$PMD_EXIT_CODE" -eq 2 ]]; then
42-
echo "PMD CLI usage error"
43-
exit 1
44-
fi
45-
echo "PMD_EXIT_CODE=$PMD_EXIT_CODE" >> $GITHUB_ENV
17+
- uses: actions/setup-java@v4
18+
with:
19+
distribution: 'temurin'
20+
java-version: '21'
4621

47-
- name: Upload static analysis report on failure
48-
if: env.PMD_EXIT_CODE != '0'
49-
uses: actions/upload-artifact@v4
22+
- uses: pmd/pmd-github-action@v2
5023
with:
51-
name: pmd-report
52-
path: build/reports/pmd/pmd-report.html
24+
rulesets: '.github/pmd-ruleset.xml'
25+
sourcePath: 'src/main/java'
5326

54-
- name: Check for static code analysis violations
55-
run: |
56-
if [[ "$PMD_EXIT_CODE" -eq 0 ]]; then
57-
echo "No PMD violations"
58-
else
59-
echo "PMD violations found"
60-
exit 1
61-
fi
27+
- name: Fail build if there are violations
28+
if: steps.pmd.outputs.violations != 0
29+
run: exit 1

0 commit comments

Comments
 (0)