generated from hmcts/service-hmcts-crime-springboot-template
-
Notifications
You must be signed in to change notification settings - Fork 1
59 lines (51 loc) · 1.61 KB
/
code-analysis.yml
File metadata and controls
59 lines (51 loc) · 1.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
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
name: Code analysis
on:
pull_request:
branches:
- master
- main
jobs:
pmd-analysis:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install PMD CLI
run: |
curl -L -o pmd-dist-7.13.0-bin.zip https://github.com/pmd/pmd/releases/download/pmd_releases%2F7.13.0/pmd-dist-7.13.0-bin.zip
unzip pmd-dist-7.13.0-bin.zip
mv pmd-bin-7.13.0 /opt/pmd
echo "/opt/pmd/bin" >> $GITHUB_PATH
- name: Run PMD CLI analysis
run: |
mkdir -p build/reports/pmd
set +e
/opt/pmd/bin/pmd check \
--dir src/main/java \
--rulesets \
.github/pmd-ruleset.xml \
--format html \
-r build/reports/pmd/pmd-report.html
PMD_EXIT_CODE=$?
set -e
if [[ "$PMD_EXIT_CODE" -eq 1 ]]; then
echo "Unexpected internal error during PMD execution"
exit 1
elif [[ "$PMD_EXIT_CODE" -eq 2 ]]; then
echo "PMD CLI usage error"
exit 1
fi
echo "PMD_EXIT_CODE=$PMD_EXIT_CODE" >> $GITHUB_ENV
- name: Upload static analysis report on failure
if: env.PMD_EXIT_CODE != '0'
uses: actions/upload-artifact@v4
with:
name: pmd-report
path: build/reports/pmd/pmd-report.html
- name: Check for static code analysis violations
run: |
if [[ "$PMD_EXIT_CODE" -eq 0 ]]; then
echo "No PMD violations"
else
echo "PMD violations found"
exit 1
fi