Skip to content

Commit

Permalink
Merge pull request #13 from Liftric/chore/update_dependencies
Browse files Browse the repository at this point in the history
refactor: use Property API for lazy configuration & update dependencies
  • Loading branch information
nvima authored Aug 15, 2024
2 parents 102d4d9 + b92fee9 commit 3ec7400
Show file tree
Hide file tree
Showing 30 changed files with 750 additions and 486 deletions.
18 changes: 17 additions & 1 deletion .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,24 @@ jobs:
# needed for FirstCommitHashTaskTest
fetch-depth: 0
- name: Cache
uses: gradle/gradle-build-action@v2
uses: gradle/[email protected]
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'temurin'
- name: Download and Install Octo CLI
run: |
wget https://github.com/OctopusDeploy/OctopusCLI/releases/download/v9.1.7/OctopusTools.9.1.7.linux-x64.tar.gz
mkdir -p $HOME/.local/bin
tar -xzf OctopusTools.9.1.7.linux-x64.tar.gz -C $HOME/.local/bin
echo "$HOME/.local/bin" >> $GITHUB_PATH
- name: Build
run: ./gradlew build
- name: Validate
run: ./gradlew check validatePlugins --continue
- name: Integration Test
run: |
octo --version
java -version
./gradlew integrationTest --no-daemon
2 changes: 1 addition & 1 deletion .github/workflows/publish.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
# needed for FirstCommitHashTaskTest
fetch-depth: 0
- name: Cache
uses: gradle/gradle-build-action@v2
uses: gradle/gradle-build-action@v2.4.2
- name: Build
run: ./gradlew build
- name: Validate
Expand Down
49 changes: 33 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@ Requirements:

# Usage
The plugin can be configured with the `octopus` DSL block:
```
```kotlin
plugins {
id("com.liftric.octopus-deploy-plugin") version "whatever"
}
[...]
// ...
octopus {
serverUrl.set("http://localhost:8080/")
apiKey.set("API-TESTTEST123TRESDTSDD")

generateChangelogSinceLastTag = true
generateChangelogSinceLastTag.set(true)

val jar by tasks.existing(Jar::class)
packageName.set(jar.get().archiveBaseName.get())
Expand All @@ -46,8 +46,8 @@ uploadBuildInformation | Uploads the created octopus build-information file.
uploadPackage | Uploads the package to octopus.
PromoteReleaseTask | Promotes octopus project from one environment to another

For normale use-cases, only `uploadBuildInformation` are `uploadPackage` are needed to call explicitly. Depending
task will be called implicitly by both as needed.
For normal use-cases, only `uploadBuildInformation` and `uploadPackage` are needed to call explicitly. Depending
tasks will be called implicitly by both as needed.

**Noteworthy**: The build-information can be uploaded before the package itself.
Useful when creating automatic releases and using the commits in the release notes in octopus.
Expand All @@ -56,7 +56,7 @@ Useful when creating automatic releases and using the commits in the release not
The PromoteReleaseTask has no default implementation and must be created explicitly:
```kotlin
import com.liftric.octopusdeploy.task.PromoteReleaseTask
[...]
// ...
tasks {
val devToDemo by creating(PromoteReleaseTask::class) {
projectName.set("example-project")
Expand All @@ -79,19 +79,19 @@ After the plugin is applied, the octopus extension is registered with the follow

Property | Description | default value
---|---|---
apiKey | Octopus deploy server API key (lazy gradle property)| -
serverUrl | Octopus deploy server URL (lazy gradle property)| -
apiKey | Octopus deploy server API key | -
serverUrl | Octopus deploy server URL | -
generateChangelogSinceLastTag | Enable to calculate the commits for the changelog when uploading build-information (needs git installed) | false
commitLinkBaseUrl | Prefix / Baseurl for the build-information commit urls | http://git.example.com/repo/commits/
outputDir | Output folder for files generated by the plugin | build/octopus
gitRoot | Directory to run the git helpers in. By default the projects root dir | project.rootDir
pushPackage | Target file (package) which will be uploaded to octopus | -
version | Package version (lazy gradle property)| -
packageName | Package name (lazy gradle property)| -
version | Package version | -
packageName | Package name | -
buildInformationOverwriteMode | octo build-information OverwriteMode | -
pushOverwriteMode | octo push OverwriteMode | -
buildInformationAddition | Customize the final octopus build-information before uploading | {}
gitlab() | Default `buildInformationAddition` implementation adding context from the CI environment for Gitlab CI. Also sets `commitLinkBaseUrl`. | not applied
gitlab | Default `buildInformationAddition` implementation adding context from the CI environment for Gitlab CI. Also sets `commitLinkBaseUrl`. | not applied
httpLogLevel | configures the http logging while using the Octopus API | `HttpLoggingInterceptor.Level.NONE`
issueTrackerName | When parsing issues the target issue tracker name is needed. Currently only `Jira` supported | **optional/none**
parseCommitsForJiraIssues | Enable Jira Issue parsing. This needs the changelog generation enabled to parse the commits there. | **optional/none**
Expand All @@ -102,13 +102,30 @@ useShortCommitHashes | Use short (7 char) commit hashes. | true
If no tag is found, the first commit in the history tree is used instead.

You can configure `serverUrl` and `apiKey` using a provider which enables configuring them on demand, not at configuration time:
```
```kotlin
apiKey.set(provider {
"API-TESTTEST123TRESDTSDD"
// read from file / vault / etc.
"API-TESTTEST123TRESDTSDD"
// read from file / vault / etc.
})
```

To customize the build information, use the `buildInformationAddition` block:
```kotlin
buildInformationAddition.set({
Id = "custom-id"
// Add other properties as needed
})

```

For GitLab CI integration, set the `gitlab` block:
```kotlin
gitlab {
Id = "custom-id"
// Add other properties as needed
}
```

### task specific configuration
Both the **PromoteReleaseTask** and **UploadPackageTask** provide support for waiting
for any deployment on octopus deploy and will block task finishing until all octopus deploy tasks are finished.
Expand All @@ -125,10 +142,10 @@ delayBetweenChecksSeconds | how long to delay between polls
initialWaitSeconds | initial delay before waitForReleaseDeployments logic starts | -

Example:
```
```kotlin
import com.liftric.octopusdeploy.task.PromoteReleaseTask
import com.liftric.octopusdeploy.task.UploadPackageTask
[...]
// ...
tasks {
val devToDemo by creating(PromoteReleaseTask::class) {
waitForReleaseDeployments.set(true)
Expand Down
31 changes: 14 additions & 17 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import org.jetbrains.kotlin.gradle.plugin.getKotlinPluginVersion
plugins {
`kotlin-dsl`
`maven-publish`
id("com.gradle.plugin-publish") version "0.18.0"
id("net.nemerosa.versioning") version "2.15.1"
id("com.avast.gradle.docker-compose") version "0.14.11"
id("com.gradle.plugin-publish") version "1.2.1"
id("net.nemerosa.versioning") version "3.1.0"
id("com.avast.gradle.docker-compose") version "0.17.7"
}

group = "com.liftric.octopusdeploy"
Expand Down Expand Up @@ -41,19 +41,19 @@ dependencies {
implementation(gradleApi())
implementation(kotlin("gradle-plugin"))
implementation(kotlin("stdlib-jdk8"))
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.5.2")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.8.1")

implementation("com.fasterxml.jackson.module:jackson-module-kotlin:2.13.0")
implementation("com.squareup.retrofit2:retrofit:2.9.0")
implementation("com.squareup.retrofit2:converter-jackson:2.9.0")
implementation("com.squareup.retrofit2:converter-scalars:2.9.0")
implementation("com.squareup.okhttp3:logging-interceptor:4.9.3")
implementation("com.fasterxml.jackson.module:jackson-module-kotlin:2.17.2")
implementation("com.squareup.retrofit2:retrofit:2.11.0")
implementation("com.squareup.retrofit2:converter-jackson:2.11.0")
implementation("com.squareup.retrofit2:converter-scalars:2.11.0")
implementation("com.squareup.okhttp3:logging-interceptor:4.12.0")

testImplementation(gradleTestKit())
testImplementation("junit:junit:4.13.2")
testImplementation("com.github.stefanbirkner:system-rules:1.19.0")
integrationTestImplementation("junit:junit:4.13.2")
integrationTestImplementation("org.apache.httpcomponents:httpclient:4.5.13")
integrationTestImplementation("org.apache.httpcomponents:httpclient:4.5.14")
}
java {
sourceCompatibility = JavaVersion.VERSION_1_8
Expand Down Expand Up @@ -131,25 +131,22 @@ publishing {
}
}
gradlePlugin {
website.set("https://github.com/Liftric/octopus-deploy-plugin")
vcsUrl.set("https://github.com/Liftric/octopus-deploy-plugin")
plugins {
create("OctopusDeployPlugin") {
id = "com.liftric.octopus-deploy-plugin"
displayName = "octopus-deploy-plugin"
implementationClass = "com.liftric.octopusdeploy.OctopusDeployPlugin"
description = "Common tasks for Octopus Deploy interaction, like package or build-information uploading"
tags.set(listOf("octopus", "deploy", "releases", "build-information", "upload", "packages"))
}
}
}
pluginBundle {
website = "https://github.com/Liftric/octopus-deploy-plugin"
vcsUrl = "https://github.com/Liftric/octopus-deploy-plugin"
description = "Common tasks for Octopus Deploy interaction, like package or build-information uploading"
tags = listOf("octopus", "deploy", "releases", "build-information", "upload", "packages")
}
dockerCompose {
useComposeFiles.set(listOf("docker-compose.yml"))
waitForTcpPorts.set(true)
captureContainersOutput.set(true)
captureContainersOutput.set(false)
stopContainers.set(true)
removeContainers.set(true)
buildBeforeUp.set(true)
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ services:
ACCEPT_EULA: Y
DB_CONNECTION_STRING: Server=db,1433;Database=OctopusDeploy;User=sa;Password=yourStrong(!)Password
ADMIN_USERNAME: admin
ADMIN_PASSWORD: testtest123
ADMIN_PASSWORD: testTEST123!
ADMIN_API_KEY: API-TESTTEST123TRESDTSDD
ports:
- "8080:8080"
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.1-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.9-all.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
package com.liftric.octopusdeploy.task

import com.liftric.octopusdeploy.apiKey
import com.liftric.octopusdeploy.getBuildInformationResponse
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 UploadBuildInformationOverwriteTaskIntegrationTest {
@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", "uploadBuildInformation")
.withPluginClasspath()
.build()
println(result.output)
assertEquals(TaskOutcome.SUCCESS, result.task(":uploadBuildInformation")?.outcome)
val buildInfoItem = getBuildInformationResponse()
.items
?.firstOrNull {
it.version == "$major.$minor.$micro"
}
assertNotNull(buildInfoItem)
assertEquals("Git", buildInfoItem?.vcsType)

val secondResult = GradleRunner.create()
.forwardOutput()
.withProjectDir(testProjectDir.root)
.withArguments("build", "uploadBuildInformation")
.withPluginClasspath()
.build()
println(secondResult.output)
assertEquals(TaskOutcome.SUCCESS, secondResult.task(":uploadBuildInformation")?.outcome)
}

fun setupBuild(major: Int, minor: Int, micro: Int) {
testProjectDir.newFile("build.gradle.kts").apply {
writeText(
"""
import com.liftric.octopusdeploy.api.OverwriteMode
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()}"
)
}
}
octopus {
serverUrl.set("$serverUrl")
apiKey.set("$apiKey")
generateChangelogSinceLastTag.set(true)
buildInformationOverwriteMode.set(OverwriteMode.OverwriteExisting)
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()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ octopus {
serverUrl.set("$serverUrl")
apiKey.set("$apiKey")
generateChangelogSinceLastTag = true
generateChangelogSinceLastTag.set(true)
val jar by tasks.existing(Jar::class)
packageName.set(jar.get().archiveBaseName.get().removeSuffix("-"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ octopus {
serverUrl.set("$serverUrl")
apiKey.set("$apiKey")
generateChangelogSinceLastTag = true
generateChangelogSinceLastTag.set(true)
val jar by tasks.existing(Jar::class)
packageName.set(jar.get().archiveBaseName.get().removeSuffix("-"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ octopus {
serverUrl.set("$serverUrl")
apiKey.set("$apiKey")
generateChangelogSinceLastTag = true
generateChangelogSinceLastTag.set(true)
val jar by tasks.existing(Jar::class)
packageName.set(jar.get().archiveBaseName.get().removeSuffix("-"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ class UploadPackageTaskWithWaitIntegrationTest {
val micro = Random.Default.nextInt(0, 100)
println(testProjectDir.root.absolutePath)
setupBuild(major, minor, micro)

val result = GradleRunner.create()
.forwardOutput()
.withProjectDir(testProjectDir.root)
Expand Down Expand Up @@ -82,7 +81,7 @@ octopus {
serverUrl.set("$serverUrl")
apiKey.set("$apiKey")
generateChangelogSinceLastTag = true
generateChangelogSinceLastTag.set(true)
val jar by tasks.existing(Jar::class)
packageName.set(jar.get().archiveBaseName.get().removeSuffix("-"))
Expand Down
Loading

0 comments on commit 3ec7400

Please sign in to comment.