Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
fscarponi committed Mar 6, 2024
1 parent 97598cf commit 8009ca7
Show file tree
Hide file tree
Showing 4 changed files with 108 additions and 50 deletions.
55 changes: 42 additions & 13 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,37 +5,66 @@ on:
branches: [ fabrizio.scarponi/e2e-test ]

jobs:
run-e2e-tests:
gradle-e2e-tests:
continue-on-error: true
strategy:
matrix:
os: [ ubuntu-latest, macos-latest, windows-latest ]
# gradle-versions: [ '5.6.4', '6.9.2', '7.6.4', '8.6', 'latest' ]
gradle-versions: [ '6.9.2', '8.6' ]
name: Gradle ${{ matrix.gradle-versions }} on ${{ matrix.os }}
# gradle-versions: [ '5.6.4', '6.9.2', '7.6.4', '8.6', 'latest' ]
gradle-version: [ '5.6.4', '6.9.2', '8.6' ]
name: Gradle ${{ matrix.gradle-version }} on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
with:
submodules: true
- uses: gradle/gradle-build-action@v2
- name: Set up JDK 17
uses: actions/setup-java@v3
- name: Set up JDK 11
uses: actions/setup-java@v4
with:
java-version: |
8
17
java-version: 11
distribution: 'temurin'
- name: Run Gradle tests
id: test
env:
KMP: true
GRADLE_VERSION: ${{ matrix.gradle-versions }}
GRADLE_VERSION: ${{ matrix.gradle-version }}
GRADLE_ENTERPRISE_KEY: ${{ secrets.GRADLE_ENTERPRISE_KEY }}
run: ./gradlew :plugin:test
JDK_VERSION: ${{matrix.jdk-version}}
run: ./gradlew :plugin:test --tests E2ETests.testGradleProjects
- name: Upload test result
if: steps.test.outcome == 'failure'
uses: actions/upload-artifact@v4
with:
name: testResult-${{ matrix.os }}-${{ matrix.gradle-versions }}
path: /home/runner/work/package-search-intellij-plugin/package-search-intellij-plugin/plugin/build/testData
name: testResult-${{ matrix.os }}-${{ matrix.gradle-version }}
path: /home/runner/work/package-search-intellij-plugin/package-search-intellij-plugin/plugin/build/testData
maven-e2e-tests:
continue-on-error: true
strategy:
matrix:
os: [ ubuntu-latest, macos-latest, windows-latest ]
name: Maven on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
with:
submodules: true
- uses: gradle/gradle-build-action@v2
- name: Set up JDK 11
uses: actions/setup-java@v4
with:
java-version: 11
distribution: 'temurin'
- name: Run Gradle tests
id: test
env:
KMP: true
GRADLE_ENTERPRISE_KEY: ${{ secrets.GRADLE_ENTERPRISE_KEY }}
JDK_VERSION: ${{matrix.jdk-version}}
run: ./gradlew :plugin:test --tests E2ETests.testMavenProjects
- name: Upload test result
if: steps.test.outcome == 'failure'
uses: actions/upload-artifact@v4
with:
name: testResult-${{ matrix.os }}-${{ matrix.gradle-version }}
path: /home/runner/work/package-search-intellij-plugin/package-search-intellij-plugin/plugin/build/testData
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import kotlinx.coroutines.test.runTest
import kotlinx.serialization.json.Json
import kotlinx.serialization.json.decodeFromStream
import org.junit.jupiter.api.AfterAll
import org.junit.jupiter.api.Assumptions
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.TestInstance
import org.junit.jupiter.api.extension.ExtendWith
Expand All @@ -33,7 +34,7 @@ import org.junit.jupiter.params.provider.MethodSource

@TestInstance(TestInstance.Lifecycle.PER_CLASS)
@ExtendWith(JUnit5StarterAssistant::class)
class E2ETests {
class GradleE2ETests {

private fun getProjects() =
getResourceAbsolutePath("/projects/")
Expand All @@ -44,10 +45,11 @@ class E2ETests {
?: error("Unable to list project files.")

@Test
fun `pre test validation`() {
fun `test configuration validation`() {
assertNotNull(
System.getenv("PKGS_PLUGIN_ARTIFACT_FILE"),
"environment variable PKGS_PLUGIN_ARTIFACT_FILE is not set for the test, should be set to the path of the plugin artifact file"
"environment variable PKGS_PLUGIN_ARTIFACT_FILE is not set for the test, " +
"should be set to the path of the plugin artifact file"
)
assertNotNull(
System.getenv("PKGS_PLUGIN_ID"),
Expand Down Expand Up @@ -78,30 +80,22 @@ class E2ETests {
.forEach { it.takeIf { it.isDirectory() }?.deleteRecursively() }
}

///split 2 tests 1 for gradle project and 1 for maven (update matrixs and split jobs)
@ParameterizedTest
@MethodSource("getProjects")
fun `verify PKGS Modules`(projectName: String) = runTest(timeout = 30.minutes) {
Assumptions.assumeTrue(assertGradleCompatibility())

//project setup and extraction
val projectZip = getResourceAbsolutePath("/projects/$projectName.zip")
?: error("Project file not found: $projectName.zip")

projectZip.extractInto(outputDir = PKGS_TEST_DATA_OUTPUT_DIR)
val projectDir = PKGS_TEST_DATA_OUTPUT_DIR.resolve(projectZip.nameWithoutExtension)

val patchGradleVersion = System.getenv("GRADLE_VERSION")
// remove comment override gradle configuration also if no env var is set
//?: patchGradleVersion("7.6.4", projectDir) //[ '5.6.4', '6.9.2', '7.6.4', '8.6', 'latest' ]

patchGradleVersion?.let {
Log.warn("patching project's gradle version to $it")
val pachedGradleFile = patchGradleVersion(it, projectDir)
// copy patched file for manual check
// NOTE: ci/cd will upload all files (non dir) in PKGS_TEST_DATA_OUTPUT_DIR as artifact
pachedGradleFile?.copyTo(
target = PKGS_TEST_DATA_OUTPUT_DIR.resolve("patched-gradle-wrapper.properties"),
overwrite = true
)
}
val projectDir = PKGS_TEST_DATA_OUTPUT_DIR.resolve(projectZip.nameWithoutExtension)
val gradleVersionToSet = System.getenv("GRADLE_VERSION") ?: "8.6"
patchGradleVersion(gradleVersionToSet, projectDir)

//IDE context setup
val testContext = buildIdeContext(projectDir)

val dumpPkgsDataChain = CommandChain()
Expand All @@ -114,6 +108,12 @@ class E2ETests {
launchName = DumpPackageSearchModules.DUMP_NAME
).await()

//result validation
validateResult(projectName)

}

private fun validateResult(projectName: String) {
val outputResultFile = PKGS_TEST_DATA_OUTPUT_DIR.resolve("modules.json")

assert(outputResultFile.isRegularFile()) {
Expand Down Expand Up @@ -170,28 +170,44 @@ class E2ETests {
validateModule(value, it)
}
}

}

private fun patchGradleVersion(gradleVersion: String, projectDir: Path): Path? {
val gradleProperties = projectDir.resolve("gradle/wrapper/gradle-wrapper.properties")
if (!gradleProperties.isRegularFile()) return null
gradleProperties.writeLines(
gradleProperties.readLines()
.map { line ->
when {
line.startsWith("distributionUrl=") -> {
"distributionUrl=https\\://services.gradle.org/distributions/gradle-$gradleVersion-bin.zip"
}

else -> {
line
}
}


private fun assertGradleCompatibility(): Boolean {
val gradleVersion = System.getenv("GRADLE_VERSION")
val javaHome: String? = System.getenv("JAVA_HOME")
TODO()
// JavaHome compatible with GradleVersion ?


}

private fun patchGradleVersion(gradleVersion: String, projectDir: Path) {
val gradleProperties = projectDir.resolve("gradle/wrapper/gradle-wrapper.properties")
if (!gradleProperties.isRegularFile()) error("unable to find gradle wrapper properties file")
Log.warn("patching project's gradle version to $gradleVersion")
gradleProperties.writeLines(
gradleProperties.readLines()
.map { line ->
when {
line.startsWith("distributionUrl=") -> {
"distributionUrl=https\\://services.gradle.org/distributions/gradle-$gradleVersion-bin.zip"
}

else -> {
line
}
}
)
return gradleProperties
}
}
)
// copy patched file for manual check
// NOTE: ci/cd will upload all files (non dir) in PKGS_TEST_DATA_OUTPUT_DIR as artifact
gradleProperties.copyTo(
target = PKGS_TEST_DATA_OUTPUT_DIR.resolve("patched-gradle-wrapper.properties"),
overwrite = true
)
}


Expand Down
Empty file.
13 changes: 13 additions & 0 deletions plugin/src/test/kotlin/Utils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import com.intellij.ide.starter.project.LocalProjectInfo
import com.intellij.ide.starter.project.TestCaseTemplate
import com.intellij.ide.starter.runner.CurrentTestMethod
import com.intellij.ide.starter.runner.Starter
import com.intellij.openapi.util.io.toNioPathOrNull
import com.intellij.tools.ide.performanceTesting.commands.CommandChain
import com.intellij.tools.ide.performanceTesting.commands.SdkObject
import com.jetbrains.packagesearch.plugin.tests.dumps.DumpPackageSearchModules
Expand All @@ -22,13 +23,25 @@ internal fun buildIdeContext(projectPath: Path): IDETestContext {
val testCase = object : TestCaseTemplate(IdeProductProvider.IC) {
val project = withProject(LocalProjectInfo(projectPath))
}
val javaVersion = System.getenv("JAVA_VERSION") ?: error("JAVA_VERSION is not set")
val javaHome = System.getenv("JAVA_HOME") ?: error("JAVA_HOME is not set")

val sdk = javaHome.toNioPathOrNull()?.let {
SdkObject(
"temurin-$javaVersion",
"JavaSDK",
it
)
} ?: error("Could not determine SDK properties")

return Starter.newContext(
CurrentTestMethod.hyphenateWithClass(),
testCase.project.useEAP(),
)
.setSharedIndexesDownload(true)
.addProjectToTrustedLocations()
.disableFusSendingOnIdeClose()
.setupSdk(sdk) // <component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" project-jdk-name="..." project-jdk-type="JavaSDK" />
.also {
it.pluginConfigurator
.installPluginFromPath(
Expand Down

0 comments on commit 8009ca7

Please sign in to comment.