Skip to content

Commit

Permalink
JPERF-941: Start testing the release task
Browse files Browse the repository at this point in the history
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.
```
  • Loading branch information
dagguh committed Jan 26, 2023
1 parent df6f68c commit 3394c75
Show file tree
Hide file tree
Showing 3 changed files with 139 additions and 90 deletions.
Original file line number Diff line number Diff line change
@@ -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()
}
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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(
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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)
}
}

0 comments on commit 3394c75

Please sign in to comment.