From 57cf0bf3bbe53fe5952a4980ceecc863f383af70 Mon Sep 17 00:00:00 2001 From: Rob Winch Date: Wed, 20 Apr 2022 13:48:42 -0500 Subject: [PATCH] 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 --- ...itHubMilestoneNextVersionDueTodayTask.java | 25 ++++++++++++++----- .../milestones/GitHubMilestonePlugin.java | 1 + 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/buildSrc/src/main/java/org/springframework/gradle/github/milestones/GitHubMilestoneNextVersionDueTodayTask.java b/buildSrc/src/main/java/org/springframework/gradle/github/milestones/GitHubMilestoneNextVersionDueTodayTask.java index 93fef9d1e5..1ff7ec51f0 100644 --- a/buildSrc/src/main/java/org/springframework/gradle/github/milestones/GitHubMilestoneNextVersionDueTodayTask.java +++ b/buildSrc/src/main/java/org/springframework/gradle/github/milestones/GitHubMilestoneNextVersionDueTodayTask.java @@ -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 @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 "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() { diff --git a/buildSrc/src/main/java/org/springframework/gradle/github/milestones/GitHubMilestonePlugin.java b/buildSrc/src/main/java/org/springframework/gradle/github/milestones/GitHubMilestonePlugin.java index 2dc92c2edf..0137801968 100644 --- a/buildSrc/src/main/java/org/springframework/gradle/github/milestones/GitHubMilestonePlugin.java +++ b/buildSrc/src/main/java/org/springframework/gradle/github/milestones/GitHubMilestonePlugin.java @@ -59,6 +59,7 @@ public class GitHubMilestonePlugin implements Plugin { 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")) {