-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from Liftric/feature/wait-for-deployment
Feature: wait for deployment
- Loading branch information
Showing
29 changed files
with
1,708 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
99 changes: 99 additions & 0 deletions
99
...ionTest/kotlin/com/liftric/octopusdeploy/task/UploadPackageTaskWithWaitIntegrationTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
package com.liftric.octopusdeploy.task | ||
|
||
import com.liftric.octopusdeploy.apiKey | ||
import com.liftric.octopusdeploy.getPackageResponse | ||
import com.liftric.octopusdeploy.serverUrl | ||
import junit.framework.TestCase.assertEquals | ||
import junit.framework.TestCase.assertNotNull | ||
import org.gradle.testkit.runner.GradleRunner | ||
import org.gradle.testkit.runner.TaskOutcome | ||
import org.junit.Rule | ||
import org.junit.Test | ||
import org.junit.rules.TemporaryFolder | ||
import kotlin.random.Random | ||
|
||
class UploadPackageTaskWithWaitIntegrationTest { | ||
@get:Rule | ||
val testProjectDir = TemporaryFolder() | ||
|
||
@Test | ||
fun testExecute() { | ||
val major = Random.Default.nextInt(0, 100) | ||
val minor = Random.Default.nextInt(0, 100) | ||
val micro = Random.Default.nextInt(0, 100) | ||
println(testProjectDir.root.absolutePath) | ||
setupBuild(major, minor, micro) | ||
|
||
val result = GradleRunner.create() | ||
.forwardOutput() | ||
.withProjectDir(testProjectDir.root) | ||
.withArguments("build", "uploadPackage") | ||
.withPluginClasspath() | ||
.build() | ||
println(result.output) | ||
assertEquals(TaskOutcome.SUCCESS, result.task(":uploadPackage")?.outcome) | ||
|
||
val packageItem = getPackageResponse() | ||
.items | ||
?.filter { | ||
it.version == "$major.$minor.$micro" | ||
} | ||
?.firstOrNull() | ||
assertNotNull(packageItem) | ||
assertEquals(".jar", packageItem?.fileExtension) | ||
|
||
val secondResult = GradleRunner.create() | ||
.forwardOutput() | ||
.withProjectDir(testProjectDir.root) | ||
.withArguments("build", "uploadPackage") | ||
.withPluginClasspath() | ||
.buildAndFail() | ||
println(secondResult.output) | ||
// override is not set | ||
assertEquals(TaskOutcome.FAILED, secondResult.task(":uploadPackage")?.outcome) | ||
} | ||
|
||
fun setupBuild(major: Int, minor: Int, micro: Int) { | ||
testProjectDir.newFile("build.gradle.kts").apply { | ||
writeText( | ||
""" | ||
import com.liftric.octopusdeploy.task.UploadPackageTask | ||
plugins { | ||
java | ||
id("com.liftric.octopus-deploy-plugin") | ||
} | ||
group = "com.liftric.test" | ||
version = "$major.$minor.$micro" | ||
tasks { | ||
withType<Jar> { | ||
archiveFileName.set( | ||
"${'$'}{archiveBaseName.get() | ||
.removeSuffix("-")}.${'$'}{archiveVersion.get()}.${'$'}{archiveExtension.get()}" | ||
) | ||
} | ||
withType<UploadPackageTask>{ | ||
waitForReleaseDeployments.set(true) | ||
waitTimeoutSeconds.set(1L) | ||
delayBetweenChecksSeconds.set(2L) | ||
httpLogLevel.set(okhttp3.logging.HttpLoggingInterceptor.Level.HEADERS) | ||
} | ||
} | ||
octopus { | ||
serverUrl.set("$serverUrl") | ||
apiKey.set("$apiKey") | ||
generateChangelogSinceLastTag = true | ||
val jar by tasks.existing(Jar::class) | ||
packageName.set(jar.get().archiveBaseName.get().removeSuffix("-")) | ||
version.set(jar.get().archiveVersion.get()) | ||
pushPackage.set(jar.get().archiveFile) | ||
} | ||
""" | ||
) | ||
} | ||
testProjectDir.root.setupGitRepoCopy() | ||
} | ||
} |
57 changes: 57 additions & 0 deletions
57
src/integrationTest/kotlin/com/liftric/octopusdeploy/task/sharedcopy.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package com.liftric.octopusdeploy.task | ||
|
||
import junit.framework.TestCase | ||
import junit.framework.TestCase.assertEquals | ||
import java.io.File | ||
|
||
/** | ||
* it didn't compile without this, no clue why this happened all of the sudden | ||
*/ | ||
fun File.setupGitRepoCopy() { | ||
println("setupGitRepo=${this.absolutePath}") | ||
try { | ||
verboseTestShell("git init .") | ||
verboseTestShell("git add .") | ||
verboseTestShell("git config user.email \"[email protected]\"") | ||
verboseTestShell("git config user.name \"Your Name\"") | ||
verboseTestShell("git commit -m \"initial commit\"") | ||
verboseTestShell("git tag first-one") | ||
verboseTestShell("touch secondfile") | ||
verboseTestShell("git add .") | ||
verboseTestShell("git commit -m \"second commit\"") | ||
verboseTestShell("git tag second-one") | ||
} catch (e: Exception) { | ||
println(e.message) | ||
e.printStackTrace() | ||
val (exitCode, inputText, errorText) = this.shell("ls -lah") | ||
println("exitCode=$exitCode") | ||
println("inputText=$inputText") | ||
println("errorText=$errorText") | ||
throw e | ||
} | ||
} | ||
|
||
private fun File.verboseTestShell(cmd: String) { | ||
println("verboseTestShell=$cmd") | ||
val (exitCode, inputText, errorText) = this.shell(cmd) | ||
println("verboseTestShell exitCode=$exitCode") | ||
println("verboseTestShell inputText=$inputText") | ||
println("verboseTestShell errorText=$errorText") | ||
exitCode mustBe 0 | ||
} | ||
|
||
infix fun Int.mustBe(expected: Int) { | ||
assertEquals(expected, this) | ||
} | ||
|
||
internal fun shell(cmd: String): ShellResult = File(".").shell(cmd) | ||
|
||
internal fun File.shell(cmd: String): ShellResult { | ||
val process = Runtime.getRuntime().exec(arrayOf("sh", "-c", cmd), emptyArray(), this) | ||
val exitCode = process.waitFor() | ||
val inputText = process.inputStream.bufferedReader().readText().trim() | ||
val errorText = process.errorStream.bufferedReader().readText().trim() | ||
return ShellResult(exitCode, inputText, errorText) | ||
} | ||
|
||
data class ShellResult(val exitCode: Int, val inputText: String, val errorText: String) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...n/com/liftric/octopusdeploy/api/Commit.kt → ...om/liftric/octopusdeploy/api/CommitCli.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.