Update description of smoke tests
This commit harmonizes the description of each smoke test so that the CI lifecycle plugin can read them and create the appropriate GitHub Actions workflow. See gh-61
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2023 the original author or authors.
|
||||
* Copyright 2022-2024 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.
|
||||
@@ -19,6 +19,7 @@ package org.springframework.lifecycle.gradle;
|
||||
import org.gradle.api.Plugin;
|
||||
import org.gradle.api.Project;
|
||||
import org.gradle.api.artifacts.Configuration;
|
||||
import org.gradle.api.tasks.Sync;
|
||||
import org.gradle.api.tasks.TaskProvider;
|
||||
|
||||
import org.springframework.lifecycle.gradle.tasks.UpdateConcoursePipeline;
|
||||
@@ -36,6 +37,10 @@ public class LifecycleSmokeTestAggregatorPlugin implements Plugin<Project> {
|
||||
@Override
|
||||
public void apply(Project project) {
|
||||
Configuration smokeTests = project.getConfigurations().create("smokeTests");
|
||||
project.getTasks().register("describeSmokeTests", Sync.class, (sync) -> {
|
||||
sync.into(project.getLayout().getBuildDirectory().dir("smoke-tests"));
|
||||
sync.from(smokeTests);
|
||||
});
|
||||
TaskProvider<UpdateStatusPage> updateStatusPage = project.getTasks()
|
||||
.register("updateStatusPage", UpdateStatusPage.class, (task) -> {
|
||||
task.setSmokeTests(smokeTests);
|
||||
|
||||
@@ -43,8 +43,9 @@ import org.springframework.boot.gradle.plugin.SpringBootPlugin;
|
||||
import org.springframework.boot.gradle.tasks.bundling.BootJar;
|
||||
import org.springframework.lifecycle.gradle.dsl.LifecycleSmokeTestExtension;
|
||||
import org.springframework.lifecycle.gradle.tasks.AppTest;
|
||||
import org.springframework.lifecycle.gradle.tasks.DescribeSmokeTests;
|
||||
import org.springframework.lifecycle.gradle.tasks.DescribeSmokeTest;
|
||||
import org.springframework.lifecycle.gradle.tasks.RestoreJvmApplication;
|
||||
import org.springframework.lifecycle.gradle.tasks.SmokeTest;
|
||||
import org.springframework.lifecycle.gradle.tasks.StartAndCheckpointJvmApplication;
|
||||
import org.springframework.lifecycle.gradle.tasks.StartApplication;
|
||||
import org.springframework.lifecycle.gradle.tasks.StartJvmApplication;
|
||||
@@ -101,17 +102,25 @@ public class LifecycleSmokeTestPlugin implements Plugin<Project> {
|
||||
configureAppTests(project, extension, appTest);
|
||||
configureTests(project);
|
||||
configureKotlin(project, javaExtension);
|
||||
Configuration smokeTests = project.getConfigurations().create("smokeTests");
|
||||
TaskProvider<DescribeSmokeTests> describeSmokeTests = project.getTasks()
|
||||
.register("describeSmokeTests", DescribeSmokeTests.class);
|
||||
describeSmokeTests.configure((task) -> {
|
||||
task.getOutputDirectory().set(project.getLayout().getBuildDirectory().dir(task.getName()));
|
||||
task.setAppTests(appTest.getAllSource());
|
||||
task.setTests(javaExtension.getSourceSets().getByName(SourceSet.TEST_SOURCE_SET_NAME).getAllSource());
|
||||
Provider<SmokeTest> smokeTestProvider = project.provider(() -> {
|
||||
boolean runTests = false;
|
||||
boolean runAppTests = false;
|
||||
if (!javaExtension.getSourceSets().getByName(SourceSet.TEST_SOURCE_SET_NAME).getAllSource().isEmpty()) {
|
||||
runTests = true;
|
||||
}
|
||||
if (!appTest.getAllSource().isEmpty()) {
|
||||
runAppTests = true;
|
||||
}
|
||||
return new SmokeTest(project.getName(), project.getParent().getName(), project.getPath(), runTests,
|
||||
runAppTests);
|
||||
});
|
||||
project.artifacts((artifacts) -> artifacts.add(smokeTests.getName(), describeSmokeTests));
|
||||
TaskProvider<DescribeSmokeTest> describeSmokeTest = project.getTasks()
|
||||
.register("describeSmokeTest", DescribeSmokeTest.class);
|
||||
describeSmokeTest.configure((task) -> task.getSmokeTest().set(smokeTestProvider));
|
||||
Configuration smokeTests = project.getConfigurations().create("smokeTests");
|
||||
project.artifacts((artifacts) -> artifacts.add(smokeTests.getName(), describeSmokeTest));
|
||||
DependencyHandler dependencies = project.getRootProject().getDependencies();
|
||||
dependencies.add("smokeTests",
|
||||
dependencies.add(smokeTests.getName(),
|
||||
dependencies.project(Map.of("path", project.getPath(), "configuration", smokeTests.getName())));
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,65 @@
|
||||
/*
|
||||
* Copyright 2022-2024 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 org.springframework.lifecycle.gradle.tasks;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.gradle.api.DefaultTask;
|
||||
import org.gradle.api.file.RegularFileProperty;
|
||||
import org.gradle.api.provider.Property;
|
||||
import org.gradle.api.tasks.Input;
|
||||
import org.gradle.api.tasks.OutputFile;
|
||||
import org.gradle.api.tasks.TaskAction;
|
||||
|
||||
/**
|
||||
* Task to describe a smoke test in a consumable format.
|
||||
*
|
||||
* @author Andy Wilkinson
|
||||
*/
|
||||
public abstract class DescribeSmokeTest extends DefaultTask {
|
||||
|
||||
public DescribeSmokeTest() {
|
||||
getOutputFile().convention(getProject().getLayout()
|
||||
.getBuildDirectory()
|
||||
.file(getSmokeTest()
|
||||
.map((smokeTest) -> "smoke-tests/" + smokeTest.group() + "-" + smokeTest.name() + ".properties")));
|
||||
}
|
||||
|
||||
@OutputFile
|
||||
public abstract RegularFileProperty getOutputFile();
|
||||
|
||||
@Input
|
||||
public abstract Property<SmokeTest> getSmokeTest();
|
||||
|
||||
@TaskAction
|
||||
void describeSmokeTest() throws IOException {
|
||||
SmokeTest smokeTest = getSmokeTest().get();
|
||||
File propertiesFile = getOutputFile().getAsFile().get();
|
||||
List<String> properties = new ArrayList<>();
|
||||
properties.add("appTests=" + smokeTest.appTests());
|
||||
properties.add("tests=" + smokeTest.tests());
|
||||
properties.add("path=" + smokeTest.path());
|
||||
properties.add("group=" + smokeTest.group());
|
||||
properties.add("name=" + smokeTest.name());
|
||||
Files.write(propertiesFile.toPath(), properties);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,90 +0,0 @@
|
||||
/*
|
||||
* Copyright 2023 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 org.springframework.lifecycle.gradle.tasks;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.util.List;
|
||||
|
||||
import org.gradle.api.DefaultTask;
|
||||
import org.gradle.api.Task;
|
||||
import org.gradle.api.file.DirectoryProperty;
|
||||
import org.gradle.api.file.FileCollection;
|
||||
import org.gradle.api.provider.MapProperty;
|
||||
import org.gradle.api.tasks.Input;
|
||||
import org.gradle.api.tasks.InputFiles;
|
||||
import org.gradle.api.tasks.OutputDirectory;
|
||||
import org.gradle.api.tasks.TaskAction;
|
||||
|
||||
/**
|
||||
* {@link Task} that describes a project's smoke tests.
|
||||
*
|
||||
* @author Andy Wilkinson
|
||||
*/
|
||||
public abstract class DescribeSmokeTests extends DefaultTask {
|
||||
|
||||
private FileCollection appTests;
|
||||
|
||||
private FileCollection tests;
|
||||
|
||||
public DescribeSmokeTests() {
|
||||
getSmokeTestsDescription().put("appTests",
|
||||
getProject().provider(() -> Boolean.toString(!this.appTests.isEmpty())));
|
||||
getSmokeTestsDescription().put("tests", getProject().provider(() -> Boolean.toString(!this.tests.isEmpty())));
|
||||
getSmokeTestsDescription().put("path", getProject().provider(getProject()::getPath));
|
||||
getSmokeTestsDescription().put("group", getProject().provider(getProject().getParent()::getName));
|
||||
getSmokeTestsDescription().put("name", getProject().provider(getProject()::getName));
|
||||
}
|
||||
|
||||
@Input
|
||||
abstract MapProperty<String, String> getSmokeTestsDescription();
|
||||
|
||||
@OutputDirectory
|
||||
public abstract DirectoryProperty getOutputDirectory();
|
||||
|
||||
@InputFiles
|
||||
public FileCollection getAppTests() {
|
||||
return this.appTests;
|
||||
}
|
||||
|
||||
public void setAppTests(FileCollection appTests) {
|
||||
this.appTests = appTests;
|
||||
}
|
||||
|
||||
@InputFiles
|
||||
public FileCollection getTests() {
|
||||
return this.tests;
|
||||
}
|
||||
|
||||
public void setTests(FileCollection tests) {
|
||||
this.tests = tests;
|
||||
}
|
||||
|
||||
@TaskAction
|
||||
void describeSmokeTests() throws IOException {
|
||||
File smokeTests = getOutputDirectory().file("smoke-tests.properties").get().getAsFile();
|
||||
List<String> lines = getSmokeTestsDescription().get()
|
||||
.entrySet()
|
||||
.stream()
|
||||
.map((entry) -> entry.getKey() + "=" + entry.getValue())
|
||||
.sorted()
|
||||
.toList();
|
||||
Files.write(smokeTests.toPath(), lines);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2023 the original author or authors.
|
||||
* Copyright 2022-2024 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.
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
package org.springframework.lifecycle.gradle.tasks;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Properties;
|
||||
|
||||
/**
|
||||
@@ -28,7 +29,8 @@ import java.util.Properties;
|
||||
* @param tests whether the smoke test contains any unit tests
|
||||
* @param appTests whether the smoke test contains any app tests
|
||||
*/
|
||||
record SmokeTest(String name, String group, String path, boolean tests, boolean appTests) {
|
||||
public record SmokeTest(String name, String group, String path, boolean tests,
|
||||
boolean appTests) implements Serializable {
|
||||
|
||||
SmokeTest(Properties properties) {
|
||||
this(properties.getProperty("name"), properties.getProperty("group"), properties.getProperty("path"),
|
||||
|
||||
Reference in New Issue
Block a user