Skip to content

Automate release verification steps #510

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 2, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 38 additions & 15 deletions src/Builder.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,56 +14,79 @@
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Locale;
import java.util.Set;

/**
* Platform-agnostic builder
*/
@SuppressWarnings({ "WeakerAccess", "SameParameterValue" })
class Builder {

private static final java.lang.String EXCLUDE_OPTION = "--exclude=";

public static void main(String[] args) {
var status = new Builder().build();
var excludedProjects = determineExcludedProjects(args);
var status = new Builder().build(excludedProjects);
if (status != 0) {
throw new AssertionError("Expected exit status of zero, but got: " + status);
}
}

int status = 0;

int build() {
int build(Set<String> excludedProjects) {
System.out.printf("|%n| Building all samples...%n|%n");
run(".", "java", "--version");
checkLicense("src/eclipse-public-license-2.0.java", ".java", ".kt", ".scala", ".groovy");

// jupiter-starter
if (!isWindows()) { // TODO https://github.com/junit-team/junit5-samples/issues/66
run("junit5-jupiter-starter-ant", "build.sh");
runProject(excludedProjects, "junit5-jupiter-starter-ant", "build.sh");
}
run("junit5-jupiter-starter-gradle", "gradlew", "test");
run("junit5-jupiter-starter-gradle-groovy", "gradlew", "test");
run("junit5-jupiter-starter-gradle-kotlin", "gradlew", "test");
run("junit5-jupiter-starter-maven", "mvnw", "--batch-mode", "clean", "test");
run("junit5-jupiter-starter-maven-kotlin", "mvnw", "--batch-mode", "clean", "test");
run("junit5-jupiter-starter-bazel", "bazel", "test", "//...", "--test_output", "all");
run("junit5-jupiter-starter-sbt", "sbt", "test");
runProject(excludedProjects, "junit5-jupiter-starter-gradle", "gradlew", "test");
runProject(excludedProjects, "junit5-jupiter-starter-gradle-groovy", "gradlew", "test");
runProject(excludedProjects, "junit5-jupiter-starter-gradle-kotlin", "gradlew", "test");
runProject(excludedProjects, "junit5-jupiter-starter-maven", "mvnw", "--batch-mode", "clean", "test");
runProject(excludedProjects, "junit5-jupiter-starter-maven-kotlin", "mvnw", "--batch-mode", "clean", "test");
runProject(excludedProjects, "junit5-jupiter-starter-bazel", "bazel", "test", "//...", "--test_output", "all");
runProject(excludedProjects, "junit5-jupiter-starter-sbt", "sbt", "test");

// jupiter-extensions
run("junit5-jupiter-extensions", "gradlew", "test");
runProject(excludedProjects, "junit5-jupiter-extensions", "gradlew", "test");

// migration
run("junit5-migration-gradle", "gradlew", "test");
run("junit5-migration-maven", "mvnw", "--batch-mode", "clean", "test");
run("junit5-multiple-engines", "gradlew", "test");
runProject(excludedProjects, "junit5-migration-gradle", "gradlew", "test");
runProject(excludedProjects, "junit5-migration-maven", "mvnw", "--batch-mode", "clean", "test");
runProject(excludedProjects, "junit5-multiple-engines", "gradlew", "test");

// modular
run("junit5-modular-world", "jshell", "build.jsh");
runProject(excludedProjects, "junit5-modular-world", "jshell", "build.jsh");

System.out.printf("%n%n%n|%n| Done. Build exits with status = %d.%n|%n", status);
return status;
}

private static Set<String> determineExcludedProjects(String[] args) {
Set<String> excludedProjects = new HashSet<>();
for (var arg : args) {
if (arg.startsWith(EXCLUDE_OPTION)) {
excludedProjects.addAll(Set.of(arg.substring(EXCLUDE_OPTION.length()).split(",")));
}
}
return Set.copyOf(excludedProjects);
}

void runProject(Set<String> excludedProjects, String project, String executable, String... args) {
if (excludedProjects.contains(project)) {
System.out.printf("%n%n%n|%n| %s is excluded.%n|%n", project);
return;
}
run(project, executable, args);
}

void run(String directory, String executable, String... args) {
if (status != 0) {
return;
Expand Down
110 changes: 110 additions & 0 deletions src/StagingRepoInjector.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
/*
* Copyright 2015-2024 the original author or authors.
*
* All rights reserved. This program and the accompanying materials are
* made available under the terms of the Eclipse Public License v2.0 which
* accompanies this distribution and is available at
*
* https://www.eclipse.org/legal/epl-v20.html
*/

// default package

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.function.Consumer;

public class StagingRepoInjector {

public static void main(String[] args) throws Exception {
new StagingRepoInjector(args[0]).appendAfter();
}

private final String stagingRepoUrl;

public StagingRepoInjector(String stagingRepoUrl) {
this.stagingRepoUrl = stagingRepoUrl;
}

private void appendAfter() throws Exception {

appendAfter("junit5-jupiter-extensions/build.gradle", "mavenCentral()",
"%n\tmaven { url = '%s' }".formatted(stagingRepoUrl));

replace("junit5-jupiter-starter-ant/build.sh", "https://repo1.maven.org/maven2", stagingRepoUrl);

appendAfter("junit5-jupiter-starter-bazel/MODULE.bazel", "\"https://repo1.maven.org/maven2\",",
"%n \"%s\",".formatted(stagingRepoUrl));

appendAfter("junit5-jupiter-starter-gradle/build.gradle", "mavenCentral()",
"%n\tmaven { url = '%s' }".formatted(stagingRepoUrl));

appendAfter("junit5-jupiter-starter-gradle-groovy/build.gradle", "mavenCentral()",
"%n\tmaven { url = '%s' }".formatted(stagingRepoUrl));

appendAfter("junit5-jupiter-starter-gradle-kotlin/build.gradle.kts", "mavenCentral()",
"%n\tmaven(url = \"%s\")".formatted(stagingRepoUrl));

var mavenPomRepo = """


\t<repositories>
\t\t<repository>
\t\t\t<id>central-staging</id>
\t\t\t<url>%s</url>
\t\t</repository>
\t</repositories>
""".stripIndent().stripTrailing().formatted(stagingRepoUrl);

appendAfter("junit5-jupiter-starter-maven/pom.xml", "</build>", mavenPomRepo);

appendAfter("junit5-jupiter-starter-maven-kotlin/pom.xml", "</build>", mavenPomRepo);

appendAtEnd("junit5-jupiter-starter-sbt/build.sbt",
"%nresolvers += \"central-staging\" at \"%s\"%n".formatted(stagingRepoUrl));

appendAfter("junit5-migration-gradle/build.gradle", "mavenCentral()",
"%n\tmaven { url = '%s' }".formatted(stagingRepoUrl));

appendAfter("junit5-migration-maven/pom.xml", "</build>", mavenPomRepo);

replace("junit5-modular-world/BUILDING", "\"https://repo1.maven.org/maven2\"",
"group.startsWith(\"org.junit\") ? \"%s\" : \"https://repo1.maven.org/maven2\"".formatted(stagingRepoUrl));

appendAfter("junit5-multiple-engines/build.gradle.kts", "mavenCentral()",
"%n\tmaven(url = \"%s\")".formatted(stagingRepoUrl));
}

void appendAfter(String path, String token, String addedContent) throws IOException {
process(path, content -> {
if (content.indexOf(token) == -1) {
throw new IllegalStateException("Token not found in " + path);
}
content.insert(content.indexOf(token) + token.length(), addedContent);
});
}

void replace(String path, String token, String replacement) throws IOException {
process(path, content -> {
if (content.indexOf(token) == -1) {
throw new IllegalStateException("Token not found in " + path);
}
content.replace(content.indexOf(token), content.indexOf(token) + token.length(), replacement);
});
}

void appendAtEnd(String path, String addedContent) throws IOException {
process(path, content -> content.append(addedContent));
}

void process(String path, Consumer<StringBuilder> modification) throws IOException {
System.out.printf("Processing %s...", path);
System.out.flush();
var file = Path.of(path);
var content = new StringBuilder(Files.readString(file));
modification.accept(content);
Files.writeString(file, content);
System.out.println(" OK");
}
}
Loading