Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/manual release #12

Merged
merged 8 commits into from
Aug 7, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 26 additions & 26 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,27 +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" }}
# 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 @@ -74,14 +74,14 @@ workflows:
filters:
tags:
only: /.*/
- integration-test:
filters:
tags:
only: /.*/
# - integration-test:
# filters:
# tags:
# only: /.*/
- publish-plugin:
requires:
- build
- integration-test
# - integration-test
filters:
tags:
only: /.*/
Expand Down
25 changes: 25 additions & 0 deletions src/main/kotlin/com/liftric/octopusdeploy/OctopusDeployPlugin.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import org.gradle.api.Project
internal const val extensionName = "octopus"

class OctopusDeployPlugin : Plugin<Project> {
@Suppress("UNUSED_VARIABLE")
override fun apply(project: Project) {
val extension = project.extensions.create(extensionName, OctopusDeployExtension::class.java, project)
extension.outputDir.apply {
Expand Down Expand Up @@ -59,6 +60,26 @@ class OctopusDeployPlugin : Plugin<Project> {
buildInformationAddition = extension.buildInformationAddition
}
}
val createBuildInformationMarkdownTask =
project.tasks.create("createBuildInformationMarkdown", CreateBuildInformationMarkdownTask::class.java)
.apply {
val task = this
project.afterEvaluate {
if (extension.generateChangelogSinceLastTag) {
dependsOn(commitsSinceLastTagTask)
}
commits = emptyList()
packageName.set(extension.packageName)
issueTrackerName.set(extension.issueTrackerName)
parseCommitsForJiraIssues.set(extension.parseCommitsForJiraIssues)
jiraBaseBrowseUrl.set(extension.jiraBaseBrowseUrl)
task.version.set(extension.version)
}
doFirst {
commits = commitsSinceLastTagTask.commits
buildInformationAddition = extension.buildInformationAddition
}
}
val uploadBuildInformationTask =
project.tasks.create("uploadBuildInformation", UploadBuildInformationTask::class.java).apply {
dependsOn(createBuildInformationTask)
Expand Down Expand Up @@ -94,6 +115,10 @@ class OctopusDeployPlugin : Plugin<Project> {
httpLogLevel.set(extension.httpLogLevel)
}
}
project.tasks.withType(CreateReleaseTask::class.java) {
apiKey.convention(extension.apiKey)
octopusUrl.convention(extension.serverUrl)
}
}
}

Expand Down
80 changes: 40 additions & 40 deletions src/main/kotlin/com/liftric/octopusdeploy/api/Progression.kt
Original file line number Diff line number Diff line change
Expand Up @@ -218,85 +218,85 @@ data class DeploymentDeploymentLinks(
)

data class Task(
@get:JsonProperty("Id", required = true) @field:JsonProperty("Id", required = true)
val id: String,
@get:JsonProperty("Id") @field:JsonProperty("Id")
val id: String? = null,
nvima marked this conversation as resolved.
Show resolved Hide resolved

@get:JsonProperty("SpaceId", required = true) @field:JsonProperty("SpaceId", required = true)
val spaceID: String,
@get:JsonProperty("SpaceId") @field:JsonProperty("SpaceId")
val spaceID: String? = null,

@get:JsonProperty("Name", required = true) @field:JsonProperty("Name", required = true)
val name: String,
@get:JsonProperty("Name") @field:JsonProperty("Name")
val name: String? = null,

@get:JsonProperty("Description", required = true) @field:JsonProperty("Description", required = true)
val description: String,
@get:JsonProperty("Description") @field:JsonProperty("Description")
val description: String? = null,

@get:JsonProperty("Arguments", required = true) @field:JsonProperty("Arguments", required = true)
val arguments: Arguments,
@get:JsonProperty("Arguments") @field:JsonProperty("Arguments")
val arguments: Arguments? = null,

@get:JsonProperty("State", required = true) @field:JsonProperty("State", required = true)
val state: String,
@get:JsonProperty("State") @field:JsonProperty("State")
val state: String? = null,

@get:JsonProperty("QueueTime", required = true) @field:JsonProperty("QueueTime", required = true)
val queueTime: String,
@get:JsonProperty("QueueTime") @field:JsonProperty("QueueTime")
val queueTime: String? = null,

@get:JsonProperty("QueueTimeExpiry") @field:JsonProperty("QueueTimeExpiry")
val queueTimeExpiry: Any? = null,

@get:JsonProperty("StartTime", required = true) @field:JsonProperty("StartTime", required = true)
val startTime: String,
@get:JsonProperty("StartTime") @field:JsonProperty("StartTime")
val startTime: String? = null,

@get:JsonProperty("LastUpdatedTime", required = true) @field:JsonProperty("LastUpdatedTime", required = true)
val lastUpdatedTime: String,
@get:JsonProperty("LastUpdatedTime") @field:JsonProperty("LastUpdatedTime")
val lastUpdatedTime: String? = null,

@get:JsonProperty("CompletedTime") @field:JsonProperty("CompletedTime")
val completedTime: Any? = null,

@get:JsonProperty("ServerNode", required = true) @field:JsonProperty("ServerNode", required = true)
val serverNode: String,
@get:JsonProperty("ServerNode") @field:JsonProperty("ServerNode")
val serverNode: String? = null,

@get:JsonProperty("Duration", required = true) @field:JsonProperty("Duration", required = true)
val duration: String,
@get:JsonProperty("Duration") @field:JsonProperty("Duration")
val duration: String? = null,

@get:JsonProperty("ErrorMessage", required = true) @field:JsonProperty("ErrorMessage", required = true)
val errorMessage: String,
@get:JsonProperty("ErrorMessage") @field:JsonProperty("ErrorMessage")
val errorMessage: String? = null,

@get:JsonProperty("HasBeenPickedUpByProcessor", required = true) @field:JsonProperty(
@get:JsonProperty("HasBeenPickedUpByProcessor") @field:JsonProperty(
"HasBeenPickedUpByProcessor",
required = true
)
val hasBeenPickedUpByProcessor: Boolean,
val hasBeenPickedUpByProcessor: Boolean? = null,

@get:JsonProperty("IsCompleted", required = true) @field:JsonProperty("IsCompleted", required = true)
val isCompleted: Boolean,
@get:JsonProperty("IsCompleted") @field:JsonProperty("IsCompleted")
val isCompleted: Boolean? = null,

@get:JsonProperty("FinishedSuccessfully", required = true) @field:JsonProperty(
@get:JsonProperty("FinishedSuccessfully") @field:JsonProperty(
"FinishedSuccessfully",
required = true
)
val finishedSuccessfully: Boolean,
val finishedSuccessfully: Boolean? = null,

@get:JsonProperty("HasPendingInterruptions", required = true) @field:JsonProperty(
@get:JsonProperty("HasPendingInterruptions") @field:JsonProperty(
"HasPendingInterruptions",
required = true
)
val hasPendingInterruptions: Boolean,
val hasPendingInterruptions: Boolean? = null,

@get:JsonProperty("CanRerun", required = true) @field:JsonProperty("CanRerun", required = true)
val canRerun: Boolean,
@get:JsonProperty("CanRerun") @field:JsonProperty("CanRerun")
val canRerun: Boolean? = null,

@get:JsonProperty("HasWarningsOrErrors", required = true) @field:JsonProperty(
@get:JsonProperty("HasWarningsOrErrors") @field:JsonProperty(
"HasWarningsOrErrors",
required = true
)
val hasWarningsOrErrors: Boolean,
val hasWarningsOrErrors: Boolean? = null,

@get:JsonProperty("Links", required = true) @field:JsonProperty("Links", required = true)
val links: TaskLinks
@get:JsonProperty("Links") @field:JsonProperty("Links")
val links: TaskLinks? = null
)

data class Arguments(
@get:JsonProperty("DeploymentId", required = true) @field:JsonProperty("DeploymentId", required = true)
val deploymentID: String
@get:JsonProperty("DeploymentId") @field:JsonProperty("DeploymentId")
val deploymentID: String? = null
)

data class TaskLinks(
Expand Down
26 changes: 26 additions & 0 deletions src/main/kotlin/com/liftric/octopusdeploy/buildinformation.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.liftric.octopusdeploy

import com.liftric.octopusdeploy.api.CommitCli
import com.liftric.octopusdeploy.api.WorkItem

fun parseCommitsForJira(
commits: List<CommitCli>,
jiraBaseBrowseUrl: String
): List<WorkItem> {
val jiraIssues = commits
.mapNotNull { it.Comment }
.map { jiraKeyRegex.findAll(it).map { it.groupValues[1] }.toList() }
.flatten()
.toSet()
println("parseCommitsForJira: found $jiraIssues")
return jiraIssues.map {
WorkItem(
Id = it,
LinkUrl = "${jiraBaseBrowseUrl.removeSuffix("/")}/$it",
Description = "some placeholder text"
)
}
}

// from https://confluence.atlassian.com/stashkb/integrating-with-custom-jira-issue-key-313460921.html
private val jiraKeyRegex = Regex("((?<!([A-Z]{1,10})-?)[A-Z]+-\\d+)")
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,3 @@ interface Progressions {
}

fun Progression.anyOngoingTask(): Boolean = phases.any { it.deployments.any { it.task?.isCompleted == false } }

Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package com.liftric.octopusdeploy.task

import com.liftric.octopusdeploy.api.BuildInformationCli
import com.liftric.octopusdeploy.api.CommitCli
import org.gradle.api.DefaultTask
import org.gradle.api.provider.Property
import org.gradle.api.tasks.Input
import org.gradle.api.tasks.Optional
import org.gradle.api.tasks.OutputFile
import org.gradle.kotlin.dsl.property
import java.io.File

abstract class AbstractBuildInformationTask : DefaultTask() {

@Input
val packageName: Property<String> = project.objects.property()

@Input
val version: Property<String> = project.objects.property()

@Input
lateinit var commits: List<CommitCli>

@Input
var buildInformationAddition: BuildInformationCli.() -> Unit = {}

@OutputFile
@Optional
var outputFile: File? = null

@Input
@Optional
val issueTrackerName: Property<String> = project.objects.property()

@Input
@Optional
val parseCommitsForJiraIssues: Property<Boolean> = project.objects.property()

@Input
@Optional
val jiraBaseBrowseUrl: Property<String> = project.objects.property()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package com.liftric.octopusdeploy.task

import com.liftric.octopusdeploy.api.BuildInformationCli
import com.liftric.octopusdeploy.api.WorkItem
import com.liftric.octopusdeploy.extensionName
import com.liftric.octopusdeploy.parseCommitsForJira
import org.gradle.api.file.DirectoryProperty
import org.gradle.api.file.RegularFileProperty
import org.gradle.api.tasks.OutputDirectory
import org.gradle.api.tasks.OutputFile
import org.gradle.api.tasks.TaskAction

open class CreateBuildInformationMarkdownTask : AbstractBuildInformationTask() {
init {
group = "octopus"
description = "Creates a markdown file freom the build-information for octo cli release creation."
outputs.upToDateWhen { false }
}

@OutputDirectory
val outputDirectory: DirectoryProperty = project.objects.directoryProperty().convention(project.layout.buildDirectory.dir(extensionName))

@OutputFile
val outputMarkdown: RegularFileProperty = project.objects.fileProperty().convention(outputDirectory.file("build-information.md"))

@TaskAction
fun execute() {
val workItems: List<WorkItem>? = if (parseCommitsForJiraIssues.getOrElse(false)) {
parseCommitsForJira(commits, jiraBaseBrowseUrl.getOrElse(""))
} else {
null
}
val buildInformationCli = BuildInformationCli().apply(buildInformationAddition)
outputMarkdown.get().asFile.apply {
writeText("")
appendText("# ${packageName.get()}: ${version.get()}\n")
appendText("[VCS Root](${buildInformationCli.VcsRoot})\n\n")
appendText("CI: [${buildInformationCli.VcsCommitNumber}](${buildInformationCli.VcsCommitUrl})\n\n")
appendText("[BuildEnvironment: ${buildInformationCli.BuildEnvironment}](${buildInformationCli.BuildUrl})\n\n")
appendText("last modified by: ${buildInformationCli.LastModifiedBy}\n\n")
if (commits.isNotEmpty())
appendText("## Commits\n")
commits.forEach {
appendText(" - ${it.Id}: [${it.Comment}](${it.LinkUrl})\n")
}
if (workItems?.isNotEmpty() == true)
appendText("## WorkItems\n")
workItems?.forEach {
appendText(" - [${it.Id}](${it.LinkUrl})\n")
}
}
}
}
Loading