Skip to content

Commit

Permalink
Merge pull request #3 from Liftric/feature/lazy-conf
Browse files Browse the repository at this point in the history
adapt apiKey and serverUrl lazy gradle properties
  • Loading branch information
benjohnde authored Apr 27, 2020
2 parents 3ab163f + dc35814 commit 901cf8c
Show file tree
Hide file tree
Showing 11 changed files with 48 additions and 32 deletions.
16 changes: 12 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ plugins {
}
[...]
octopus {
serverUrl = "http://localhost:8080/"
apiKey = "API-TESTTEST123TRESDTSDD"
serverUrl.set("http://localhost:8080/")
apiKey.set("API-TESTTEST123TRESDTSDD")
generateChangelogSinceLastTag = true
Expand Down Expand Up @@ -77,8 +77,8 @@ After the plugin is applied, the octopus extension is registered with the follow

Property | Description | default value
---|---|---
apiKey | Octopus deploy server API key | -
serverUrl | Octopus deploy server URL | -
apiKey | Octopus deploy server API key (lazy gradle property)| -
serverUrl | Octopus deploy server URL (lazy gradle property)| -
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
Expand All @@ -93,3 +93,11 @@ gitlab() | Default `buildInformationAddition` implementation adding context from

`generateChangelogSinceLastTag` extracts all commits between the HEAD and the last tag.
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 on configuration time:
```
apiKey.set(provider {
"API-TESTTEST123TRESDTSDD"
// read from file / vault / etc.
})
```
6 changes: 4 additions & 2 deletions example/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@ tasks {
}
octopus {
// targets the GITROOT/docker-compose.yml ocotpus deploy instance
serverUrl = "http://localhost:8080/"
apiKey = "API-TESTTEST123TRESDTSDD"
serverUrl.set("http://localhost:8080/")
apiKey.set(provider {
"API-TESTTEST123TRESDTSDD"
})

commitLinkBaseUrl = "${System.getenv("CI_PROJECT_URL")?.removeSuffix("/")}/commit"
generateChangelogSinceLastTag = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ tasks {
}
}
octopus {
serverUrl = "$serverUrl"
apiKey = "$apiKey"
serverUrl.set("$serverUrl")
apiKey.set("$apiKey")
generateChangelogSinceLastTag = true
Expand All @@ -88,4 +88,4 @@ octopus {
}
testProjectDir.root.setupGitRepo()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ tasks {
}
}
octopus {
serverUrl = "$serverUrl"
apiKey = "$apiKey"
serverUrl.set("$serverUrl")
apiKey.set("$apiKey")
generateChangelogSinceLastTag = true
Expand All @@ -88,4 +88,4 @@ octopus {
}
testProjectDir.root.setupGitRepo()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,23 @@ package com.liftric.octopusdeploy
import com.liftric.octopusdeploy.api.BuildInformation
import com.liftric.octopusdeploy.api.OverwriteMode
import org.gradle.api.Project
import org.gradle.api.provider.Property
import org.gradle.api.tasks.Input
import org.gradle.api.tasks.InputFile
import org.gradle.api.tasks.OutputDirectory
import org.gradle.kotlin.dsl.property
import java.io.File

open class OctopusDeployExtension(project: Project) {
/**
* Octopus deploy server API key
*/
var apiKey: String? = null
val apiKey: Property<String> = project.objects.property()

/**
* Octopus deploy server URL
*/
var serverUrl: String? = null
val serverUrl: Property<String> = project.objects.property()

/**
* Enable to calculate the commits for the changelog when uploading build-information
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ class OctopusDeployPlugin : Plugin<Project> {
dependsOn(createBuildInformationTask)
val task = this
project.afterEvaluate {
apiKey = extension.apiKey ?: error("$extensionName: didn't specify apiKey!")
octopusUrl = extension.serverUrl ?: error("$extensionName: didn't specify serverUrl!")
apiKey.set(extension.apiKey)
octopusUrl.set(extension.serverUrl)
packageName = extension.packageName ?: error("$extensionName: didn't specify packageName!")
task.version = extension.version ?: error("$extensionName: didn't specify version!")
overwriteMode = extension.buildInformationOverwriteMode?.name
Expand All @@ -74,8 +74,8 @@ class OctopusDeployPlugin : Plugin<Project> {
project.tasks.create("uploadPackage", UploadPackageTask::class.java).apply {
val task = this
project.afterEvaluate {
apiKey = extension.apiKey ?: error("$extensionName: didn't specify apiKey!")
octopusUrl = extension.serverUrl ?: error("$extensionName: didn't specify serverUrl!")
apiKey.set(extension.apiKey)
octopusUrl.set(extension.serverUrl)
packageName = extension.packageName ?: error("$extensionName: didn't specify packageName!")
task.version = extension.version ?: error("$extensionName: didn't specify version!")
packageFile = extension.pushPackage
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ package com.liftric.octopusdeploy.task

import com.liftric.octopusdeploy.shell
import org.gradle.api.DefaultTask
import org.gradle.api.provider.Property
import org.gradle.api.tasks.Input
import org.gradle.api.tasks.InputFile
import org.gradle.api.tasks.Optional
import org.gradle.api.tasks.TaskAction
import org.gradle.kotlin.dsl.property
import java.io.File

open class UploadBuildInformationTask : DefaultTask() {
Expand All @@ -16,9 +18,9 @@ open class UploadBuildInformationTask : DefaultTask() {
}

@Input
lateinit var octopusUrl: String
val octopusUrl: Property<String> = project.objects.property()
@Input
lateinit var apiKey: String
val apiKey: Property<String> = project.objects.property()

@Input
lateinit var packageName: String
Expand All @@ -38,8 +40,8 @@ open class UploadBuildInformationTask : DefaultTask() {
val (exitCode, inputText, errorText) = listOf(
"octo",
"build-information",
"--server=${octopusUrl}",
"--apiKey=${apiKey}",
"--server=${octopusUrl.get()}",
"--apiKey=${apiKey.get()}",
"--file",
buildInformation?.absolutePath ?: error("couldn't find build-information.json"),
"--package-id",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ package com.liftric.octopusdeploy.task

import com.liftric.octopusdeploy.shell
import org.gradle.api.DefaultTask
import org.gradle.api.provider.Property
import org.gradle.api.tasks.Input
import org.gradle.api.tasks.InputFile
import org.gradle.api.tasks.Optional
import org.gradle.api.tasks.TaskAction
import org.gradle.kotlin.dsl.property
import java.io.File

open class UploadPackageTask : DefaultTask() {
Expand All @@ -16,9 +18,9 @@ open class UploadPackageTask : DefaultTask() {
}

@Input
lateinit var octopusUrl: String
val octopusUrl: Property<String> = project.objects.property()
@Input
lateinit var apiKey: String
val apiKey: Property<String> = project.objects.property()

@Input
lateinit var packageName: String
Expand All @@ -38,8 +40,8 @@ open class UploadPackageTask : DefaultTask() {
val (exitCode, inputText, errorText) = listOf(
"octo",
"push",
"--server=${octopusUrl}",
"--apiKey=${apiKey}",
"--server=${octopusUrl.get()}",
"--apiKey=${apiKey.get()}",
"--package",
packageFile?.absolutePath ?: error("couldn't find build-information.json"),
overwriteMode?.let { "--overwrite-mode=$it" }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ plugins {
id("com.liftric.octopus-deploy-plugin")
}
octopus {
apiKey = "whatever"
apiKey.set("whatever")
version = "whatever"
packageName = "whatever"
serverUrl = "whatever"
serverUrl.set("whatever")
}"""
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@ plugins {
id("com.liftric.octopus-deploy-plugin")
}
octopus {
apiKey = "fakefake"
apiKey.set("fakefake")
gitRoot = file("${File(".").absolutePath}")
version = "whatever"
packageName = "whatever"
serverUrl = "whatever"
serverUrl.set("whatever")
}
"""
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ plugins {
id("com.liftric.octopus-deploy-plugin")
}
octopus {
apiKey = "whatever"
apiKey.set("whatever")
version = "whatever"
packageName = "whatever"
serverUrl = "whatever"
serverUrl.set("whatever")
}
"""
)
Expand Down

0 comments on commit 901cf8c

Please sign in to comment.