Skip to content

Commit

Permalink
Add integrationTestScope to select which Gradle versions get tested a…
Browse files Browse the repository at this point in the history
…gainst
  • Loading branch information
vierbergenlars committed Aug 18, 2022
1 parent a8a8b8a commit 1b3d947
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 28 deletions.
10 changes: 4 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ jobs:
build:
name: "build"
runs-on: ubuntu-latest
env:
TEST_GRADLE_VERSION: 6.7
steps:
- uses: actions/checkout@v2
with:
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
23 changes: 8 additions & 15 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,16 +52,16 @@ public static List<String[]> testData() {
});
}

boolean majorsOnly = Boolean.getBoolean("eu.xenit.gradle.integration.majorsOnly");
int scope = Integer.parseUnsignedInt(System.getProperty("eu.xenit.gradle.integration.scope", "2"));
List<String[]> 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())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ public static GradleVersionSeries extract(String series, Collection<GradleVersio
}

public int getSeriesPriority() {
if(series.isEmpty()) {
return 0;
}
return series.split("\\.").length;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public Set<String> getVersionSeries() {
}
series.add(serie.substring(0, Math.max(serie.length()-1, 0)));
}
series.add("");

return Collections.unmodifiableSet(series);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,7 @@ public static Stream<GradleVersionSeries> fetchVersionSeries() {
}

return versionSeries.stream()
.map(series -> GradleVersionSeries.extract(series, versions))
.filter(series -> series.getSeriesPriority() <= 2);
.map(series -> GradleVersionSeries.extract(series, versions));
}

}

0 comments on commit 1b3d947

Please sign in to comment.