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
This commit is contained in:
parent
78f059e446
commit
57cf0bf3bb
|
@ -22,16 +22,21 @@ import org.gradle.api.file.RegularFileProperty;
|
||||||
import org.gradle.api.tasks.Input;
|
import org.gradle.api.tasks.Input;
|
||||||
import org.gradle.api.tasks.InputFile;
|
import org.gradle.api.tasks.InputFile;
|
||||||
import org.gradle.api.tasks.Optional;
|
import org.gradle.api.tasks.Optional;
|
||||||
|
import org.gradle.api.tasks.OutputFile;
|
||||||
import org.gradle.api.tasks.TaskAction;
|
import org.gradle.api.tasks.TaskAction;
|
||||||
|
import org.gradle.work.DisableCachingByDefault;
|
||||||
import org.yaml.snakeyaml.Yaml;
|
import org.yaml.snakeyaml.Yaml;
|
||||||
import org.yaml.snakeyaml.constructor.Constructor;
|
import org.yaml.snakeyaml.constructor.Constructor;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileInputStream;
|
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;
|
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 {
|
public abstract class GitHubMilestoneNextVersionDueTodayTask extends DefaultTask {
|
||||||
|
|
||||||
@Input
|
@Input
|
||||||
|
@ -44,10 +49,13 @@ public abstract class GitHubMilestoneNextVersionDueTodayTask extends DefaultTask
|
||||||
@InputFile
|
@InputFile
|
||||||
public abstract RegularFileProperty getNextVersionFile();
|
public abstract RegularFileProperty getNextVersionFile();
|
||||||
|
|
||||||
|
@OutputFile
|
||||||
|
public abstract RegularFileProperty getIsDueTodayFile();
|
||||||
|
|
||||||
private GitHubMilestoneApi milestones = new GitHubMilestoneApi();
|
private GitHubMilestoneApi milestones = new GitHubMilestoneApi();
|
||||||
|
|
||||||
@TaskAction
|
@TaskAction
|
||||||
public void checkReleaseDueToday() throws FileNotFoundException {
|
public void checkReleaseDueToday() throws IOException {
|
||||||
File nextVersionFile = getNextVersionFile().getAsFile().get();
|
File nextVersionFile = getNextVersionFile().getAsFile().get();
|
||||||
Yaml yaml = new Yaml(new Constructor(NextVersionYml.class));
|
Yaml yaml = new Yaml(new Constructor(NextVersionYml.class));
|
||||||
NextVersionYml nextVersionYml = yaml.load(new FileInputStream(nextVersionFile));
|
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());
|
"Could not find version property in provided file " + nextVersionFile.getName());
|
||||||
}
|
}
|
||||||
boolean milestoneDueToday = this.milestones.isMilestoneDueToday(this.repository, nextVersion);
|
boolean milestoneDueToday = this.milestones.isMilestoneDueToday(this.repository, nextVersion);
|
||||||
if (!milestoneDueToday) {
|
Path isDueTodayPath = getIsDueTodayFile().getAsFile().get().toPath();
|
||||||
throw new IllegalStateException("The milestone with the title " + nextVersion + " in the repository "
|
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");
|
+ 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() {
|
public RepositoryRef getRepository() {
|
||||||
|
|
|
@ -59,6 +59,7 @@ public class GitHubMilestonePlugin implements Plugin<Project> {
|
||||||
public void execute(GitHubMilestoneNextVersionDueTodayTask gitHubMilestoneNextVersionDueTodayTask) {
|
public void execute(GitHubMilestoneNextVersionDueTodayTask gitHubMilestoneNextVersionDueTodayTask) {
|
||||||
gitHubMilestoneNextVersionDueTodayTask.setGroup("Release");
|
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.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(
|
gitHubMilestoneNextVersionDueTodayTask.getNextVersionFile().convention(
|
||||||
nextReleaseMilestoneTask.flatMap(GitHubMilestoneNextReleaseTask::getNextReleaseFile));
|
nextReleaseMilestoneTask.flatMap(GitHubMilestoneNextReleaseTask::getNextReleaseFile));
|
||||||
if (project.hasProperty("gitHubAccessToken")) {
|
if (project.hasProperty("gitHubAccessToken")) {
|
||||||
|
|
Loading…
Reference in New Issue