From 5278700845011fb3804cf0b127e38b3bd655bc30 Mon Sep 17 00:00:00 2001 From: Ulli Hafner Date: Tue, 27 Feb 2024 20:56:34 +0100 Subject: [PATCH 1/8] Replace old GitHub action with updated one. --- .github/workflows/ci.yml | 37 +++++++++++++++++++++++++++++++ .github/workflows/maven.yml | 43 ------------------------------------- 2 files changed, 37 insertions(+), 43 deletions(-) create mode 100644 .github/workflows/ci.yml delete mode 100644 .github/workflows/maven.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 00000000..34d12011 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,37 @@ +name: 'GitHub CI' + +on: + push: + branches: + - master + - main + pull_request: + +jobs: + build: + + strategy: + matrix: + platform: [ubuntu-latest, macos-latest, windows-latest] + jdk: [17, 21] + + runs-on: ${{ matrix.platform }} + name: on ${{ matrix.platform }} with JDK ${{ matrix.jdk }} + + steps: + - uses: actions/checkout@v4 + - name: Set up JDK ${{ matrix.jdk }} + uses: actions/setup-java@v4 + with: + distribution: 'temurin' + java-version: '${{ matrix.jdk }}' + check-latest: true + cache: 'maven' + - name: Set up Maven + uses: stCarolas/setup-maven@v5 + with: + maven-version: 3.9.6 + - name: Build with Maven + env: + BROWSER: chrome-container + run: mvn -V --color always -ntp clean verify --file pom.xml '-Djenkins.test.timeout=5000' '-Dgpg.skip' diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml deleted file mode 100644 index 376abbf7..00000000 --- a/.github/workflows/maven.yml +++ /dev/null @@ -1,43 +0,0 @@ -name: CI - -on: - push: - branches: - - master - pull_request: - -jobs: - build: - - strategy: - matrix: - java: [11] - os: [ubuntu-latest, windows-latest] - - runs-on: ${{ matrix.os }} - name: on ${{ matrix.os }} - - steps: - - uses: actions/checkout@v4 - - - name: Set up JDK ${{ matrix.java }} - uses: actions/setup-java@v3 - with: - distribution: 'temurin' - java-version: ${{ matrix.java }} - - - name: Cache dependencies - uses: actions/cache@v4.0.0 - with: - path: ~/.m2/repository - key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} - restore-keys: | - ${{ runner.os }}-maven - - - name: Build with Maven - run: mvn -Penable-jacoco clean verify -B -V -ntp - - - name: Upload coverage to Codecov - uses: codecov/codecov-action@v3 - with: - file: '*jacoco.xml' From 1dd8c78833c763d6fe9b835fd3b2f487cc139625 Mon Sep 17 00:00:00 2001 From: Ulli Hafner Date: Wed, 28 Feb 2024 09:14:31 +0100 Subject: [PATCH 2/8] Check for any whitespace at the line end. --- .../BuildStatusChecksPublisherITest.java | 35 +++++++++---------- 1 file changed, 17 insertions(+), 18 deletions(-) diff --git a/src/test/java/io/jenkins/plugins/checks/status/BuildStatusChecksPublisherITest.java b/src/test/java/io/jenkins/plugins/checks/status/BuildStatusChecksPublisherITest.java index a37397e3..16f67604 100644 --- a/src/test/java/io/jenkins/plugins/checks/status/BuildStatusChecksPublisherITest.java +++ b/src/test/java/io/jenkins/plugins/checks/status/BuildStatusChecksPublisherITest.java @@ -32,7 +32,6 @@ @SuppressWarnings({"PMD.AddEmptyString", "checkstyle:LambdaBodyLength"}) @SuppressFBWarnings("NP_NONNULL_FIELD_NOT_INITIALIZED_IN_CONSTRUCTOR") class BuildStatusChecksPublisherITest extends IntegrationTestWithJenkinsPerTest { - private CapturingChecksPublisher.Factory getFactory() { return getJenkins().getInstance().getExtensionList(ChecksPublisherFactory.class) .stream() @@ -100,19 +99,19 @@ public void shouldPublishStatusWithProperties() { ChecksDetails details = getFactory().getPublishedChecks().get(0); - assertThat(details.getName()).isPresent().get().isEqualTo("Test Status"); + assertThat(details.getName()).contains("Test Status"); assertThat(details.getStatus()).isEqualTo(ChecksStatus.QUEUED); assertThat(details.getConclusion()).isEqualTo(ChecksConclusion.NONE); details = getFactory().getPublishedChecks().get(1); - assertThat(details.getName()).isPresent().get().isEqualTo("Test Status"); + assertThat(details.getName()).contains("Test Status"); assertThat(details.getStatus()).isEqualTo(ChecksStatus.IN_PROGRESS); assertThat(details.getConclusion()).isEqualTo(ChecksConclusion.NONE); details = getFactory().getPublishedChecks().get(2); - assertThat(details.getName()).isPresent().get().isEqualTo("Test Status"); + assertThat(details.getName()).contains("Test Status"); assertThat(details.getStatus()).isEqualTo(ChecksStatus.COMPLETED); assertThat(details.getConclusion()).isEqualTo(ChecksConclusion.SUCCESS); } @@ -156,7 +155,7 @@ public void shouldPublishStageDetails() { ChecksDetails details = checksDetails.get(0); assertThat(details.getStatus()).isEqualTo(ChecksStatus.QUEUED); assertThat(details.getConclusion()).isEqualTo(ChecksConclusion.NONE); - assertThat(details.getName()).isPresent().get().isEqualTo("Test Status"); + assertThat(details.getName()).contains("Test Status"); assertThat(details.getOutput()).isNotPresent(); // Details 1, first stage @@ -164,7 +163,7 @@ public void shouldPublishStageDetails() { assertThat(details.getStatus()).isEqualTo(ChecksStatus.IN_PROGRESS); assertThat(details.getConclusion()).isEqualTo(ChecksConclusion.NONE); assertThat(details.getOutput()).isPresent().get().satisfies(output -> { - assertThat(output.getTitle()).isPresent().get().isEqualTo("In progress"); + assertThat(output.getTitle()).contains("In progress"); assertThat(output.getSummary()).isPresent().get().satisfies(StringUtils::isBlank); assertThat(output.getText()).isPresent().get().asString().contains("* Simple Stage *(running)*"); }); @@ -174,7 +173,7 @@ public void shouldPublishStageDetails() { assertThat(details.getOutput()).isPresent().get().satisfies(output -> { assertThat(output.getSummary()).isPresent().get().satisfies(StringUtils::isBlank); assertThat(output.getText()).isPresent().get().satisfies(text -> { - assertThat(output.getTitle()).isPresent().get().isEqualTo("In progress"); + assertThat(output.getTitle()).contains("In progress"); assertThat(text).matches(Pattern.compile(".*\\* Simple Stage \\*\\([^)]+\\)\\*.*", Pattern.DOTALL)); assertThat(text).contains(" * In parallel *(running)*"); }); @@ -183,7 +182,7 @@ public void shouldPublishStageDetails() { // Details 6, p1s1 has finished and emitted unstable details = checksDetails.get(6); assertThat(details.getOutput()).isPresent().get().satisfies(output -> { - assertThat(output.getTitle()).isPresent().get().isEqualTo("In parallel/p1/p1s1: warning in 'unstable' step"); + assertThat(output.getTitle()).contains("In parallel/p1/p1s1: warning in 'unstable' step"); assertThat(output.getSummary()).isPresent().get().asString().isEqualToIgnoringNewLines("" + "### `In parallel / p1 / p1s1 / Set stage result to unstable`\n" + "Warning in `unstable` step, with arguments `something went wrong`.\n" @@ -192,13 +191,13 @@ public void shouldPublishStageDetails() { + "```\n" + "\n"); assertThat(output.getText()).isPresent().get().asString().matches(Pattern.compile(".*" - + " \\* Simple Stage \\*\\([^)]+\\)\\*\n" - + " \\* In parallel \\*\\(running\\)\\*\n" - + " \\* p1 \\*\\(running\\)\\*\n" - + " \\* p1s1 \\*\\([^)]+\\)\\*\n" - + " \\*\\*Unstable\\*\\*: \\*something went wrong\\*\n" - + " \\* p1s2 \\*\\(running\\)\\*\n" - + " \\* p2 \\*\\([^)]+\\)\\*\n.*", Pattern.DOTALL)); + + " \\* Simple Stage \\*\\([^)]+\\)\\*\\s*" + + " \\* In parallel \\*\\(running\\)\\*\\s*" + + " \\* p1 \\*\\(running\\)\\*\\s*" + + " \\* p1s1 \\*\\([^)]+\\)\\*\\s*" + + " \\*\\*Unstable\\*\\*: \\*something went wrong\\*\\s*" + + " \\* p1s2 \\*\\(running\\)\\*\\s*" + + " \\* p2 \\*\\([^)]+\\)\\*\\s*.*", Pattern.DOTALL | Pattern.UNIX_LINES)); }); // Details 8, final checks @@ -206,7 +205,7 @@ public void shouldPublishStageDetails() { assertThat(details.getStatus()).isEqualTo(ChecksStatus.COMPLETED); assertThat(details.getConclusion()).isEqualTo(ChecksConclusion.FAILURE); assertThat(details.getOutput()).isPresent().get().satisfies(output -> { - assertThat(output.getTitle()).isPresent().get().isEqualTo("Fails: error in 'error' step"); + assertThat(output.getTitle()).contains("Fails: error in 'error' step"); assertThat(output.getSummary()).isPresent().get().asString().matches(Pattern.compile(".*" + "### `In parallel / p1 / p1s1 / Set stage result to unstable`\\s+" + "Warning in `unstable` step, with arguments `something went wrong`\\.\\s+" @@ -271,7 +270,7 @@ public void shouldPublishStageDetailsWithoutLogsIfRequested() { assertThat(details.getStatus()).isEqualTo(ChecksStatus.COMPLETED); assertThat(details.getConclusion()).isEqualTo(ChecksConclusion.FAILURE); assertThat(details.getOutput()).isPresent().get().satisfies(output -> { - assertThat(output.getTitle()).isPresent().get().isEqualTo("Fails: error in 'archiveArtifacts' step"); + assertThat(output.getTitle()).contains("Fails: error in 'archiveArtifacts' step"); assertThat(output.getSummary()).isPresent().get().asString().matches(Pattern.compile(".*" + "### `In parallel / p1 / p1s1 / Set stage result to unstable`\\s+" + "Warning in `unstable` step, with arguments `something went wrong`\\.\\s+" @@ -317,7 +316,7 @@ public void shouldPublishSimplePipeline() { List checksDetails = getFactory().getPublishedChecks(); ChecksDetails details = checksDetails.get(1); - assertThat(details.getOutput()).isPresent().get().satisfies(output -> assertThat(output.getTitle()).isPresent().get().isEqualTo("Success")); + assertThat(details.getOutput()).isPresent().get().satisfies(output -> assertThat(output.getTitle()).contains("Success")); } /** From 74e1be49aa5709d5d392bf91887e4ed234a9b4a6 Mon Sep 17 00:00:00 2001 From: Ulli Hafner Date: Wed, 28 Feb 2024 10:19:44 +0100 Subject: [PATCH 3/8] Build only on Java 17 and 21. --- Jenkinsfile | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 5e9546e3..d174f3ac 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -1,8 +1,13 @@ def configurations = [ - [ platform: "linux", jdk: "11" ], - [ platform: "windows", jdk: "11" ] + [ platform: "linux", jdk: "21" ], + [ platform: "windows", jdk: "17" ] ] -buildPlugin(failFast: false, configurations: configurations, +def params = [ + failFast: false, + configurations: configurations, checkstyle: [qualityGates: [[threshold: 1, type: 'NEW', unstable: true]]], - pmd: [qualityGates: [[threshold: 1, type: 'NEW', unstable: true]]] ) + spotbugs: [qualityGates: [[threshold: 1, type: 'NEW', unstable: true]]]] +] + +buildPlugin(params) From 491001d39b29be63ecac9fe813333ebaa1fb0949 Mon Sep 17 00:00:00 2001 From: Ulli Hafner Date: Wed, 28 Feb 2024 10:23:34 +0100 Subject: [PATCH 4/8] Build only on Java 17 and 21. --- Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index d174f3ac..99c4f40e 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -7,7 +7,7 @@ def params = [ failFast: false, configurations: configurations, checkstyle: [qualityGates: [[threshold: 1, type: 'NEW', unstable: true]]], - spotbugs: [qualityGates: [[threshold: 1, type: 'NEW', unstable: true]]]] + spotbugs: [qualityGates: [[threshold: 1, type: 'NEW', unstable: true]]] ] buildPlugin(params) From 4e0271c601023ef57e4aecd0d92d1fedd8fe0c47 Mon Sep 17 00:00:00 2001 From: Ulli Hafner Date: Wed, 28 Feb 2024 10:57:20 +0100 Subject: [PATCH 5/8] Remove UNIX_LINES. --- .../plugins/checks/status/BuildStatusChecksPublisherITest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/io/jenkins/plugins/checks/status/BuildStatusChecksPublisherITest.java b/src/test/java/io/jenkins/plugins/checks/status/BuildStatusChecksPublisherITest.java index 16f67604..ae56ab2f 100644 --- a/src/test/java/io/jenkins/plugins/checks/status/BuildStatusChecksPublisherITest.java +++ b/src/test/java/io/jenkins/plugins/checks/status/BuildStatusChecksPublisherITest.java @@ -197,7 +197,7 @@ public void shouldPublishStageDetails() { + " \\* p1s1 \\*\\([^)]+\\)\\*\\s*" + " \\*\\*Unstable\\*\\*: \\*something went wrong\\*\\s*" + " \\* p1s2 \\*\\(running\\)\\*\\s*" - + " \\* p2 \\*\\([^)]+\\)\\*\\s*.*", Pattern.DOTALL | Pattern.UNIX_LINES)); + + " \\* p2 \\*\\([^)]+\\)\\*\\s*.*", Pattern.DOTALL)); }); // Details 8, final checks From 90fa1a0d246989f6956394da8e14caafbc2f0a27 Mon Sep 17 00:00:00 2001 From: Ulli Hafner Date: Wed, 28 Feb 2024 11:08:12 +0100 Subject: [PATCH 6/8] Check for any whitespace at the line end. --- .../BuildStatusChecksPublisherITest.java | 50 +++++++++---------- 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/src/test/java/io/jenkins/plugins/checks/status/BuildStatusChecksPublisherITest.java b/src/test/java/io/jenkins/plugins/checks/status/BuildStatusChecksPublisherITest.java index ae56ab2f..5e6c56fe 100644 --- a/src/test/java/io/jenkins/plugins/checks/status/BuildStatusChecksPublisherITest.java +++ b/src/test/java/io/jenkins/plugins/checks/status/BuildStatusChecksPublisherITest.java @@ -191,13 +191,13 @@ public void shouldPublishStageDetails() { + "```\n" + "\n"); assertThat(output.getText()).isPresent().get().asString().matches(Pattern.compile(".*" - + " \\* Simple Stage \\*\\([^)]+\\)\\*\\s*" - + " \\* In parallel \\*\\(running\\)\\*\\s*" - + " \\* p1 \\*\\(running\\)\\*\\s*" - + " \\* p1s1 \\*\\([^)]+\\)\\*\\s*" - + " \\*\\*Unstable\\*\\*: \\*something went wrong\\*\\s*" - + " \\* p1s2 \\*\\(running\\)\\*\\s*" - + " \\* p2 \\*\\([^)]+\\)\\*\\s*.*", Pattern.DOTALL)); + + " \\* Simple Stage \\*\\([^)]+\\)\\*\\s+" + + " \\* In parallel \\*\\(running\\)\\*\\s+" + + " \\* p1 \\*\\(running\\)\\*\\s+" + + " \\* p1s1 \\*\\([^)]+\\)\\*\\s+" + + " \\*\\*Unstable\\*\\*: \\*something went wrong\\*\\s+" + + " \\* p1s2 \\*\\(running\\)\\*\\s+" + + " \\* p2 \\*\\([^)]+\\)\\*\\s+.*", Pattern.DOTALL)); }); // Details 8, final checks @@ -218,15 +218,15 @@ public void shouldPublishStageDetails() { + "a fatal error occurs\\s+" + "```\\s+", Pattern.DOTALL)); assertThat(output.getText()).isPresent().asString().matches(Pattern.compile(".*" - + " \\* Simple Stage \\*\\([^)]+\\)\\*\n" - + " \\* In parallel \\*\\([^)]+\\)\\*\n" - + " \\* p1 \\*\\([^)]+\\)\\*\n" - + " \\* p1s1 \\*\\([^)]+\\)\\*\n" - + " \\*\\*Unstable\\*\\*: \\*something went wrong\\*\n" - + " \\* p1s2 \\*\\([^)]+\\)\\*\n" - + " \\* p2 \\*\\([^)]+\\)\\*\n" - + " \\* Fails \\*\\([^)]+\\)\\*\n" - + " \\*\\*Error\\*\\*: \\*a fatal error occurs\\*\n.*", + + " \\* Simple Stage \\*\\([^)]+\\)\\*\\s+" + + " \\* In parallel \\*\\([^)]+\\)\\*\\s+" + + " \\* p1 \\*\\([^)]+\\)\\*\\s+" + + " \\* p1s1 \\*\\([^)]+\\)\\*\\s+" + + " \\*\\*Unstable\\*\\*: \\*something went wrong\\*\\s+" + + " \\* p1s2 \\*\\([^)]+\\)\\*\\s+" + + " \\* p2 \\*\\([^)]+\\)\\*\\s+" + + " \\* Fails \\*\\([^)]+\\)\\*\\s+" + + " \\*\\*Error\\*\\*: \\*a fatal error occurs\\*\\s+.*", Pattern.DOTALL)); }); } @@ -283,15 +283,15 @@ public void shouldPublishStageDetailsWithoutLogsIfRequested() { + "No artifacts found that match the file pattern \"oh dear\"\\. Configuration error\\?\\s+" + "```\\s+", Pattern.DOTALL)); assertThat(output.getText()).isPresent().asString().matches(Pattern.compile(".*" - + " \\* Simple Stage \\*\\([^)]+\\)\\*\n" - + " \\* In parallel \\*\\([^)]+\\)\\*\n" - + " \\* p1 \\*\\([^)]+\\)\\*\n" - + " \\* p1s1 \\*\\([^)]+\\)\\*\n" - + " \\*\\*Unstable\\*\\*: \\*something went wrong\\*\n" - + " \\* p1s2 \\*\\([^)]+\\)\\*\n" - + " \\* p2 \\*\\([^)]+\\)\\*\n" - + " \\* Fails \\*\\([^)]+\\)\\*\n" - + " \\*\\*Error\\*\\*: \\*No artifacts found that match the file pattern \"oh dear\". Configuration error\\?\\*\n.*", + + " \\* Simple Stage \\*\\([^)]+\\)\\*\\s+" + + " \\* In parallel \\*\\([^)]+\\)\\*\\s+" + + " \\* p1 \\*\\([^)]+\\)\\*\\s+" + + " \\* p1s1 \\*\\([^)]+\\)\\*\\s+" + + " \\*\\*Unstable\\*\\*: \\*something went wrong\\*\\s+" + + " \\* p1s2 \\*\\([^)]+\\)\\*\\s+" + + " \\* p2 \\*\\([^)]+\\)\\*\\s+" + + " \\* Fails \\*\\([^)]+\\)\\*\\s+" + + " \\*\\*Error\\*\\*: \\*No artifacts found that match the file pattern \"oh dear\". Configuration error\\?\\*\\s+.*", Pattern.DOTALL)); }); } From d781eb64d7ff9a6d33dbb3fe93c201a299067313 Mon Sep 17 00:00:00 2001 From: Ulli Hafner Date: Wed, 28 Feb 2024 11:38:43 +0100 Subject: [PATCH 7/8] Add missing get. --- .../plugins/checks/status/BuildStatusChecksPublisherITest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/io/jenkins/plugins/checks/status/BuildStatusChecksPublisherITest.java b/src/test/java/io/jenkins/plugins/checks/status/BuildStatusChecksPublisherITest.java index 5e6c56fe..cb78ed51 100644 --- a/src/test/java/io/jenkins/plugins/checks/status/BuildStatusChecksPublisherITest.java +++ b/src/test/java/io/jenkins/plugins/checks/status/BuildStatusChecksPublisherITest.java @@ -217,7 +217,7 @@ public void shouldPublishStageDetails() { + "```\\s+" + "a fatal error occurs\\s+" + "```\\s+", Pattern.DOTALL)); - assertThat(output.getText()).isPresent().asString().matches(Pattern.compile(".*" + assertThat(output.getText()).isPresent().get().asString().matches(Pattern.compile(".*" + " \\* Simple Stage \\*\\([^)]+\\)\\*\\s+" + " \\* In parallel \\*\\([^)]+\\)\\*\\s+" + " \\* p1 \\*\\([^)]+\\)\\*\\s+" From bc454a35fd6768896f766e1c4362597a03d59e55 Mon Sep 17 00:00:00 2001 From: Ulli Hafner Date: Thu, 29 Feb 2024 10:09:35 +0100 Subject: [PATCH 8/8] Always print the time, even if < 1ms. --- .../io/jenkins/plugins/checks/status/FlowExecutionAnalyzer.java | 2 +- .../plugins/checks/status/BuildStatusChecksPublisherITest.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/io/jenkins/plugins/checks/status/FlowExecutionAnalyzer.java b/src/main/java/io/jenkins/plugins/checks/status/FlowExecutionAnalyzer.java index 9d5bbe97..553d6213 100644 --- a/src/main/java/io/jenkins/plugins/checks/status/FlowExecutionAnalyzer.java +++ b/src/main/java/io/jenkins/plugins/checks/status/FlowExecutionAnalyzer.java @@ -89,7 +89,7 @@ private Pair processStageOrBranchRow(final FlowGraphTable.Row ro if (row.getNode().isActive()) { nodeTextBuilder.append(" *(running)*"); } - else if (row.getDurationMillis() > 0) { + else { nodeTextBuilder.append(String.format(" *(%s)*", row.getDurationString())); } nodeTextBuilder.append("\n"); diff --git a/src/test/java/io/jenkins/plugins/checks/status/BuildStatusChecksPublisherITest.java b/src/test/java/io/jenkins/plugins/checks/status/BuildStatusChecksPublisherITest.java index cb78ed51..6f92a5bb 100644 --- a/src/test/java/io/jenkins/plugins/checks/status/BuildStatusChecksPublisherITest.java +++ b/src/test/java/io/jenkins/plugins/checks/status/BuildStatusChecksPublisherITest.java @@ -171,9 +171,9 @@ public void shouldPublishStageDetails() { // Details 2, first stage finished, parallel started details = checksDetails.get(2); assertThat(details.getOutput()).isPresent().get().satisfies(output -> { + assertThat(output.getTitle()).contains("In progress"); assertThat(output.getSummary()).isPresent().get().satisfies(StringUtils::isBlank); assertThat(output.getText()).isPresent().get().satisfies(text -> { - assertThat(output.getTitle()).contains("In progress"); assertThat(text).matches(Pattern.compile(".*\\* Simple Stage \\*\\([^)]+\\)\\*.*", Pattern.DOTALL)); assertThat(text).contains(" * In parallel *(running)*"); });