Skip to content

Commit 9aea7cb

Browse files
committed
ICU-23270 Enable error-prone checking in CI
1 parent 09dd52d commit 9aea7cb

File tree

3 files changed

+79
-9
lines changed

3 files changed

+79
-9
lines changed

.github/workflows/icu4j.yml

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ concurrency:
3232
cancel-in-progress: ${{ !contains(github.ref, 'maint/') && github.ref != 'main' }}
3333

3434
env:
35-
SHARED_MVN_ARGS: '--show-version --no-transfer-progress'
35+
SHARED_MVN_ARGS: '--show-version'
3636

3737
permissions:
3838
contents: read
@@ -95,6 +95,61 @@ jobs:
9595
cd icu4j;
9696
mvn spotless:check || (echo "Style checker failed. Formatting changes can be applied by 'mvn spotless:apply'" && exit 1)
9797
98+
# Runs an error-prone test that fails the build if any issues are found.
99+
formatter:
100+
name: Error-prone check
101+
needs: icu4j-mvn-init-cache
102+
runs-on: ubuntu-latest
103+
steps:
104+
- name: Checkout and setup
105+
uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
106+
with:
107+
fetch-depth: 0
108+
- name: Restore read-only cache of local Maven repository
109+
uses: actions/cache/restore@9255dc7a253b0ccc959486e2bca901246202afeb # v5.0.1
110+
id: cache
111+
with:
112+
path: ~/.m2/repository
113+
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
114+
restore-keys: |
115+
${{ runner.os }}-maven-
116+
lookup-only: true
117+
- uses: actions/setup-java@dded0888837ed1f317902acf8a20df0ad188d165 # v5.0.0
118+
with:
119+
distribution: 'temurin'
120+
java-version: '21'
121+
- name: Run error-prone
122+
run: |
123+
mvn -version
124+
# ICU_STATUS will be used to indicate whether the errorprone process succeeds or fails.
125+
# Failure means errors need to be fixed.
126+
echo "ICU_STATUS=1" >> "$GITHUB_ENV"
127+
mvn ${SHARED_MVN_ARGS} clean test -DskipTests -DskipITs -P errorprone -l /tmp/errorprone.log
128+
# We only get here if Maven does not fail
129+
echo "ICU_STATUS=0" >> "$GITHUB_ENV"
130+
continue-on-error: true
131+
- name: Generate errorprone report and output it to summary
132+
run: |
133+
if [ $ICU_STATUS -ne 0 ]; then
134+
grep '^\[ERROR\] ' /tmp/errorprone.log
135+
# We need to build this sub-project. If maven fails in a previous sub-project the
136+
# whole build stops and we never get to build the report tool, so we can't run it.
137+
mvn install -f icu4j/tools/build/ -q
138+
mvn exec:java -f icu4j/tools/build/ -P errorprone_report -DlogFile=/tmp/errorprone.log
139+
# Output messages and the error-prone report as workflow job summary
140+
echo '**Run this command locally and fix all errors:**' >> $GITHUB_STEP_SUMMARY
141+
echo '```' >> $GITHUB_STEP_SUMMARY
142+
echo '`mvn clean test -DskipTests -DskipITs -P errorprone`' >> $GITHUB_STEP_SUMMARY
143+
echo '```' >> $GITHUB_STEP_SUMMARY
144+
echo '**Error-prone errors:**' >> $GITHUB_STEP_SUMMARY
145+
grep -v -E ' WARNING | ICU_PRI' ./icu4j/target/errorprone.md >> $GITHUB_STEP_SUMMARY
146+
# User friendly messages to standard output
147+
echo 'View the Summary page of this Workflow instance to view the rendered Markdown of this report.'
148+
echo 'Run this command locally and fix all errors:'
149+
echo ' mvn clean test -DskipTests -DskipITs -P errorprone'
150+
exit 1
151+
fi
152+
98153
# ICU4J build and unit test using Maven
99154
# https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-java-with-maven
100155
icu4j-mvn-build-and-test:

icu4j/tools/build/src/main/java/com/ibm/icu/dev/tool/errorprone/ParseMavenOutForErrorProne.java

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,14 @@
1717

1818
class ParseMavenOutForErrorProne {
1919
// The `(?:[A-F]:)?` in the beginning is for the Windows drive letter (for example D:)
20-
private static final String RE_ERROR_PRONE_START =
20+
private static final String RE_ERROR_PRONE_START_WARN =
2121
"^\\[WARNING\\] ((?:[A-F]:)?[\\\\/a-zA-Z0-9_.\\-]+\\.java):\\[([0-9,]+)\\]"
2222
+ " \\[(\\S+)\\] (.+)";
23-
private static final Pattern PATTERN = Pattern.compile(RE_ERROR_PRONE_START);
23+
private static final String RE_ERROR_PRONE_START_ERR =
24+
"^\\[ERROR\\] ((?:[A-F]:)?[\\\\/a-zA-Z0-9_.\\-]+\\.java):\\[([0-9,]+)\\]"
25+
+ " error: \\[(\\S+)\\] (.+)";
26+
private static final Pattern PATTERN_WARN = Pattern.compile(RE_ERROR_PRONE_START_WARN);
27+
private static final Pattern PATTERN_ERR = Pattern.compile(RE_ERROR_PRONE_START_ERR);
2428

2529
// These are ICU custom tags, but errorprone does not allow us to exclude them.
2630
// So we will filter them out in our code.
@@ -63,8 +67,11 @@ static Map<String, List<ErrorProneEntry>> parse(String baseDir, String fileName)
6367
int currentLine = 0;
6468
for (String line : Files.readAllLines(Paths.get(fileName), StandardCharsets.UTF_8)) {
6569
currentLine++;
66-
Matcher m = PATTERN.matcher(line);
67-
if (m.find()) {
70+
Matcher m = PATTERN_WARN.matcher(line);
71+
if (!m.find()) {
72+
m = PATTERN_ERR.matcher(line);
73+
}
74+
if (m.find(0)) {
6875
String path = line.substring(m.start(1), m.end(1)).replace('\\', '/');
6976
if (baseDir != null) {
7077
if (path.startsWith(baseDir)) {
@@ -109,6 +116,14 @@ static Map<String, List<ErrorProneEntry>> parse(String baseDir, String fileName)
109116
"[WARNING] Unable to autodetect 'javac' path, using 'javac' from the"
110117
+ " environment.")) {
111118
currentError = addErrorToReportAndReset(errorReport, currentError);
119+
} else if (line.startsWith("[INFO] BUILD FAILURE")) {
120+
// Stop parsing, after this there will be a duplication of the issues
121+
// already reported, and possibly all kind of non-error-prone errors.
122+
break;
123+
} else if (line.startsWith("[WARNING] COMPILATION WARNING")) {
124+
// Known, but not actionable
125+
} else if (line.startsWith("[ERROR] COMPILATION ERROR")) {
126+
// Known, but not actionable
112127
} else if (line.startsWith("[INFO]")) {
113128
currentError = addErrorToReportAndReset(errorReport, currentError);
114129
} else {

pom.xml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -633,7 +633,7 @@
633633

634634
<profile>
635635
<!-- Run this in the root of the ICU project:
636-
mvn clean package -ntp -DskipTests -DskipITs -P errorprone
636+
mvn clean test -DskipTests -DskipITs -P errorprone
637637
-->
638638
<id>errorprone</id>
639639
<build>
@@ -684,9 +684,9 @@
684684

685685
<profile>
686686
<!-- Run this in the root of the ICU project:
687-
mvn clean test -ntp -DskipTests -DskipITs -l /tmp/errorprone.log -P errorprone-all
688-
mvn exec:java -f icu4j/tools/build/ -P errorprone_report -DlogFile=/tmp/errorprone.log
689-
On Windows you can use %TEMP%\errorprone.log for the temporary folder.
687+
mvn clean test -DskipTests -DskipITs -l /tmp/errorprone_all.log -P errorprone-all
688+
mvn exec:java -f icu4j/tools/build/ -P errorprone_report -DlogFile=/tmp/errorprone_all.log
689+
On Windows you can use %TEMP%\errorprone_all.log for the temporary folder.
690690
You can then inspect the content of the errorprone.log file, or the reports in
691691
the target folder (errorprone*.html, errorprone.md, errorprone.tsv) -->
692692
<id>errorprone-all</id>

0 commit comments

Comments
 (0)