Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 57 additions & 2 deletions .github/workflows/icu4j.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ concurrency:
cancel-in-progress: ${{ !contains(github.ref, 'maint/') && github.ref != 'main' }}

env:
SHARED_MVN_ARGS: '--show-version --no-transfer-progress'
SHARED_MVN_ARGS: '--show-version'

permissions:
contents: read
Expand Down Expand Up @@ -69,7 +69,7 @@ jobs:
# Spotless is configured to run only on files in this branch (PR) that differ
# from origin/main
formatter:
name: Formatter + Style checker
name: Format checker
needs: icu4j-mvn-init-cache
runs-on: ubuntu-latest
steps:
Expand All @@ -95,6 +95,61 @@ jobs:
cd icu4j;
mvn spotless:check || (echo "Style checker failed. Formatting changes can be applied by 'mvn spotless:apply'" && exit 1)

# Runs an error-prone test that fails the build if any issues are found.
linter:
name: Linter
needs: icu4j-mvn-init-cache
runs-on: ubuntu-latest
steps:
- name: Checkout and setup
uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
with:
fetch-depth: 0
- name: Restore read-only cache of local Maven repository
uses: actions/cache/restore@9255dc7a253b0ccc959486e2bca901246202afeb # v5.0.1
id: cache
with:
path: ~/.m2/repository
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
restore-keys: |
${{ runner.os }}-maven-
lookup-only: true
- uses: actions/setup-java@dded0888837ed1f317902acf8a20df0ad188d165 # v5.0.0
with:
distribution: 'temurin'
java-version: '21'
- name: Run error-prone
run: |
mvn -version
# ICU_STATUS will be used to indicate whether the errorprone process succeeds or fails.
# Failure means errors need to be fixed.
echo "ICU_STATUS=1" >> "$GITHUB_ENV"
mvn ${SHARED_MVN_ARGS} clean test -DskipTests -DskipITs -P errorprone -l /tmp/errorprone.log
# We only get here if Maven does not fail
echo "ICU_STATUS=0" >> "$GITHUB_ENV"
continue-on-error: true
- name: Generate errorprone report and output it to summary
run: |
if [ $ICU_STATUS -ne 0 ]; then
grep '^\[ERROR\] ' /tmp/errorprone.log
# We need to build this sub-project. If maven fails in a previous sub-project the
# whole build stops and we never get to build the report tool, so we can't run it.
mvn install -f icu4j/tools/build/ -q
mvn exec:java -f icu4j/tools/build/ -P errorprone_report -DlogFile=/tmp/errorprone.log
# Output messages and the error-prone report as workflow job summary
echo '**Run this command locally and fix all errors:**' >> $GITHUB_STEP_SUMMARY
echo '```' >> $GITHUB_STEP_SUMMARY
echo '`mvn clean test -DskipTests -DskipITs -P errorprone`' >> $GITHUB_STEP_SUMMARY
echo '```' >> $GITHUB_STEP_SUMMARY
echo '**Error-prone errors:**' >> $GITHUB_STEP_SUMMARY
grep -v -E ' WARNING | ICU_PRI' ./icu4j/target/errorprone.md >> $GITHUB_STEP_SUMMARY
# User friendly messages to standard output
echo 'View the Summary page of this Workflow instance to view the rendered Markdown of this report.'
echo 'Run this command locally and fix all errors:'
echo ' mvn clean test -DskipTests -DskipITs -P errorprone'
exit 1
fi

# ICU4J build and unit test using Maven
# https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-java-with-maven
icu4j-mvn-build-and-test:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,14 @@

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

// These are ICU custom tags, but errorprone does not allow us to exclude them.
// So we will filter them out in our code.
Expand Down Expand Up @@ -63,8 +67,11 @@ static Map<String, List<ErrorProneEntry>> parse(String baseDir, String fileName)
int currentLine = 0;
for (String line : Files.readAllLines(Paths.get(fileName), StandardCharsets.UTF_8)) {
currentLine++;
Matcher m = PATTERN.matcher(line);
if (m.find()) {
Matcher m = PATTERN_WARN.matcher(line);
if (!m.find()) {
m = PATTERN_ERR.matcher(line);
}
if (m.find(0)) {
String path = line.substring(m.start(1), m.end(1)).replace('\\', '/');
if (baseDir != null) {
if (path.startsWith(baseDir)) {
Expand Down Expand Up @@ -109,6 +116,14 @@ static Map<String, List<ErrorProneEntry>> parse(String baseDir, String fileName)
"[WARNING] Unable to autodetect 'javac' path, using 'javac' from the"
+ " environment.")) {
currentError = addErrorToReportAndReset(errorReport, currentError);
} else if (line.startsWith("[INFO] BUILD FAILURE")) {
// Stop parsing, after this there will be a duplication of the issues
// already reported, and possibly all kind of non-error-prone errors.
break;
} else if (line.startsWith("[WARNING] COMPILATION WARNING")) {
// Known, but not actionable
} else if (line.startsWith("[ERROR] COMPILATION ERROR")) {
// Known, but not actionable
} else if (line.startsWith("[INFO]")) {
currentError = addErrorToReportAndReset(errorReport, currentError);
} else {
Expand Down
8 changes: 4 additions & 4 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -633,7 +633,7 @@

<profile>
<!-- Run this in the root of the ICU project:
mvn clean package -ntp -DskipTests -DskipITs -P errorprone
mvn clean test -DskipTests -DskipITs -P errorprone
-->
<id>errorprone</id>
<build>
Expand Down Expand Up @@ -684,9 +684,9 @@

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