From 3394c755e66f925f9f971c586628ad99c1a38d0c Mon Sep 17 00:00:00 2001 From: Maciej Kwidzinski Date: Wed, 25 Jan 2023 17:02:33 +0100 Subject: [PATCH] JPERF-941: Start testing the `release` task Now JPERF-941 actually reproduces with the axion symptoms: ``` * What went wrong: A problem was found with the configuration of task ':verifyRelease' (type 'VerifyReleaseTask'). - In plugin 'pl.allegro.tech.build.axion-release' type 'pl.allegro.tech.build.axion.release.VerifyReleaseTask' property 'versionConfig' is missing an input or output annotation. Reason: A property without annotation isn't considered during up-to-date checking. Possible solutions: 1. Add an input or output annotation. 2. Mark it as @Internal. Please refer to https://docs.gradle.org/7.6/userguide/validation_problems.html#missing_annotation for more details about this problem. ``` --- .../performance/tools/license/Fixtures.kt | 94 ++++++++++++++++++ .../performance/tools/license/PublishTest.kt | 98 ++----------------- .../performance/tools/license/ReleaseTest.kt | 37 +++++++ 3 files changed, 139 insertions(+), 90 deletions(-) create mode 100644 src/test/kotlin/com/atlassian/performance/tools/license/Fixtures.kt create mode 100644 src/test/kotlin/com/atlassian/performance/tools/license/ReleaseTest.kt diff --git a/src/test/kotlin/com/atlassian/performance/tools/license/Fixtures.kt b/src/test/kotlin/com/atlassian/performance/tools/license/Fixtures.kt new file mode 100644 index 0000000..cb27976 --- /dev/null +++ b/src/test/kotlin/com/atlassian/performance/tools/license/Fixtures.kt @@ -0,0 +1,94 @@ +package com.atlassian.performance.tools.license + +import org.eclipse.jgit.api.Git +import org.eclipse.jgit.transport.URIish +import org.junit.rules.TemporaryFolder +import java.io.File + +class Fixtures { + + class ProjectFixture( + val root: File, + val git: Git + ) + + internal fun configureProject( + projectName: String, + version: String + ): ProjectFixture { + val buildFolder = TemporaryFolder() + buildFolder.create() + val git = Git.init().setDirectory(buildFolder.root).call() + addInitialCommit(projectName, buildFolder, git) + git.tag().setName("release-$version-alpha").call() + addCode(buildFolder, git) + return ProjectFixture(buildFolder.root, git) + } + + private fun addInitialCommit( + projectName: String, + buildFolder: TemporaryFolder, + git: Git + ) { + buildFolder.newFile("build.gradle").writeText( + """ + plugins { + id 'com.atlassian.performance.tools.gradle-release' + id "org.jetbrains.kotlin.jvm" version "1.3.20" + } + dependencies { + compile group: 'org.jetbrains.kotlin', name: 'kotlin-stdlib-jdk8', version: '1.3.20' + } + """.trimIndent() + ) + buildFolder.newFile("settings.gradle").writeText( + """ + rootProject.name = "$projectName" + """.trimIndent() + ) + buildFolder.newFile(".gitignore").writeText( + """ + .gradle + build + """.trimIndent() + ) + git + .add() + .addFilepattern(".gitignore") + .addFilepattern("settings.gradle") + .addFilepattern("build.gradle") + .call() + git + .commit() + .setMessage("Initial commit") + .call() + } + + private fun addCode( + buildFolder: TemporaryFolder, + git: Git + ) { + val javaFolder = buildFolder.newFolder("src", "main", "kotlin") + File(javaFolder, "Hello.kt").writeText( + """ + class Hello { + } + """.trimIndent() + ) + git + .add() + .addFilepattern("src") + .call() + git + .commit() + .setMessage("Hello world") + .call() + } +} + +internal fun Git.addRemote(uri: URIish) { + remoteAdd() + .apply { setName("origin") } + .apply { setUri(uri) } + .call() +} \ No newline at end of file diff --git a/src/test/kotlin/com/atlassian/performance/tools/license/PublishTest.kt b/src/test/kotlin/com/atlassian/performance/tools/license/PublishTest.kt index 4973e6a..ad51c6d 100644 --- a/src/test/kotlin/com/atlassian/performance/tools/license/PublishTest.kt +++ b/src/test/kotlin/com/atlassian/performance/tools/license/PublishTest.kt @@ -19,12 +19,14 @@ class PublishTest { @Test fun shouldPublishModule() { - val projectName = "release-test" + val projectName = "publish-test" val version = "0.3.0" - val project = configureProject(projectName, version) + val project = Fixtures().configureProject(projectName, version) + val realisticLookingRemote = URIish("git@github.com:atlassian/jira-actions.git") // not actually pushed to + project.git.addRemote(realisticLookingRemote) val publishResult = GradleRunner.create() - .withProjectDir(project) + .withProjectDir(project.root) .withArguments("publishToMavenLocal", "--stacktrace") .withPluginClasspath() .forwardOutput() @@ -39,13 +41,13 @@ class PublishTest { val scm = extractScm(pomXml) assertThat(scm.getChildValue("url")) .`as`("SCM url in $pomXml") - .isEqualTo("https://github.com/atlassian/release-test") + .isEqualTo("https://github.com/atlassian/publish-test") assertThat(scm.getChildValue("connection")) .`as`("SCM connection in $pomXml") - .isEqualTo("scm:git:git@github.com:atlassian/release-test.git") + .isEqualTo("scm:git:git@github.com:atlassian/publish-test.git") assertThat(scm.getChildValue("developerConnection")) .`as`("SCM dev connection in $pomXml") - .isEqualTo("scm:git:git@github.com:atlassian/release-test.git") + .isEqualTo("scm:git:git@github.com:atlassian/publish-test.git") } private fun extractScm( @@ -61,90 +63,6 @@ class PublishTest { .single() } - private fun configureProject( - projectName: String, - version: String - ): File { - val buildFolder = TemporaryFolder() - buildFolder.create() - val git = Git.init().setDirectory(buildFolder.root).call() - addInitialCommit(projectName, buildFolder, git) - git.tag().setName("release-$version-alpha").call() - addCode(buildFolder, git) - addRemote(git) - return buildFolder.root - } - - private fun addInitialCommit( - projectName: String, - buildFolder: TemporaryFolder, - git: Git - ) { - buildFolder.newFile("build.gradle").writeText( - """ - plugins { - id 'com.atlassian.performance.tools.gradle-release' - id "org.jetbrains.kotlin.jvm" version "1.3.20" - } - dependencies { - compile group: 'org.jetbrains.kotlin', name: 'kotlin-stdlib-jdk8', version: '1.3.20' - } - """.trimIndent() - ) - buildFolder.newFile("settings.gradle").writeText( - """ - rootProject.name = "$projectName" - """.trimIndent() - ) - buildFolder.newFile(".gitignore").writeText( - """ - .gradle - build - """.trimIndent() - ) - git - .add() - .addFilepattern(".gitignore") - .addFilepattern("settings.gradle") - .addFilepattern("build.gradle") - .call() - git - .commit() - .setMessage("Initial commit") - .call() - } - - private fun addCode( - buildFolder: TemporaryFolder, - git: Git - ) { - val javaFolder = buildFolder.newFolder("src", "main", "kotlin") - File(javaFolder, "Hello.kt").writeText( - """ - class Hello { - } - """.trimIndent() - ) - git - .add() - .addFilepattern("src") - .call() - git - .commit() - .setMessage("Hello world") - .call() - } - - private fun addRemote( - git: Git - ) { - git - .remoteAdd() - .also { it.setName("origin") } - .also { it.setUri(URIish("git@github.com:atlassian/jira-actions.git")) } - .call() - } - private fun findPublishedPom( projectName: String, publishedVersion: String diff --git a/src/test/kotlin/com/atlassian/performance/tools/license/ReleaseTest.kt b/src/test/kotlin/com/atlassian/performance/tools/license/ReleaseTest.kt new file mode 100644 index 0000000..1d400ed --- /dev/null +++ b/src/test/kotlin/com/atlassian/performance/tools/license/ReleaseTest.kt @@ -0,0 +1,37 @@ +package com.atlassian.performance.tools.license + +import org.assertj.core.api.Assertions.assertThat +import org.eclipse.jgit.api.Git +import org.eclipse.jgit.transport.URIish +import org.gradle.testkit.runner.GradleRunner +import org.gradle.testkit.runner.TaskOutcome +import org.junit.Test +import org.junit.rules.TemporaryFolder + +class ReleaseTest { + + @Test + fun shouldReleaseModule() { + val projectName = "release-test" + val version = "1.2.4" + val project = Fixtures().configureProject(projectName, version) + val safelyPushableRemote = TemporaryFolder() + .also { it.create() } + .root + .also { Git.init().setDirectory(it) } + .let {URIish("file://${it.absolutePath}")} + project.git.addRemote(safelyPushableRemote) + + val releaseResult = GradleRunner.create() + .withProjectDir(project.root) + .withArguments("release", "--stacktrace") + .withPluginClasspath() + .forwardOutput() + .withDebug(true) + .build() + + val releaseTask = releaseResult.task(":release") + assertThat(releaseTask?.outcome) + .isEqualTo(TaskOutcome.SUCCESS) + } +}