Browse Source

GitHubMilestoneNextVersionDueTodayTask Outputs to File

Rather than having the task fail if the milestone is not due today, it now
outputs to a file true or false. This allows the pipeline to determine
if it should continue or not without causing a failure.

Issue gh-11158
pull/11176/head
Rob Winch 4 years ago committed by Eleftheria Stein
parent
commit
57cf0bf3bb
  1. 25
      buildSrc/src/main/java/org/springframework/gradle/github/milestones/GitHubMilestoneNextVersionDueTodayTask.java
  2. 1
      buildSrc/src/main/java/org/springframework/gradle/github/milestones/GitHubMilestonePlugin.java

25
buildSrc/src/main/java/org/springframework/gradle/github/milestones/GitHubMilestoneNextVersionDueTodayTask.java

@ -22,16 +22,21 @@ import org.gradle.api.file.RegularFileProperty; @@ -22,16 +22,21 @@ import org.gradle.api.file.RegularFileProperty;
import org.gradle.api.tasks.Input;
import org.gradle.api.tasks.InputFile;
import org.gradle.api.tasks.Optional;
import org.gradle.api.tasks.OutputFile;
import org.gradle.api.tasks.TaskAction;
import org.gradle.work.DisableCachingByDefault;
import org.yaml.snakeyaml.Yaml;
import org.yaml.snakeyaml.constructor.Constructor;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import org.springframework.gradle.github.RepositoryRef;
@DisableCachingByDefault(because = "the due date needs to be checked every time in case it changes")
public abstract class GitHubMilestoneNextVersionDueTodayTask extends DefaultTask {
@Input
@ -44,10 +49,13 @@ public abstract class GitHubMilestoneNextVersionDueTodayTask extends DefaultTask @@ -44,10 +49,13 @@ public abstract class GitHubMilestoneNextVersionDueTodayTask extends DefaultTask
@InputFile
public abstract RegularFileProperty getNextVersionFile();
@OutputFile
public abstract RegularFileProperty getIsDueTodayFile();
private GitHubMilestoneApi milestones = new GitHubMilestoneApi();
@TaskAction
public void checkReleaseDueToday() throws FileNotFoundException {
public void checkReleaseDueToday() throws IOException {
File nextVersionFile = getNextVersionFile().getAsFile().get();
Yaml yaml = new Yaml(new Constructor(NextVersionYml.class));
NextVersionYml nextVersionYml = yaml.load(new FileInputStream(nextVersionFile));
@ -57,12 +65,17 @@ public abstract class GitHubMilestoneNextVersionDueTodayTask extends DefaultTask @@ -57,12 +65,17 @@ public abstract class GitHubMilestoneNextVersionDueTodayTask extends DefaultTask
"Could not find version property in provided file " + nextVersionFile.getName());
}
boolean milestoneDueToday = this.milestones.isMilestoneDueToday(this.repository, nextVersion);
if (!milestoneDueToday) {
throw new IllegalStateException("The milestone with the title " + nextVersion + " in the repository "
Path isDueTodayPath = getIsDueTodayFile().getAsFile().get().toPath();
Files.writeString(isDueTodayPath, String.valueOf(milestoneDueToday));
if (milestoneDueToday) {
System.out.println("The milestone with the title " + nextVersion + " in the repository " + this.repository
+ " is due today");
}
else {
System.out.println("The milestone with the title " + nextVersion + " in the repository "
+ this.repository + " is not due yet");
}
System.out.println("The milestone with the title " + nextVersion + " in the repository " + this.repository
+ " is due today");
}
public RepositoryRef getRepository() {

1
buildSrc/src/main/java/org/springframework/gradle/github/milestones/GitHubMilestonePlugin.java

@ -59,6 +59,7 @@ public class GitHubMilestonePlugin implements Plugin<Project> { @@ -59,6 +59,7 @@ public class GitHubMilestonePlugin implements Plugin<Project> {
public void execute(GitHubMilestoneNextVersionDueTodayTask gitHubMilestoneNextVersionDueTodayTask) {
gitHubMilestoneNextVersionDueTodayTask.setGroup("Release");
gitHubMilestoneNextVersionDueTodayTask.setDescription("Checks if the next release version is due today or past due, will fail if the next version is not due yet");
gitHubMilestoneNextVersionDueTodayTask.getIsDueTodayFile().value(project.getLayout().getBuildDirectory().file("github/milestones/is-due-today"));
gitHubMilestoneNextVersionDueTodayTask.getNextVersionFile().convention(
nextReleaseMilestoneTask.flatMap(GitHubMilestoneNextReleaseTask::getNextReleaseFile));
if (project.hasProperty("gitHubAccessToken")) {

Loading…
Cancel
Save