forked from logisim-evolution/logisim-evolution
-
Notifications
You must be signed in to change notification settings - Fork 0
108 lines (91 loc) · 3.74 KB
/
checkstyle.yml
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# This workflow will check code style of the project files (mostly Java).
#
# By design, it is expected to only analyse files affected by given
# pull request, and not the whole source tree.
#
# Marcin Orlowski
name: "Code style"
on:
push:
# main is left just for emergency cases.
branches: [ main ]
pull_request:
branches: [ main ]
jobs:
analyze_sources:
name: "Is there any Java source code to lint?"
runs-on: ubuntu-latest
outputs:
# Export 'filter' step check result so next step can use it.
run_checkstyle: ${{ steps.filter.outputs.src }}
# These are source files matching our filter that are affected by the PR.
changed_files: ${{ steps.filter.outputs.src_files }}
steps:
- name: "Install packages..."
run: sudo apt-get install -y sysvbanner
# https://github.com/marketplace/actions/checkout
- name: "Checkout sources"
uses: actions/checkout@v3
# https://github.com/marketplace/actions/paths-changes-filter
- name: "Look for changes that matters for us..."
uses: dorny/paths-filter@v2
id: filter
with:
list-files: 'escape'
filters: |
src:
- 'src/**/*.java'
- name: "WILL JAVA LINT STEP BE RUN?"
run: |
found="NO"
[[ ${{ steps.filter.outputs.src }} == 'true' ]] && found="YES"
echo "run_checkstyle=${found}" >> $GITHUB_OUTPUT
echo -e "\n****************************************\n"
banner "${found}"
echo -e "****************************************"
# Build step.
checkstyle:
name: "Code style linter"
runs-on: ubuntu-latest
# Will run only if analyze_sources determined it is needed.
needs: analyze_sources
if: needs.analyze_sources.outputs.run_checkstyle == 'true'
# TODO: we may want to use checkstyle.jar directly, skipping cli wrapper
# that would let us use most recent version, but would also require downloading
# such instead of installing packaged version via apt.
steps:
- name: "Checkout sources"
uses: actions/checkout@v3
- name: "Lint changed files"
run: |
# Run CheckStyle
# https://github.com/checkstyle/checkstyle/releases/
CHECKSTYLE_VERSION="10.3.4"
JAR="checkstyle-${CHECKSTYLE_VERSION}-all.jar"
URL="https://github.com/checkstyle/checkstyle/releases/download/checkstyle-${CHECKSTYLE_VERSION}/${JAR}"
echo "Downloading ${JAR}..."
wget --quiet "${URL}"
# Using built-in config.
declare -r CHECKS_FILE="/google_checks.xml"
declare -r REPORT_FILE="output.txt"
# Let's lint eventually...
echo "*********************************************************"
java -version
echo "Linting using $(java -jar "${JAR}" --version)"
java -jar "${JAR}" -o "${REPORT_FILE}" -c "${CHECKS_FILE}" ${{ needs.analyze_sources.outputs.changed_files }}
# Plain output always contains "Starting audit..." and "Audit done." lines. Let's remove them.
sed -i 's/^Starting audit...$//; s/^Audit done.$//' "${REPORT_FILE}"
# The `strings` tool is used to filter out empty lines.
cnt="$(strings "${REPORT_FILE}" | wc -l)"
if [[ "${cnt}" -gt 0 ]]; then
echo "*********************************************************"
echo "* FIXME! Code style guide violations detected: ${cnt}"
echo "*"
echo "* For more information about used code style guide see:"
echo "* https://github.com/logisim-evolution/logisim-evolution/blob/main/docs/style.md"
echo "*********************************************************"
cat "${REPORT_FILE}"
exit 1
else
echo "Looks good. No style guide violations found."
fi