Skip to content

Commit

Permalink
Capture more data in build scans (#196)
Browse files Browse the repository at this point in the history
This commit enables capture of task inputs and adds common state
capture like the branch name, Git status, ...
  • Loading branch information
melix authored Sep 21, 2021
1 parent a259936 commit d1daf90
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
2 changes: 2 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,10 @@ dependencies {
implementation('org.xhtmlrenderer:core-renderer:8.0') {
exclude group: 'bouncycastle', module:'bcprov-jdk14'
}

implementation 'com.gradle:gradle-enterprise-gradle-plugin:3.7'
implementation 'org.nosphere.gradle.github:gradle-github-actions-plugin:1.3.2'
implementation 'com.gradle:common-custom-user-data-gradle-plugin:1.4.2'

implementation 'org.tomlj:tomlj:1.0.0'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,14 @@
*/
package io.micronaut.build;

import com.gradle.CommonCustomUserDataGradlePlugin;
import com.gradle.enterprise.gradleplugin.GradleEnterpriseExtension;
import com.gradle.enterprise.gradleplugin.GradleEnterprisePlugin;
import com.gradle.scan.plugin.BuildScanExtension;
import org.gradle.api.Plugin;
import org.gradle.api.initialization.Settings;
import org.gradle.api.invocation.Gradle;
import org.gradle.api.plugins.PluginManager;
import org.gradle.api.provider.ProviderFactory;
import org.nosphere.gradle.github.ActionsPlugin;

Expand All @@ -29,7 +31,9 @@
public class MicronautSharedSettingsPlugin implements Plugin<Settings> {
@Override
public void apply(Settings settings) {
settings.getPluginManager().apply(GradleEnterprisePlugin.class);
PluginManager pluginManager = settings.getPluginManager();
pluginManager.apply(GradleEnterprisePlugin.class);
pluginManager.apply(CommonCustomUserDataGradlePlugin.class);
GradleEnterpriseExtension ge = settings.getExtensions().getByType(GradleEnterpriseExtension.class);
configureGradleEnterprise(settings, ge);
}
Expand All @@ -47,11 +51,12 @@ private void configureBuildScansPublishing(GradleEnterpriseExtension ge, boolean
buildScan.publishAlways();
if (isCI) {
buildScan.setUploadInBackground(false);
buildScan.tag("CI");
} else {
buildScan.tag("LOCAL");
publishIfAuthenticated(buildScan);
}
buildScan.capture(c ->
c.setTaskInputFiles(true)
);
});
}

Expand All @@ -62,20 +67,19 @@ private static void applyGitHubActionsPlugin(Gradle gradle) {
private static void publishIfAuthenticated(BuildScanExtension ext) {
try {
ext.getClass().getMethod("publishIfAuthenticated").invoke(ext);
} catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
} catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
System.err.println("Unable to set publish if authenticated on build scan extension");
}
}

private static boolean guessCI(ProviderFactory providers) {
return providers
.environmentVariable("CI").forUseAtConfigurationTime()
.map(s -> // Not all workflows may have the enterprise key set
.flatMap(s -> // Not all workflows may have the enterprise key set
providers.environmentVariable("GRADLE_ENTERPRISE_ACCESS_KEY")
.forUseAtConfigurationTime()
.map(env -> true)
.orElse(false)
.get()
)
.orElse(false)
.get();
Expand Down

0 comments on commit d1daf90

Please sign in to comment.