You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by hb...@apache.org on 2021/05/27 05:50:53 UTC
[maven-dist-tool] branch master updated: Fix quickperf link by
fetching directly build status from Github API (#3)
This is an automated email from the ASF dual-hosted git repository.
hboutemy pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/maven-dist-tool.git
The following commit(s) were added to refs/heads/master by this push:
new 8cdda69 Fix quickperf link by fetching directly build status from Github API (#3)
8cdda69 is described below
commit 8cdda69689aafe42c6fa943d0302e313c608281b
Author: Patrice CAVEZZAN <pc...@gmail.com>
AuthorDate: Thu May 27 07:50:46 2021 +0200
Fix quickperf link by fetching directly build status from Github API (#3)
* Generate report from quickperf maven test bench directly with github api
* Convert report generation with fluent API call.
* Use a more accurate comment for this report.
---
pom.xml | 7 +
.../dist/tools/memorycheck/MemoryCheckReport.java | 206 +++++++++++++++++++++
src/site/markdown/index.md | 4 +-
3 files changed, 215 insertions(+), 2 deletions(-)
diff --git a/pom.xml b/pom.xml
index fdfb0d8..6e7ea31 100644
--- a/pom.xml
+++ b/pom.xml
@@ -113,6 +113,12 @@
<artifactId>maven-aether-provider</artifactId>
<version>${mvnversion}</version>
</dependency>
+ <!-- https://mvnrepository.com/artifact/org.kohsuke/github-api -->
+ <dependency>
+ <groupId>org.kohsuke</groupId>
+ <artifactId>github-api</artifactId>
+ <version>1.129</version>
+ </dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
@@ -247,6 +253,7 @@
<report>list-plugins-prerequisites</report>
<report>list-master-jobs</report>
<report>list-branches</report>
+ <report>memory-check</report>
</reports>
</reportSet>
<reportSet>
diff --git a/src/main/java/org/apache/maven/dist/tools/memorycheck/MemoryCheckReport.java b/src/main/java/org/apache/maven/dist/tools/memorycheck/MemoryCheckReport.java
new file mode 100644
index 0000000..0d1ff70
--- /dev/null
+++ b/src/main/java/org/apache/maven/dist/tools/memorycheck/MemoryCheckReport.java
@@ -0,0 +1,206 @@
+package org.apache.maven.dist.tools.memorycheck;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.apache.maven.dist.tools.AbstractDistCheckReport;
+import org.apache.maven.dist.tools.ConfigurationLineInfo;
+import org.apache.maven.doxia.sink.Sink;
+import org.apache.maven.doxia.sink.SinkEventAttributes;
+import org.apache.maven.doxia.sink.impl.SinkEventAttributeSet;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugins.annotations.Mojo;
+import org.apache.maven.reporting.MavenReportException;
+import org.kohsuke.github.GHWorkflowJob;
+import org.kohsuke.github.GHWorkflowRun;
+import org.kohsuke.github.GitHub;
+
+import java.io.IOException;
+import java.time.ZoneId;
+import java.time.format.DateTimeFormatter;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Locale;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+import java.util.stream.StreamSupport;
+
+/**
+ * Generate from now a single page with an history of build status from
+ * <a href="https://github.com/quick-perf/maven-test-bench">Maven Test Bench</a> project, which runs a daily
+ * memory check based on running `mvn validate` on a third party project using Github Action platform.
+ *
+ * @author Patrice Cavezzan
+ */
+
+@Mojo( name = "memory-check", requiresProject = false )
+public class MemoryCheckReport extends AbstractDistCheckReport
+{
+
+ private static final String GITHUB_REPOSITORY = "quick-perf/maven-test-bench";
+ public static final String GITHUB_REPOSITORY_URL = "https://github.com/" + GITHUB_REPOSITORY;
+ public static final String MEMORY_CHECK_GITHUB_ACTION_WORKFLOW_NAME = "Daily Memory Check";
+ private static final int BUILD_HISTORY_SIZE = 10;
+ private static final int GITHUB_ACTION_JOB_PAGE_SIZE = 10;
+
+ @Override
+ protected void executeReport( Locale locale ) throws MavenReportException
+ {
+ final Sink sink = getSink();
+
+ sink.head();
+ generateTitle( sink );
+ sink.head_();
+
+ sink.body();
+ generateMavenTestBenchIntroduction( sink );
+ sink.paragraph();
+ generateMavenTestBenchBuildStatusResult( sink );
+ sink.paragraph_();
+ sink.body_();
+ }
+
+ private void generateTitle( Sink sink )
+ {
+ sink.title();
+ sink.text( "Memory Check" );
+ sink.title_();
+ }
+
+ private void generateMavenTestBenchIntroduction( Sink sink )
+ {
+ final SinkEventAttributes mavenQuickPerfLinkAttributes = new SinkEventAttributeSet();
+ mavenQuickPerfLinkAttributes.addAttribute( SinkEventAttributes.TITLE, "Memory Check" );
+ // open in new tab to avoid being blocked by iframe
+ mavenQuickPerfLinkAttributes.addAttribute( SinkEventAttributes.TARGET , "_blank" );
+ sink.link( GITHUB_REPOSITORY_URL, mavenQuickPerfLinkAttributes );
+ sink.text( "Memory Check" );
+ sink.link_( );
+ sink.text( "is running " );
+ sink.rawText( "mvn validate" );
+ sink.text( " on a massive multi module project, and we make sure that memory allocation stay " );
+ final SinkEventAttributes sampleLinkAttributes = new SinkEventAttributeSet();
+ sampleLinkAttributes.addAttribute( SinkEventAttributes.TITLE, "Threashold set" );
+ // open in new tab to avoid being blocked by iframe
+ sampleLinkAttributes.addAttribute( SinkEventAttributes.TARGET , "_blank" );
+ sink.link(
+ GITHUB_REPOSITORY_URL + "/blob/master/maven-perf/src/test/java/org/quickperf/"
+ + "maven/bench/head/MvnValidateMaxAllocation.java#L52",
+ sampleLinkAttributes
+ );
+ sink.text( "under a certain threshold." );
+ sink.link_();
+ }
+
+ private void generateMavenTestBenchBuildStatusResult( Sink sink )
+ {
+ sink.lineBreak();
+ sink.text( "Current build status: " );
+ List<GHWorkflowJob> status = getLatestBuildStatus();
+ sink.list();
+ status.forEach( s ->
+ {
+ sink.listItem();
+ sink.link( s.getHtmlUrl().toString() );
+ sink.text( DateTimeFormatter.ISO_LOCAL_DATE
+ .withZone( ZoneId.of( "UTC" ) )
+ .format( s.getStartedAt().toInstant() ) );
+ if ( s.getConclusion() == GHWorkflowRun.Conclusion.SUCCESS )
+ {
+ iconSuccess( sink );
+ }
+ else
+ {
+ iconError( sink );
+ }
+ sink.link_();
+ sink.listItem_();
+ } );
+ sink.list_();
+ }
+
+ @Override
+ protected boolean isIndexPageCheck()
+ {
+ return false;
+ }
+
+ @Override
+ protected void checkArtifact( ConfigurationLineInfo request, String repoBase ) throws MojoExecutionException
+ {
+ }
+
+ @Override
+ protected String getFailuresFilename()
+ {
+ return null;
+ }
+
+ @Override
+ public String getOutputName()
+ {
+ return "dist-tool-memory-check";
+ }
+
+ @Override
+ public String getName( Locale locale )
+ {
+ return "Dist Tool> Memory Check";
+ }
+
+ @Override
+ public String getDescription( Locale locale )
+ {
+ return "Display daily memory result from a QuickPerf sub project on github";
+ }
+
+ private List<GHWorkflowJob> getLatestBuildStatus()
+ {
+ try
+ {
+ return StreamSupport.stream(
+ GitHub.connect()
+ .getRepository( GITHUB_REPOSITORY )
+ .queryWorkflowRuns().list().withPageSize( GITHUB_ACTION_JOB_PAGE_SIZE )
+ .spliterator(),
+ false )
+ .limit( BUILD_HISTORY_SIZE )
+ .filter( ghWorkflowRun -> ghWorkflowRun.getName().equals( MEMORY_CHECK_GITHUB_ACTION_WORKFLOW_NAME ) )
+ .flatMap( ghWorkflowRun ->
+ {
+ try
+ {
+ return Arrays.stream( ghWorkflowRun.listJobs().toArray() );
+ }
+ catch ( IOException e )
+ {
+ getLog().warn( e );
+ return Stream.empty();
+ }
+ } )
+ .collect( Collectors.toList() );
+ }
+ catch ( IOException e )
+ {
+ getLog().warn( e );
+ return new ArrayList<>();
+ }
+ }
+}
diff --git a/src/site/markdown/index.md b/src/site/markdown/index.md
index 98ea7c7..11512ed 100644
--- a/src/site/markdown/index.md
+++ b/src/site/markdown/index.md
@@ -47,8 +47,7 @@ in other context, it would require more configurations.
## Maven Core Performance Checks
-* [Memory Check](https://github.com/quick-perf/maven-test-bench/) [![Daily Memory Check](https://github.com/quick-perf/maven-test-bench/actions/workflows/memorycheck.yml/badge.svg)](https://github.com/quick-perf/maven-test-bench/actions/workflows/memorycheck.yml),
-running `mvn validate` on a massive multi module project, and we make sure that [memory allocation stay under a certain threshold](https://github.com/quick-perf/maven-test-bench/blob/master/maven-perf/src/test/java/org/quickperf/maven/bench/head/MvnValidateMaxAllocation.java#L52).
+* [Memory Check][11] report, displaying daily memory check result.
_Powered by [QuickPerf](https://github.com/quick-perf/)_
@@ -62,3 +61,4 @@ _Powered by [QuickPerf](https://github.com/quick-perf/)_
[8]: ./dist-tool-check-errors.html
[9]: ./dist-tool-master-jobs.html
[10]: ./dist-tool-branches.html
+[11]: ./dist-tool-memory-check.html
\ No newline at end of file