Skip to content

Commit

Permalink
Merge pull request #1 from Liftric/feature/package-and-buildinfo
Browse files Browse the repository at this point in the history
feature/package and buildinfo
  • Loading branch information
Ingwersaft authored Apr 17, 2020
2 parents 44268eb + 0adfc00 commit 2bafb68
Show file tree
Hide file tree
Showing 29 changed files with 1,507 additions and 15 deletions.
46 changes: 38 additions & 8 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
version: 2
jobs:
build:
docker:
- image: circleci/openjdk:8-jdk
working_directory: ~/repo
environment:
JVM_OPTS: -Xmx3200m
TERM: dumb
machine: true
steps:
- checkout
- restore_cache:
Expand All @@ -15,6 +10,16 @@ jobs:
# fallback to using the latest cache if no exact match is found
- v1-dependencies-
- run: ./gradlew build
- run:
name: Save test results
command: |
mkdir -p ~/test-results/junit/
find . -type f -regex ".*/build/test-results/.*xml" -exec cp {} ~/test-results/junit/ \;
when: always
- store_test_results:
path: ~/test-results
- store_artifacts:
path: ~/test-results/junit
- save_cache:
paths:
- ~/.gradle
Expand All @@ -39,6 +44,27 @@ jobs:
paths:
- ~/.gradle
key: v1-dependencies-{{ checksum "build.gradle.kts" }}
integration-test:
machine: true
steps:
- checkout
- restore_cache:
keys:
- v1-dependencies-{{ checksum "build.gradle.kts" }}
# fallback to using the latest cache if no exact match is found
- v1-dependencies-
- run:
name: Install octo cli
command: |
sudo apt update && sudo apt install --no-install-recommends gnupg curl ca-certificates apt-transport-https && \
curl -sSfL https://apt.octopus.com/public.key | sudo apt-key add - && \
sudo sh -c "echo deb https://apt.octopus.com/ stable main > /etc/apt/sources.list.d/octopus.com.list" && \
sudo apt update && sudo apt install octopuscli
- run: ./gradlew integrationTest
- save_cache:
paths:
- ~/.gradle
key: v1-dependencies-{{ checksum "build.gradle.kts" }}

workflows:
version: 2
Expand All @@ -48,10 +74,14 @@ workflows:
filters:
tags:
only: /.*/
- integration-test:
filters:
tags:
only: /.*/
- publish-plugin:
requires:
- integration-token
- integration-tokenfile
- build
- integration-test
filters:
tags:
only: /.*/
Expand Down
70 changes: 69 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,76 @@
![GitHub release (latest by date)](https://img.shields.io/github/v/release/Liftric/octopus-deploy-plugin)
[![CircleCI](https://circleci.com/gh/Liftric/octopus-deploy-plugin/tree/master.svg?style=svg)](https://circleci.com/gh/Liftric/octopus-deploy-plugin/tree/master)

The octopus-deploy-plugin generates build-information and uploads packages and generated build-information to Octopus Deploy instances.

Requirements:
* [Octopus Deploy CLI](https://octopus.com/downloads/octopuscli)
* git (for commit/changelog calculation)

# Usage
The plugin can be configured with the `octopus` DSL block:
```
plugins {
id("com.liftric.octopus-deploy-plugin") version "whatever"
}
[...]
octopus {
serverUrl = "http://localhost:8080/"
apiKey = "API-TESTTEST123TRESDTSDD"
generateChangelogSinceLastTag = true
val jar by tasks.existing(Jar::class)
packageName = jar.get().archiveBaseName.get()
version = jar.get().archiveVersion.get()
pushPackage = jar.get().archiveFile.get().asFile
}
```

See the example directory for a minimal, working example.

## tasks
The following tasks are added by the plugin:

Task | Description
---|---
previousTag | Calls git describe to receive the previous tag name. Will fail if no tag is found.
firstCommitHash | Calls git log to get the first commit hash of the current history tree
commitsSinceLastTag | Calls git log to receive all commits since the previous tag or the first commit of the current history.
createBuildInformation | Creates the octopus build-information file.
uploadBuildInformation | Uploads the created octopus build-information file.
uploadPackage | Uploads the package to octopus.

For normale use-cases, only `uploadBuildInformation` are `uploadPackage` are needed to call explicitly. Depending
task 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.

## naming
Octopus deploy expects the name and version in the following format: `<name>.<version>.<extension>`

For Java archives, `<name>-<version>.<extension>` is conventional, so should be changed to get picked up properly by octopus.
Otherwise the first version number part will be parsed as part of the name.

## configuration
After the plugin is applied, the octopus extension is registered with the following settings:

Property | Description | default value
---|---|---
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 | -
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

## buildSrc
`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.
51 changes: 46 additions & 5 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ import net.nemerosa.versioning.tasks.VersionDisplayTask
plugins {
kotlin("jvm") version "1.3.61"
`java-gradle-plugin`
id("org.gradle.kotlin.kotlin-dsl") version "1.3.3"
id("org.gradle.kotlin.kotlin-dsl") version "1.3.4"
`maven-publish`
id("com.gradle.plugin-publish") version "0.10.1"
id("com.gradle.plugin-publish") version "0.11.0"
id("net.nemerosa.versioning") version "2.12.0"
id("com.avast.gradle.docker-compose") version "0.10.7"
}

group = "com.liftric.octopusdeploy"
Expand All @@ -19,12 +20,22 @@ allprojects {
}
}
}

sourceSets {
create("integrationTest") {
compileClasspath += sourceSets.main.get().output
compileClasspath += sourceSets.test.get().output
runtimeClasspath += sourceSets.main.get().output
runtimeClasspath += sourceSets.test.get().output
}
}
val integrationTestImplementation by configurations.getting {
extendsFrom(configurations.testImplementation.get())
}
configurations["integrationTestRuntimeOnly"].extendsFrom(configurations.testRuntimeOnly.get())
repositories {
mavenCentral()
jcenter()
}

dependencies {
implementation(gradleApi())
implementation(kotlin("gradle-plugin"))
Expand All @@ -33,15 +44,23 @@ dependencies {
testImplementation(gradleTestKit())
testImplementation("junit:junit:4.12")
testImplementation("com.github.stefanbirkner:system-rules:1.19.0")
integrationTestImplementation("junit:junit:4.12")
integrationTestImplementation("org.apache.httpcomponents:httpclient:4.5.12")
}
java {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}

tasks {
compileKotlin {
kotlinOptions.jvmTarget = "1.8"
}
compileTestKotlin {
kotlinOptions.jvmTarget = "1.8"
}
withType<Test> {
testLogging.showStandardStreams = true
}
withType<VersionDisplayTask> {
doLast {
println("[VersionDisplayTask] version=$version")
Expand Down Expand Up @@ -74,6 +93,20 @@ tasks {
}
val publishPlugins by existing
publishPlugins.get().dependsOn(setupPluginsLogin)

//
val composeUp by existing
val composeDownForced by existing
val integrationTest by creating(Test::class) {
description = "Runs integration tests."
group = "verification"

testClassesDirs = sourceSets["integrationTest"].output.classesDirs
classpath = sourceSets["integrationTest"].runtimeClasspath
shouldRunAfter("test")
dependsOn(composeUp)
finalizedBy(composeDownForced)
}
}
publishing {
repositories {
Expand All @@ -96,3 +129,11 @@ pluginBundle {
description = "Common tasks for Octopus Deploy interaction, like package or build-information uploading"
tags = listOf("octopus", "deploy", "releases", "build-information", "upload", "packages")
}
dockerCompose {
useComposeFiles = listOf("docker-compose.yml")
waitForTcpPorts = true
captureContainersOutput = true
stopContainers = true
removeContainers = true
buildBeforeUp = true
}
27 changes: 27 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
version: '3'
services:
db:
image: microsoft/mssql-server-linux
environment:
SA_PASSWORD: yourStrong(!)Password
ACCEPT_EULA: Y
ports:
- 1433:1433
healthcheck:
test: [ "CMD", "/opt/mssql-tools/bin/sqlcmd", "-U", "sa", "-P", "yourStrong(!)Password", "-Q", "select 1"]
interval: 10s
retries: 10
octopus:
image: octopusdeploy/octopusdeploy
environment:
ACCEPT_EULA: Y
DB_CONNECTION_STRING: Server=db,1433;Database=OctopusDeploy;User=sa;Password=yourStrong(!)Password
ADMIN_USERNAME: admin
ADMIN_PASSWORD: testtest123
ADMIN_API_KEY: API-TESTTEST123TRESDTSDD
ports:
- "8080:8080"
links:
- db
depends_on:
- db
31 changes: 31 additions & 0 deletions example/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
plugins {
java
id("com.liftric.octopus-deploy-plugin") version "whatever"
}
group = "com.liftric"
version = "1.2.3"

tasks {
withType<Jar> {
// example-1.2.3.jar would be parsed as package: example-1 with version 2.3,
// so the name is changed to example.1.2.3.jar to support the octopus deploy naming convention
archiveFileName.set(
"${archiveBaseName.get()
.removeSuffix("-")}.${archiveVersion.get()}.${archiveExtension.get()}"
)
}
}
octopus {
// targets the GITROOT/docker-compose.yml ocotpus deploy instance
serverUrl = "http://localhost:8080/"
apiKey = "API-TESTTEST123TRESDTSDD"

commitLinkBaseUrl = "${System.getenv("CI_PROJECT_URL")?.removeSuffix("/")}/commit"
generateChangelogSinceLastTag = true

val jar by tasks.existing(Jar::class)
packageName = jar.get().archiveBaseName.get().removeSuffix("-")
version = jar.get().archiveVersion.get()
pushPackage = jar.get().archiveFile.get().asFile

}
16 changes: 16 additions & 0 deletions example/settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
rootProject.name = "example"
pluginManagement {
repositories {
gradlePluginPortal()
mavenLocal()
}

resolutionStrategy {
eachPlugin {
if (requested.id.id == "com.liftric.octopus-deploy-plugin") {
val currentVersion = file("../build/version").readText().trim()
useModule("com.liftric.octopusdeploy:octopus-deploy-plugin:${currentVersion}")
}
}
}
}
Loading

0 comments on commit 2bafb68

Please sign in to comment.