Updated exit codes and guarded against no projects to run
- exit code for build unstable resulted in batch being failed - migrated to completed build status and manually checks the execution result - added a guard against no projects to run when marking the run post release tasks only option Fixes gh-190, gh-191
This commit is contained in:
2
pom.xml
2
pom.xml
@@ -12,7 +12,7 @@
|
||||
<parent>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-build</artifactId>
|
||||
<version>2.2.1.RELEASE</version>
|
||||
<version>2.2.3.RELEASE</version>
|
||||
<relativePath/>
|
||||
<!-- lookup parent from repository -->
|
||||
</parent>
|
||||
|
||||
@@ -53,13 +53,13 @@ public class BuildUnstableException extends RuntimeException implements Serializ
|
||||
|
||||
public BuildUnstableException(Throwable cause) {
|
||||
super(cause);
|
||||
log.error("\n\n" + DESCRIPTION, cause);
|
||||
log.warn("\n\n" + DESCRIPTION, cause);
|
||||
this.exceptions.add(cause);
|
||||
}
|
||||
|
||||
public BuildUnstableException(String message, List<Throwable> throwables) {
|
||||
this(throwables);
|
||||
log.error("\n\n" + DESCRIPTION + message + " with causes " + throwables);
|
||||
log.warn("\n\n" + DESCRIPTION + message + " with causes " + throwables);
|
||||
}
|
||||
|
||||
// for Jackson
|
||||
|
||||
@@ -134,8 +134,9 @@ class SpringBatchFlowRunner implements FlowRunner, Closeable {
|
||||
contribution.getStepExecution().getExecutionContext()
|
||||
.put("entity", entity);
|
||||
if (result.isFailureOrUnstable()) {
|
||||
log.warn("The execution of [{}] failed or was unstable",
|
||||
entity.getReleaserTaskType().getSimpleName());
|
||||
log.warn("The execution of [{}] failed [{}] / unstable [{}]",
|
||||
entity.getReleaserTaskType().getSimpleName(),
|
||||
result.isFailure(), result.isUnstable());
|
||||
contribution.getStepExecution().getExecutionContext()
|
||||
.put("errors", errors);
|
||||
}
|
||||
@@ -212,8 +213,8 @@ class SpringBatchFlowRunner implements FlowRunner, Closeable {
|
||||
return stepExecution.getExitStatus();
|
||||
}
|
||||
else if (result.isUnstable()) {
|
||||
return new ExitStatus(BuildUnstableException.EXIT_CODE,
|
||||
BuildUnstableException.DESCRIPTION);
|
||||
return ExitStatus.COMPLETED
|
||||
.addExitDescription(BuildUnstableException.DESCRIPTION);
|
||||
}
|
||||
else if (result.isFailure()) {
|
||||
return ExitStatus.FAILED;
|
||||
@@ -226,6 +227,10 @@ class SpringBatchFlowRunner implements FlowRunner, Closeable {
|
||||
@Override
|
||||
public ExecutionResult runReleaseTasks(Options options, ReleaserProperties properties,
|
||||
ProjectsToRun projectsToRun, TasksToRun tasksToRun) {
|
||||
if (properties.isPostReleaseTasksOnly() && options.metaRelease) {
|
||||
log.info("Only post release tasks will be executed for the meta release");
|
||||
return ExecutionResult.skipped();
|
||||
}
|
||||
ProjectsToReleaseGroups groups = new ProjectsToReleaseGroups(properties);
|
||||
List<ReleaseGroup> releaseGroups = groups.toReleaseGroup(projectsToRun);
|
||||
if (groups.hasGroups()) {
|
||||
@@ -416,10 +421,7 @@ class SpringBatchFlowRunner implements FlowRunner, Closeable {
|
||||
+ execution.getExitStatus().getExitDescription() + "]"));
|
||||
}
|
||||
List<Exception> thrownExceptions = exceptionsThrownBySteps(execution);
|
||||
if (thrownExceptions.isEmpty()) {
|
||||
return ExecutionResult.success();
|
||||
}
|
||||
return ExecutionResult.failure(thrownExceptions);
|
||||
return new ExecutionResult(thrownExceptions);
|
||||
}
|
||||
catch (JobExecutionException ex) {
|
||||
return ExecutionResult.failure(ex);
|
||||
|
||||
@@ -0,0 +1,180 @@
|
||||
/*
|
||||
* Copyright 2013-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package releaser.internal.spring;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import org.assertj.core.api.BDDAssertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.BDDMockito;
|
||||
import releaser.internal.ReleaserProperties;
|
||||
import releaser.internal.options.Options;
|
||||
import releaser.internal.options.OptionsBuilder;
|
||||
import releaser.internal.project.ProjectVersion;
|
||||
import releaser.internal.project.Projects;
|
||||
import releaser.internal.tasks.ProjectPostReleaseReleaserTask;
|
||||
import releaser.internal.tasks.TrainPostReleaseReleaserTask;
|
||||
import releaser.internal.tech.ExecutionResult;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.SpringBootConfiguration;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.test.context.ActiveProfiles;
|
||||
|
||||
@SpringBootTest
|
||||
@ActiveProfiles("batch")
|
||||
class SpringBatchFlowRunnerTests {
|
||||
|
||||
ReleaserProperties releaserProperties = new ReleaserProperties();
|
||||
|
||||
@Test
|
||||
void should_not_fail_the_release_when_project_post_release_task_fails(
|
||||
@Autowired SpringBatchFlowRunner runner) {
|
||||
Options options = new OptionsBuilder().interactive(false).options();
|
||||
ProjectsToRun projectsToRun = projectsToRun(options, releaserProperties);
|
||||
TasksToRun tasks = new TasksToRun(new MyProjectPostReleaseTask());
|
||||
|
||||
ExecutionResult executionResult = runner.runReleaseTasks(options,
|
||||
releaserProperties, projectsToRun, tasks);
|
||||
|
||||
BDDAssertions.then(executionResult.isUnstable()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
void should_execute_post_train_tasks_when_such_property_is_set(
|
||||
@Autowired SpringBatchFlowRunner runner,
|
||||
@Autowired ProjectsToRunFactory factory) {
|
||||
Options options = new OptionsBuilder().interactive(false).metaRelease(true)
|
||||
.options();
|
||||
releaserProperties.setPostReleaseTasksOnly(true);
|
||||
releaserProperties.getMetaRelease().setReleaseTrainProjectName("foo");
|
||||
ProjectsToRun projectsToRun = projectsToRun(options, releaserProperties);
|
||||
BDDMockito.given(factory.postReleaseTrain(BDDMockito.any()))
|
||||
.willReturn(projectsToRun);
|
||||
TasksToRun tasks = new TasksToRun(new MyPostTrainReleaseTask());
|
||||
|
||||
ExecutionResult executionResult = runner.runReleaseTasks(options,
|
||||
releaserProperties, projectsToRun, tasks);
|
||||
|
||||
BDDAssertions.then(executionResult.isSkipped()).isTrue();
|
||||
|
||||
executionResult = runner.runPostReleaseTrainTasks(options, releaserProperties,
|
||||
"post-release", tasks);
|
||||
|
||||
BDDAssertions.then(executionResult.isSuccess()).isTrue();
|
||||
}
|
||||
|
||||
private ProjectsToRun projectsToRun(Options options,
|
||||
ReleaserProperties releaserProperties) {
|
||||
return new ProjectsToRun(new ProjectToRun.ProjectToRunSupplier("test",
|
||||
() -> projectToRun(options, releaserProperties)));
|
||||
}
|
||||
|
||||
private ProjectToRun projectToRun(Options options,
|
||||
ReleaserProperties releaserProperties) {
|
||||
return new ProjectToRun(new File("."),
|
||||
new ProjectsFromBom(new Projects(), new ProjectVersion("foo", "0.0.1")),
|
||||
new ProjectVersion("foo", "0.0.1"), releaserProperties, options);
|
||||
}
|
||||
|
||||
@SpringBootConfiguration
|
||||
@EnableAutoConfiguration
|
||||
static class Config extends BatchConfiguration {
|
||||
|
||||
@Bean
|
||||
ProjectsToRunFactory projectsToRunFactory() {
|
||||
return BDDMockito.mock(ProjectsToRunFactory.class);
|
||||
}
|
||||
|
||||
@Bean
|
||||
ReleaserProperties releaserProperties() {
|
||||
return new ReleaserProperties();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class MyProjectPostReleaseTask implements ProjectPostReleaseReleaserTask {
|
||||
|
||||
@Override
|
||||
public String name() {
|
||||
return "post-release-task";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String shortName() {
|
||||
return name();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String header() {
|
||||
return name();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String description() {
|
||||
return name();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ExecutionResult runTask(Arguments args) {
|
||||
return ExecutionResult.unstable(new RuntimeException("Some instability"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getOrder() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class MyPostTrainReleaseTask implements TrainPostReleaseReleaserTask {
|
||||
|
||||
@Override
|
||||
public String name() {
|
||||
return "train-post-release-task";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String shortName() {
|
||||
return name();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String header() {
|
||||
return name();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String description() {
|
||||
return name();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ExecutionResult runTask(Arguments args) {
|
||||
return ExecutionResult.success();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getOrder() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
||||
7
releaser-spring/src/test/resources/application-batch.yml
Normal file
7
releaser-spring/src/test/resources/application-batch.yml
Normal file
@@ -0,0 +1,7 @@
|
||||
releaser:
|
||||
git:
|
||||
org-name: hello
|
||||
|
||||
spring:
|
||||
batch:
|
||||
initialize-schema: always
|
||||
Reference in New Issue
Block a user