All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.g2forge.gearbox.github.actions.HGHActions Maven / Gradle / Ivy

The newest version!
package com.g2forge.gearbox.github.actions;

import java.util.Set;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
import com.fasterxml.jackson.dataformat.yaml.YAMLGenerator.Feature;
import com.g2forge.alexandria.annotations.note.Note;
import com.g2forge.alexandria.annotations.note.NoteType;
import com.g2forge.alexandria.java.core.marker.Helpers;
import com.g2forge.gearbox.github.actions.GHActionJob.GHActionJobBuilder;
import com.g2forge.gearbox.github.actions.GHActionStep.GHActionStepBuilder;
import com.g2forge.gearbox.github.actions.GHActionWorkflow.GHActionWorkflowBuilder;

import lombok.Getter;
import lombok.experimental.UtilityClass;

@UtilityClass
@Helpers
public class HGHActions {
	@Getter(lazy = true)
	private static final ObjectMapper mapper = new ObjectMapper(new YAMLFactory().enable(Feature.MINIMIZE_QUOTES).disable(Feature.WRITE_DOC_START_MARKER));

	@Note(type = NoteType.TODO, value = "Use gb-command to render command lines")
	public static GHActionWorkflow createMavenWorkflow(String name, Set dependencies) {
		if ((name == null) && (dependencies != null) && (dependencies.size() > 0)) throw new IllegalArgumentException("You must provide a name for this repository (subdirectory, logging, etc) if you want to build dependencies!");

		final GHActionWorkflowBuilder workflow = GHActionWorkflow.builder().name("Java CI with Maven");

		workflow.on(GHActionEvent.Push, GHActionEventConfiguration.builder().branch("master").build());
		workflow.on(GHActionEvent.PullRequest, GHActionEventConfiguration.builder().branch("master").build());

		final GHActionJobBuilder build = GHActionJob.builder().runsOn("ubuntu-latest");
		final String JAVA_VERSION = "11";
		build.step(GHActionStep.builder().name("Set up JDK " + JAVA_VERSION).uses("actions/setup-java@v1").with("java-version", JAVA_VERSION).build());
		if (dependencies != null) for (String dependency : dependencies) {
			final String repo = dependency.substring(dependency.indexOf('/') + 1);
			build.step(GHActionStep.builder().name("Checkout " + repo).uses("actions/checkout@v2").with("repository", dependency).with("path", repo).build());
			build.step(GHActionStep.builder().name("Build " + repo).workingDirectory("./" + repo).run("mvn -B install --file pom.xml -P release -Dgpg.skip -DskipTests").build());
		}
		{
			final GHActionStepBuilder checkout = GHActionStep.builder().name("Checkout").uses("actions/checkout@v2");
			if (name != null) checkout.with("path", name);
			build.step(checkout.build());
			final GHActionStepBuilder maven = GHActionStep.builder().name("Build with Maven");
			if (name != null) maven.workingDirectory("./" + name);
			build.step(maven.run("mvn -B package --file pom.xml -P release -Dgpg.skip").build());
		}
		workflow.job("build", build.build());

		return workflow.build();
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy