From a15ce0f46b8795aea69707eb26a38077df9202a6 Mon Sep 17 00:00:00 2001 From: Lars Vierbergen Date: Wed, 17 Aug 2022 17:39:20 +0200 Subject: [PATCH 1/3] Fetch versions from Gradle website to automatically pull in new versions. Versions are filtered to be greater than 5.6 and to be a release version. To be able to keep our build matrix, the strategy there has to be changed to slice the set of discovered versions in a number of parts, and to select the part to run --- .github/workflows/ci.yml | 20 ++--- build.gradle | 5 ++ .../testrunner/AbstractIntegrationTest.java | 89 ++++++++++++++----- .../versions/GradleVersionSpec.java | 45 ++++++++++ .../testrunner/versions/VersionFetcher.java | 54 +++++++++++ 5 files changed, 183 insertions(+), 30 deletions(-) create mode 100644 src/integrationTest/java/eu/xenit/gradle/testrunner/versions/GradleVersionSpec.java create mode 100644 src/integrationTest/java/eu/xenit/gradle/testrunner/versions/VersionFetcher.java diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 3654b8a5..936cd1cd 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -42,18 +42,18 @@ jobs: env: GRADLE_PUBLISH_KEY: ${{ secrets.GRADLE_PLUGINS_PUBLISH_KEY }} GRADLE_PUBLISH_SECRET: ${{ secrets.GRADLE_PLUGINS_PUBLISH_SECRET }} - run: ./gradlew publishPlugins -Pgradle.publish.key=$GRADLE_PUBLISH_KEY -Pgradle.publish.secret=$GRADLE_PUBLISH_SECRET + run: ./gradlew check -PintegrationTestMajorsOnly=true publishPlugins -Pgradle.publish.key=$GRADLE_PUBLISH_KEY -Pgradle.publish.secret=$GRADLE_PUBLISH_SECRET integration-test: - name: "integration-test (gradle-versions=${{ matrix.gradle-versions}})" + name: "integration-test (slice=${{ matrix.slice }})" runs-on: ubuntu-latest strategy: matrix: - gradle-versions: - - 5.6 - - 6.0,6.1,6.2 - - 6.3,6.4,6.5 - - 6.6,6.7,6.8 - - 7.0,7.1,7.2 + slice: + - 0 + - 1 + - 2 + - 3 + - 4 steps: - uses: actions/checkout@v2 with: @@ -64,10 +64,10 @@ jobs: - name: Pull docker images run: 'parallel docker pull -- alfresco/alfresco-content-repository-community:6.0.7-ga tomcat:7-jre8 hello-world alpine:edge' - name: Check - run: ./gradlew check -PintegrationTestGradleVersions=${{ matrix.gradle-versions }} + run: ./gradlew check -PintegrationTestSlice.index=${{ matrix.slice }} -PintegrationTestSlice.total=5 - name: Upload reports if: ${{ failure() }} uses: actions/upload-artifact@v2 with: - name: reports-integration-test-${{ matrix.gradle-versions }} + name: reports-integration-test-${{ matrix.slice }} path: build/reports diff --git a/build.gradle b/build.gradle index 381fbb8d..20e86082 100644 --- a/build.gradle +++ b/build.gradle @@ -133,6 +133,8 @@ dependencies { testImplementation gradleTestKit() testImplementation "org.mockito:mockito-core:4.+" testImplementation 'com.github.stefanbirkner:system-rules:1.19.0' + + integrationTestImplementation 'com.fasterxml.jackson.core:jackson-databind:2.10.3' } @@ -180,6 +182,9 @@ task integrationTest(type: Test, group: "verification") { filter.includeTestsMatching("*[Gradle v${version}.*]") }) } + systemProperty "eu.xenit.gradle.integration.majorsOnly", project.findProperty("integrationTestMajorsOnly") ?: "false" + systemProperty "eu.xenit.gradle.integration.slice.index", project.findProperty("integrationTestSlice.index") ?: "0" + systemProperty "eu.xenit.gradle.integration.slice.total", project.findProperty("integrationTestSlice.total") ?: "1" doFirst { if (gradle.startParameter.offline) { systemProperty "eu.xenit.gradle.integration.useGradleVersion", GradleVersion.current().version diff --git a/src/integrationTest/java/eu/xenit/gradle/testrunner/AbstractIntegrationTest.java b/src/integrationTest/java/eu/xenit/gradle/testrunner/AbstractIntegrationTest.java index d30cd74c..a134c983 100644 --- a/src/integrationTest/java/eu/xenit/gradle/testrunner/AbstractIntegrationTest.java +++ b/src/integrationTest/java/eu/xenit/gradle/testrunner/AbstractIntegrationTest.java @@ -3,22 +3,28 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; +import eu.xenit.gradle.testrunner.versions.GradleVersionSpec; +import eu.xenit.gradle.testrunner.versions.VersionFetcher; import java.io.File; import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; -import java.nio.file.Paths; import java.util.ArrayList; import java.util.Arrays; -import java.util.Collection; -import java.util.HashSet; +import java.util.Collections; +import java.util.Comparator; +import java.util.HashMap; import java.util.LinkedHashSet; import java.util.List; +import java.util.Map; +import java.util.Objects; import java.util.Set; +import java.util.stream.Collectors; import org.apache.commons.io.FileUtils; import org.gradle.testkit.runner.BuildResult; import org.gradle.testkit.runner.GradleRunner; import org.gradle.testkit.runner.TaskOutcome; +import org.gradle.util.GradleVersion; import org.junit.Rule; import org.junit.rules.TemporaryFolder; import org.junit.runner.RunWith; @@ -36,28 +42,71 @@ public abstract class AbstractIntegrationTest { public String gradleVersion; @Parameters(name = "Gradle v{0}") - public static Collection testData() { + public static List testData() { String forceGradleVersion = System.getProperty("eu.xenit.gradle.integration.useGradleVersion"); if (forceGradleVersion != null) { - return Arrays.asList(new Object[][]{ + return Arrays.asList(new String[][]{ {forceGradleVersion}, }); } - return Arrays.asList(new Object[][]{ - {"7.2"}, - {"7.1"}, - {"7.0"}, - {"6.8.3"}, - {"6.7.1"}, - {"6.6.1"}, - {"6.5.1"}, - {"6.4.1"}, - {"6.3"}, - {"6.2.2"}, - {"6.1.1"}, - {"6.0.1"}, - {"5.6.4"}, - }); + + boolean majorsOnly = Boolean.getBoolean("eu.xenit.gradle.integration.majorsOnly"); + Comparator byVersionNumber = Comparator.comparing(versionSpec -> GradleVersion.version(versionSpec.getVersion())); + List fetchedVersions = VersionFetcher.fetchVersions() + .filter(VersionFetcher::isRelease) + .filter(VersionFetcher.greaterThan("5.6")) + .sorted(byVersionNumber) + .collect(Collectors.toList()); + + Map> versionsByMinor = new HashMap<>(); + + for (GradleVersionSpec versionSpec : fetchedVersions) { + String[] versionParts = GradleVersion.version(versionSpec.getVersion()).getBaseVersion().getVersion().split("\\."); + String versionKey = majorsOnly?versionParts[0]:(versionParts[0]+"."+versionParts[1]); + if(versionsByMinor.containsKey(versionKey)) { + versionsByMinor.get(versionKey).add(versionSpec); + } else { + versionsByMinor.put(versionKey, new ArrayList<>(Collections.singletonList(versionSpec))); + if(majorsOnly) { + versionsByMinor.put(versionKey + "-lowest", Collections.singletonList(versionSpec)); + } + } + } + + + List versionsToBuild = versionsByMinor.values() + .stream() + .map(versions -> versions.stream() + // Find latest patch version + .sorted(byVersionNumber.reversed()) + .findFirst() + .orElse(null) + ) + .filter(Objects::nonNull) + .sorted(byVersionNumber) + .map(GradleVersionSpec::getVersion) + .map(version -> new String[]{version}) + .collect(Collectors.toList()); + + List slicedVersions = slice(versionsToBuild); + System.out.println(slicedVersions.stream() + .map(i -> i[0]) + .collect(Collectors.joining(", ", "Running test on versions: ", ""))); + return slicedVersions; + } + + private static List slice(List items) { + try { + int sliceTotal = Integer.parseUnsignedInt( + System.getProperty("eu.xenit.gradle.integration.slice.total", "1")); + int sliceIndex = Integer.parseUnsignedInt( + System.getProperty("eu.xenit.gradle.integration.slice.index", "0")); + int itemsPerSlice = (int)Math.ceil(items.size()/(float)sliceTotal); + System.out.println("Executing slice "+(sliceIndex+1)+"/"+sliceTotal+ " with "+itemsPerSlice+" items per slice"); + return items.subList(itemsPerSlice*sliceIndex, Math.min(itemsPerSlice*(sliceIndex+1), items.size())); + } catch (NumberFormatException e) { + return items; + } } diff --git a/src/integrationTest/java/eu/xenit/gradle/testrunner/versions/GradleVersionSpec.java b/src/integrationTest/java/eu/xenit/gradle/testrunner/versions/GradleVersionSpec.java new file mode 100644 index 00000000..2c674262 --- /dev/null +++ b/src/integrationTest/java/eu/xenit/gradle/testrunner/versions/GradleVersionSpec.java @@ -0,0 +1,45 @@ +package eu.xenit.gradle.testrunner.versions; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import java.util.Comparator; +import org.gradle.util.GradleVersion; + +@JsonIgnoreProperties(ignoreUnknown = true) +public class GradleVersionSpec { + private String version; + private boolean snapshot; + private boolean broken; + private String rcFor; + + public String getVersion() { + return version; + } + + public void setVersion(String version) { + this.version = version; + } + + public boolean isSnapshot() { + return snapshot; + } + + public void setSnapshot(boolean snapshot) { + this.snapshot = snapshot; + } + + public boolean isBroken() { + return broken; + } + + public void setBroken(boolean broken) { + this.broken = broken; + } + + public String getRcFor() { + return rcFor; + } + + public void setRcFor(String rcFor) { + this.rcFor = rcFor; + } +} diff --git a/src/integrationTest/java/eu/xenit/gradle/testrunner/versions/VersionFetcher.java b/src/integrationTest/java/eu/xenit/gradle/testrunner/versions/VersionFetcher.java new file mode 100644 index 00000000..1a645be5 --- /dev/null +++ b/src/integrationTest/java/eu/xenit/gradle/testrunner/versions/VersionFetcher.java @@ -0,0 +1,54 @@ +package eu.xenit.gradle.testrunner.versions; + +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.type.CollectionType; +import java.io.IOException; +import java.io.UncheckedIOException; +import java.net.MalformedURLException; +import java.net.URL; +import java.util.List; +import java.util.Objects; +import java.util.function.Predicate; +import java.util.stream.Stream; +import org.gradle.util.GradleVersion; + +public class VersionFetcher { + private static List fetchAllVersions() { + ObjectMapper mapper = new ObjectMapper(); + + try { + CollectionType type = mapper.getTypeFactory().constructCollectionType(List.class, GradleVersionSpec.class); + return mapper.readerFor(type).readValue(new URL("https://services.gradle.org/versions/all")); + } catch (MalformedURLException | JsonMappingException | JsonParseException e) { + throw new RuntimeException(e); + } catch (IOException e) { + throw new UncheckedIOException(e); + } + } + + public static boolean isRelease(GradleVersionSpec versionSpec) { + GradleVersion gradleVersion = GradleVersion.version(versionSpec.getVersion()); + return !versionSpec.isSnapshot() && versionSpec.getRcFor().isEmpty() && Objects.equals(gradleVersion.getBaseVersion(), gradleVersion); + } + + public static boolean isBroken(GradleVersionSpec versionSpec) { + return versionSpec.isBroken(); + } + + public static Predicate greaterThan(String version) { + return versionSpec -> GradleVersion.version(versionSpec.getVersion()).compareTo(GradleVersion.version(version)) > 0; + } + + public static boolean firstPointRelease(GradleVersionSpec versionSpec) { + return GradleVersion.version(versionSpec.getVersion()).getBaseVersion().getVersion().endsWith(".0"); + } + + public static Stream fetchVersions() { + return fetchAllVersions() + .stream() + .filter(((Predicate) GradleVersionSpec::isBroken).negate()); + } + +} From a8a8b8a31cae11f26c675e98764a7dbe440a3740 Mon Sep 17 00:00:00 2001 From: Lars Vierbergen Date: Thu, 18 Aug 2022 09:40:47 +0200 Subject: [PATCH 2/3] Move code to split up a list of versions into series --- .../testrunner/AbstractIntegrationTest.java | 50 +++++++------------ .../versions/GradleVersionSeries.java | 48 ++++++++++++++++++ .../versions/GradleVersionSpec.java | 40 +++++++++++++++ .../testrunner/versions/VersionFetcher.java | 27 ++++++---- 4 files changed, 123 insertions(+), 42 deletions(-) create mode 100644 src/integrationTest/java/eu/xenit/gradle/testrunner/versions/GradleVersionSeries.java diff --git a/src/integrationTest/java/eu/xenit/gradle/testrunner/AbstractIntegrationTest.java b/src/integrationTest/java/eu/xenit/gradle/testrunner/AbstractIntegrationTest.java index a134c983..04cd4040 100644 --- a/src/integrationTest/java/eu/xenit/gradle/testrunner/AbstractIntegrationTest.java +++ b/src/integrationTest/java/eu/xenit/gradle/testrunner/AbstractIntegrationTest.java @@ -3,6 +3,7 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; +import eu.xenit.gradle.testrunner.versions.GradleVersionSeries; import eu.xenit.gradle.testrunner.versions.GradleVersionSpec; import eu.xenit.gradle.testrunner.versions.VersionFetcher; import java.io.File; @@ -20,6 +21,7 @@ import java.util.Objects; import java.util.Set; import java.util.stream.Collectors; +import java.util.stream.Stream; import org.apache.commons.io.FileUtils; import org.gradle.testkit.runner.BuildResult; import org.gradle.testkit.runner.GradleRunner; @@ -51,44 +53,28 @@ public static List testData() { } boolean majorsOnly = Boolean.getBoolean("eu.xenit.gradle.integration.majorsOnly"); - Comparator byVersionNumber = Comparator.comparing(versionSpec -> GradleVersion.version(versionSpec.getVersion())); - List fetchedVersions = VersionFetcher.fetchVersions() - .filter(VersionFetcher::isRelease) - .filter(VersionFetcher.greaterThan("5.6")) - .sorted(byVersionNumber) - .collect(Collectors.toList()); - - Map> versionsByMinor = new HashMap<>(); - - for (GradleVersionSpec versionSpec : fetchedVersions) { - String[] versionParts = GradleVersion.version(versionSpec.getVersion()).getBaseVersion().getVersion().split("\\."); - String versionKey = majorsOnly?versionParts[0]:(versionParts[0]+"."+versionParts[1]); - if(versionsByMinor.containsKey(versionKey)) { - versionsByMinor.get(versionKey).add(versionSpec); - } else { - versionsByMinor.put(versionKey, new ArrayList<>(Collections.singletonList(versionSpec))); - if(majorsOnly) { - versionsByMinor.put(versionKey + "-lowest", Collections.singletonList(versionSpec)); - } - } - } - - - List versionsToBuild = versionsByMinor.values() + List versionsToBuild = VersionFetcher.fetchVersionSeries() + // Only release versions >= 5.6 + .map(series -> series.filter(VersionFetcher::isRelease) + .filter(VersionFetcher.greaterThanOrEqual("5.6"))) + .filter(series -> !series.isEmpty()) + // When selecting only majors, select the series with only the major version component + .filter(series -> !majorsOnly || series.getSeriesPriority() == 1) + // For series with only the major version component, select the first and last version, for series with the minor version component, only select the last version + .flatMap(series -> series.getSeriesPriority() == 1 ? Stream.of(series.getLowestVersion(), series.getHighestVersion()): Stream.of( + series.getHighestVersion())) + // Collect to a set to deduplicate versions + .collect(Collectors.toSet()) .stream() - .map(versions -> versions.stream() - // Find latest patch version - .sorted(byVersionNumber.reversed()) - .findFirst() - .orElse(null) - ) - .filter(Objects::nonNull) - .sorted(byVersionNumber) + // Re-sort by version number + .sorted(GradleVersionSpec.BY_VERSION_NUMBER) + // Convert to parameter for junit .map(GradleVersionSpec::getVersion) .map(version -> new String[]{version}) .collect(Collectors.toList()); List slicedVersions = slice(versionsToBuild); + System.out.println(slicedVersions.stream() .map(i -> i[0]) .collect(Collectors.joining(", ", "Running test on versions: ", ""))); diff --git a/src/integrationTest/java/eu/xenit/gradle/testrunner/versions/GradleVersionSeries.java b/src/integrationTest/java/eu/xenit/gradle/testrunner/versions/GradleVersionSeries.java new file mode 100644 index 00000000..36eac77a --- /dev/null +++ b/src/integrationTest/java/eu/xenit/gradle/testrunner/versions/GradleVersionSeries.java @@ -0,0 +1,48 @@ +package eu.xenit.gradle.testrunner.versions; + +import java.util.Collection; +import java.util.Set; +import java.util.function.Predicate; +import java.util.stream.Collectors; + +public class GradleVersionSeries { + private final String series; + private final Set versionSpecs; + + public GradleVersionSeries(String series, Set versionSpecs) { + this.series = series; + this.versionSpecs = versionSpecs; + } + + public static GradleVersionSeries extract(String series, Collection versionSpecs) { + Set extractedVersions = versionSpecs.stream() + .filter(spec -> spec.getVersionSeries().contains(series)) + .collect(Collectors.toSet()); + return new GradleVersionSeries(series, extractedVersions); + } + + public int getSeriesPriority() { + return series.split("\\.").length; + } + + public GradleVersionSpec getLowestVersion() { + return versionSpecs.stream() + .min(GradleVersionSpec.BY_VERSION_NUMBER) + .orElse(null); + } + + public GradleVersionSpec getHighestVersion() { + return versionSpecs.stream() + .max(GradleVersionSpec.BY_VERSION_NUMBER) + .orElse(null); + } + + public GradleVersionSeries filter(Predicate predicate) { + return new GradleVersionSeries(series, versionSpecs.stream().filter(predicate).collect(Collectors.toSet())); + } + + public boolean isEmpty() { + return versionSpecs.isEmpty(); + } + +} diff --git a/src/integrationTest/java/eu/xenit/gradle/testrunner/versions/GradleVersionSpec.java b/src/integrationTest/java/eu/xenit/gradle/testrunner/versions/GradleVersionSpec.java index 2c674262..660ab734 100644 --- a/src/integrationTest/java/eu/xenit/gradle/testrunner/versions/GradleVersionSpec.java +++ b/src/integrationTest/java/eu/xenit/gradle/testrunner/versions/GradleVersionSpec.java @@ -1,11 +1,17 @@ package eu.xenit.gradle.testrunner.versions; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import java.util.Collections; import java.util.Comparator; +import java.util.HashSet; +import java.util.Objects; +import java.util.Set; import org.gradle.util.GradleVersion; @JsonIgnoreProperties(ignoreUnknown = true) public class GradleVersionSpec { + public static final Comparator BY_VERSION_NUMBER = Comparator.comparing(versionSpec -> GradleVersion.version(versionSpec.getVersion())); + private String version; private boolean snapshot; private boolean broken; @@ -15,6 +21,22 @@ public String getVersion() { return version; } + public Set getVersionSeries() { + String[] parts = GradleVersion.version(version).getBaseVersion().getVersion().split("\\."); + + Set series = new HashSet<>(); + + for (int i = 0; i < parts.length; i++) { + String serie = ""; + for (int j = 0; j <= i; j++) { + serie+=parts[j]+"."; + } + series.add(serie.substring(0, Math.max(serie.length()-1, 0))); + } + + return Collections.unmodifiableSet(series); + } + public void setVersion(String version) { this.version = version; } @@ -42,4 +64,22 @@ public String getRcFor() { public void setRcFor(String rcFor) { this.rcFor = rcFor; } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + GradleVersionSpec that = (GradleVersionSpec) o; + return snapshot == that.snapshot && broken == that.broken && version.equals(that.version) && rcFor.equals( + that.rcFor); + } + + @Override + public int hashCode() { + return Objects.hash(version, snapshot, broken, rcFor); + } } diff --git a/src/integrationTest/java/eu/xenit/gradle/testrunner/versions/VersionFetcher.java b/src/integrationTest/java/eu/xenit/gradle/testrunner/versions/VersionFetcher.java index 1a645be5..110bad87 100644 --- a/src/integrationTest/java/eu/xenit/gradle/testrunner/versions/VersionFetcher.java +++ b/src/integrationTest/java/eu/xenit/gradle/testrunner/versions/VersionFetcher.java @@ -8,9 +8,12 @@ import java.io.UncheckedIOException; import java.net.MalformedURLException; import java.net.URL; +import java.util.HashSet; import java.util.List; import java.util.Objects; +import java.util.Set; import java.util.function.Predicate; +import java.util.stream.Collectors; import java.util.stream.Stream; import org.gradle.util.GradleVersion; @@ -33,16 +36,8 @@ public static boolean isRelease(GradleVersionSpec versionSpec) { return !versionSpec.isSnapshot() && versionSpec.getRcFor().isEmpty() && Objects.equals(gradleVersion.getBaseVersion(), gradleVersion); } - public static boolean isBroken(GradleVersionSpec versionSpec) { - return versionSpec.isBroken(); - } - - public static Predicate greaterThan(String version) { - return versionSpec -> GradleVersion.version(versionSpec.getVersion()).compareTo(GradleVersion.version(version)) > 0; - } - - public static boolean firstPointRelease(GradleVersionSpec versionSpec) { - return GradleVersion.version(versionSpec.getVersion()).getBaseVersion().getVersion().endsWith(".0"); + public static Predicate greaterThanOrEqual(String version) { + return versionSpec -> GradleVersion.version(versionSpec.getVersion()).compareTo(GradleVersion.version(version)) >= 0; } public static Stream fetchVersions() { @@ -51,4 +46,16 @@ public static Stream fetchVersions() { .filter(((Predicate) GradleVersionSpec::isBroken).negate()); } + public static Stream fetchVersionSeries() { + List versions = fetchVersions().collect(Collectors.toList()); + Set versionSeries = new HashSet<>(); + for (GradleVersionSpec version : versions) { + versionSeries.addAll(version.getVersionSeries()); + } + + return versionSeries.stream() + .map(series -> GradleVersionSeries.extract(series, versions)) + .filter(series -> series.getSeriesPriority() <= 2); + } + } From 28749d7b2fb38bc0521aa4e62f6dd75f37df7d96 Mon Sep 17 00:00:00 2001 From: Lars Vierbergen Date: Thu, 18 Aug 2022 10:05:12 +0200 Subject: [PATCH 3/3] Add integrationTestScope to select which Gradle versions get tested against --- .github/workflows/ci.yml | 10 ++++---- appveyor.yml | 2 +- build.gradle | 23 +++++++------------ .../testrunner/AbstractIntegrationTest.java | 10 ++++---- .../versions/GradleVersionSeries.java | 3 +++ .../versions/GradleVersionSpec.java | 1 + .../testrunner/versions/VersionFetcher.java | 3 +-- 7 files changed, 23 insertions(+), 29 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 936cd1cd..b606c249 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -12,8 +12,6 @@ jobs: build: name: "build" runs-on: ubuntu-latest - env: - TEST_GRADLE_VERSION: 6.7 steps: - uses: actions/checkout@v2 with: @@ -24,7 +22,7 @@ jobs: - name: Pull docker images run: 'parallel docker pull -- xenit/alfresco-repository-skeleton:6.0 alfresco/alfresco-content-repository-community:6.0.7-ga tomcat:7-jre8 hello-world alpine:edge' - name: Check - run: ./gradlew check -PintegrationTestGradleVersions=$TEST_GRADLE_VERSION + run: ./gradlew check -PintegrationTestScope=0 - name: Upload reports if: ${{ failure() }} uses: actions/upload-artifact@v2 @@ -36,13 +34,13 @@ jobs: env: SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} GITHUB_TOKEN: ${{ github.token }} - run: ./gradlew sonarqube -Dsonar.projectKey=xenit-eu_alfresco-docker-gradle-plugin -Dsonar.organization=xenit-eu -Dsonar.host.url=https://sonarcloud.io -PintegrationTestGradleVersions=$TEST_GRADLE_VERSION + run: ./gradlew sonarqube -Dsonar.projectKey=xenit-eu_alfresco-docker-gradle-plugin -Dsonar.organization=xenit-eu -Dsonar.host.url=https://sonarcloud.io -PintegrationTestScope=0 - name: Publish if: ${{ startsWith(github.ref, 'refs/tags/') }} env: GRADLE_PUBLISH_KEY: ${{ secrets.GRADLE_PLUGINS_PUBLISH_KEY }} GRADLE_PUBLISH_SECRET: ${{ secrets.GRADLE_PLUGINS_PUBLISH_SECRET }} - run: ./gradlew check -PintegrationTestMajorsOnly=true publishPlugins -Pgradle.publish.key=$GRADLE_PUBLISH_KEY -Pgradle.publish.secret=$GRADLE_PUBLISH_SECRET + run: ./gradlew publishPlugins -Pgradle.publish.key=$GRADLE_PUBLISH_KEY -Pgradle.publish.secret=$GRADLE_PUBLISH_SECRET integration-test: name: "integration-test (slice=${{ matrix.slice }})" runs-on: ubuntu-latest @@ -64,7 +62,7 @@ jobs: - name: Pull docker images run: 'parallel docker pull -- alfresco/alfresco-content-repository-community:6.0.7-ga tomcat:7-jre8 hello-world alpine:edge' - name: Check - run: ./gradlew check -PintegrationTestSlice.index=${{ matrix.slice }} -PintegrationTestSlice.total=5 + run: ./gradlew check -PintegrationTestSlice.index=${{ matrix.slice }} -PintegrationTestSlice.total=5 -PintegrationTestScope=2 - name: Upload reports if: ${{ failure() }} uses: actions/upload-artifact@v2 diff --git a/appveyor.yml b/appveyor.yml index ec56fe1c..e6f519e6 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -18,4 +18,4 @@ install: build_script: - cmd: gradlew assemble test_script: - - cmd: gradlew check -i -PintegrationTestGradleVersions=6.4 + - cmd: gradlew check -i -PintegrationTestScope=0 diff --git a/build.gradle b/build.gradle index 20e86082..c31be086 100644 --- a/build.gradle +++ b/build.gradle @@ -168,21 +168,14 @@ import org.gradle.util.GradleVersion task integrationTest(type: Test, group: "verification") { useJUnit() - if (project.hasProperty("integrationTestGradleVersions")) { - // This is used for sharding integration tests across different gradle versions - // to avoid a timeout on travis because the total build takes too long. - // See also the .travis.yml file - project.property("integrationTestGradleVersions").tokenize(",").forEach({ version -> - // The versions specified in `integrationTestGradleVersions` are major.minor. - // We only want it to match those, and eventual patches to those versions. - // In particular, we want 4.1 to match 4.1.2, but not 4.10. - // Since there is only one test parameter for every version, either the first - // pattern matches major.minor, or the second pattern matches major.minor.patch - filter.includeTestsMatching("*[Gradle v${version}]") - filter.includeTestsMatching("*[Gradle v${version}.*]") - }) - } - systemProperty "eu.xenit.gradle.integration.majorsOnly", project.findProperty("integrationTestMajorsOnly") ?: "false" + /** + * integrationTestScope selects which Gradle versions get tested against + * A scope of 0 only tests the earliest and latest version and gives quick feedback + * A scope of 1 additionally tests the earliest and latest version of every major release + * A scope of 2 additionally tests the latest version of every minor release + * A scope of 3 tests all patch releases" + */ + systemProperty "eu.xenit.gradle.integration.scope", project.findProperty("integrationTestScope") ?: (ci.isCi()?"2":"0") systemProperty "eu.xenit.gradle.integration.slice.index", project.findProperty("integrationTestSlice.index") ?: "0" systemProperty "eu.xenit.gradle.integration.slice.total", project.findProperty("integrationTestSlice.total") ?: "1" doFirst { diff --git a/src/integrationTest/java/eu/xenit/gradle/testrunner/AbstractIntegrationTest.java b/src/integrationTest/java/eu/xenit/gradle/testrunner/AbstractIntegrationTest.java index 04cd4040..2d49ed41 100644 --- a/src/integrationTest/java/eu/xenit/gradle/testrunner/AbstractIntegrationTest.java +++ b/src/integrationTest/java/eu/xenit/gradle/testrunner/AbstractIntegrationTest.java @@ -52,16 +52,16 @@ public static List testData() { }); } - boolean majorsOnly = Boolean.getBoolean("eu.xenit.gradle.integration.majorsOnly"); + int scope = Integer.parseUnsignedInt(System.getProperty("eu.xenit.gradle.integration.scope", "2")); List versionsToBuild = VersionFetcher.fetchVersionSeries() // Only release versions >= 5.6 .map(series -> series.filter(VersionFetcher::isRelease) .filter(VersionFetcher.greaterThanOrEqual("5.6"))) .filter(series -> !series.isEmpty()) - // When selecting only majors, select the series with only the major version component - .filter(series -> !majorsOnly || series.getSeriesPriority() == 1) - // For series with only the major version component, select the first and last version, for series with the minor version component, only select the last version - .flatMap(series -> series.getSeriesPriority() == 1 ? Stream.of(series.getLowestVersion(), series.getHighestVersion()): Stream.of( + // Select only the series within a certain scope + .filter(series -> series.getSeriesPriority() <= scope) + // For series with none, or only the major version component, select the first and last version, for series with the minor version component, only select the last version + .flatMap(series -> series.getSeriesPriority() <= 1 ? Stream.of(series.getLowestVersion(), series.getHighestVersion()): Stream.of( series.getHighestVersion())) // Collect to a set to deduplicate versions .collect(Collectors.toSet()) diff --git a/src/integrationTest/java/eu/xenit/gradle/testrunner/versions/GradleVersionSeries.java b/src/integrationTest/java/eu/xenit/gradle/testrunner/versions/GradleVersionSeries.java index 36eac77a..fabb2744 100644 --- a/src/integrationTest/java/eu/xenit/gradle/testrunner/versions/GradleVersionSeries.java +++ b/src/integrationTest/java/eu/xenit/gradle/testrunner/versions/GradleVersionSeries.java @@ -22,6 +22,9 @@ public static GradleVersionSeries extract(String series, Collection getVersionSeries() { } series.add(serie.substring(0, Math.max(serie.length()-1, 0))); } + series.add(""); return Collections.unmodifiableSet(series); } diff --git a/src/integrationTest/java/eu/xenit/gradle/testrunner/versions/VersionFetcher.java b/src/integrationTest/java/eu/xenit/gradle/testrunner/versions/VersionFetcher.java index 110bad87..c02920ec 100644 --- a/src/integrationTest/java/eu/xenit/gradle/testrunner/versions/VersionFetcher.java +++ b/src/integrationTest/java/eu/xenit/gradle/testrunner/versions/VersionFetcher.java @@ -54,8 +54,7 @@ public static Stream fetchVersionSeries() { } return versionSeries.stream() - .map(series -> GradleVersionSeries.extract(series, versions)) - .filter(series -> series.getSeriesPriority() <= 2); + .map(series -> GradleVersionSeries.extract(series, versions)); } }