ソースを参照

GitHubMilestoneHasNoOpenIssuesTask outputs to a 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.

Closes gh-11158
Rob Winch 3 年 前
コミット
78f059e446

+ 16 - 4
buildSrc/src/main/java/org/springframework/gradle/github/milestones/GitHubMilestoneHasNoOpenIssuesTask.java

@@ -21,16 +21,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 GitHubMilestoneHasNoOpenIssuesTask extends DefaultTask {
 	@Input
 	private RepositoryRef repository = new RepositoryRef();
@@ -44,10 +49,13 @@ public abstract class GitHubMilestoneHasNoOpenIssuesTask extends DefaultTask {
 	@Input @Optional
 	private String gitHubAccessToken;
 
+	@OutputFile
+	public abstract RegularFileProperty getIsOpenIssuesFile();
+
 	private GitHubMilestoneApi milestones = new GitHubMilestoneApi();
 
 	@TaskAction
-	public void checkHasNoOpenIssues() throws FileNotFoundException {
+	public void checkHasNoOpenIssues() throws IOException {
 		if (this.milestoneTitle == null) {
 			File nextVersionFile = getNextVersionFile().getAsFile().get();
 			Yaml yaml = new Yaml(new Constructor(NextVersionYml.class));
@@ -61,10 +69,14 @@ public abstract class GitHubMilestoneHasNoOpenIssuesTask extends DefaultTask {
 		}
 		long milestoneNumber = this.milestones.findMilestoneNumberByTitle(this.repository, this.milestoneTitle);
 		boolean isOpenIssues = this.milestones.isOpenIssuesForMilestoneNumber(this.repository, milestoneNumber);
+		Path isOpenIssuesPath = getIsOpenIssuesFile().getAsFile().get().toPath();
+		Files.writeString(isOpenIssuesPath, String.valueOf(isOpenIssues));
 		if (isOpenIssues) {
-			throw new IllegalStateException("The repository " + this.repository + " has open issues for milestone with the title " + this.milestoneTitle + " and number " + milestoneNumber);
+			System.out.println("The repository " + this.repository + " has open issues for milestone with the title " + this.milestoneTitle + " and number " + milestoneNumber);
+		}
+		else {
+			System.out.println("The repository " + this.repository + " has no open issues for milestone with the title " + this.milestoneTitle + " and number " + milestoneNumber);
 		}
-		System.out.println("The repository " + this.repository + " has no open issues for milestone with the title " + this.milestoneTitle + " and number " + milestoneNumber);
 	}
 
 	public RepositoryRef getRepository() {

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

@@ -43,6 +43,7 @@ public class GitHubMilestonePlugin implements Plugin<Project> {
 			public void execute(GitHubMilestoneHasNoOpenIssuesTask githubCheckMilestoneHasNoOpenIssues) {
 				githubCheckMilestoneHasNoOpenIssues.setGroup("Release");
 				githubCheckMilestoneHasNoOpenIssues.setDescription("Checks if there are any open issues for the specified repository and milestone");
+				githubCheckMilestoneHasNoOpenIssues.getIsOpenIssuesFile().value(project.getLayout().getBuildDirectory().file("github/milestones/is-open-issues"));
 				githubCheckMilestoneHasNoOpenIssues.setMilestoneTitle((String) project.findProperty("nextVersion"));
 				if (!project.hasProperty("nextVersion")) {
 					githubCheckMilestoneHasNoOpenIssues.getNextVersionFile().convention(