mirror of
https://github.com/ethauvin/kobalt.git
synced 2025-04-26 08:27:12 -07:00
Added autoGitTag to github and bintray configurations.
This commit is contained in:
parent
1b7eb08074
commit
850e335843
2 changed files with 95 additions and 35 deletions
|
@ -0,0 +1,43 @@
|
||||||
|
package com.beust.kobalt.misc
|
||||||
|
|
||||||
|
import com.beust.kobalt.TaskResult
|
||||||
|
import com.beust.kobalt.api.Project
|
||||||
|
import com.google.inject.Inject
|
||||||
|
import java.io.File
|
||||||
|
|
||||||
|
class Git @Inject constructor() {
|
||||||
|
fun maybeTagRelease(project: Project, uploadResult: TaskResult, autoGitTag: Boolean) : TaskResult {
|
||||||
|
val result =
|
||||||
|
if (uploadResult.success && autoGitTag) {
|
||||||
|
val tagSuccess = tagRelease(project)
|
||||||
|
if (! tagSuccess) {
|
||||||
|
TaskResult(false, "Couldn't tag the project")
|
||||||
|
} else {
|
||||||
|
TaskResult()
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
TaskResult()
|
||||||
|
}
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun tagRelease(project: Project) : Boolean {
|
||||||
|
val success = try {
|
||||||
|
log(2, "Tagging this release as \"${project.version}\"")
|
||||||
|
val repo = org.eclipse.jgit.storage.file.FileRepositoryBuilder()
|
||||||
|
.setGitDir(File(KFiles.joinDir(project.directory, ".git")))
|
||||||
|
.readEnvironment()
|
||||||
|
.findGitDir()
|
||||||
|
.build()
|
||||||
|
val git = org.eclipse.jgit.api.Git(repo)
|
||||||
|
val ref = git.tag().setName(project.version).call()
|
||||||
|
git.push().setPushTags().call()
|
||||||
|
true
|
||||||
|
} catch(ex: Exception) {
|
||||||
|
warn("Couldn't create tag ${project.version}: ${ex.message}", ex)
|
||||||
|
false
|
||||||
|
}
|
||||||
|
|
||||||
|
return success
|
||||||
|
}
|
||||||
|
}
|
|
@ -7,14 +7,10 @@ import com.beust.kobalt.api.Project
|
||||||
import com.beust.kobalt.api.annotation.Directive
|
import com.beust.kobalt.api.annotation.Directive
|
||||||
import com.beust.kobalt.api.annotation.Task
|
import com.beust.kobalt.api.annotation.Task
|
||||||
import com.beust.kobalt.internal.DocUrl
|
import com.beust.kobalt.internal.DocUrl
|
||||||
import com.beust.kobalt.internal.KobaltSettings
|
|
||||||
import com.beust.kobalt.localMaven
|
import com.beust.kobalt.localMaven
|
||||||
import com.beust.kobalt.maven.Md5
|
import com.beust.kobalt.maven.Md5
|
||||||
import com.beust.kobalt.maven.PomGenerator
|
import com.beust.kobalt.maven.PomGenerator
|
||||||
import com.beust.kobalt.misc.GithubApi2
|
import com.beust.kobalt.misc.*
|
||||||
import com.beust.kobalt.misc.KFiles
|
|
||||||
import com.beust.kobalt.misc.LocalProperties
|
|
||||||
import com.beust.kobalt.misc.warn
|
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.net.URL
|
import java.net.URL
|
||||||
import java.nio.file.Paths
|
import java.nio.file.Paths
|
||||||
|
@ -26,7 +22,7 @@ import javax.inject.Singleton
|
||||||
@Singleton
|
@Singleton
|
||||||
public class PublishPlugin @Inject constructor(val files: KFiles, val factory: PomGenerator.IFactory,
|
public class PublishPlugin @Inject constructor(val files: KFiles, val factory: PomGenerator.IFactory,
|
||||||
val bintrayFactory: BintrayApi.IFactory, val github: GithubApi2, val localProperties: LocalProperties,
|
val bintrayFactory: BintrayApi.IFactory, val github: GithubApi2, val localProperties: LocalProperties,
|
||||||
val settings: KobaltSettings) : BasePlugin() {
|
val git: Git) : BasePlugin() {
|
||||||
|
|
||||||
override val name = PLUGIN_NAME
|
override val name = PLUGIN_NAME
|
||||||
|
|
||||||
|
@ -118,30 +114,34 @@ public class PublishPlugin @Inject constructor(val files: KFiles, val factory: P
|
||||||
val configuration = bintrayConfigurations[project.name]
|
val configuration = bintrayConfigurations[project.name]
|
||||||
val messages = arrayListOf<String>()
|
val messages = arrayListOf<String>()
|
||||||
|
|
||||||
if (configuration != null) {
|
val tmpResult =
|
||||||
//
|
if (configuration != null) {
|
||||||
// Upload to Maven
|
//
|
||||||
//
|
// Upload to Maven
|
||||||
val trMaven = jcenter.uploadMaven(project, findArtifactFiles(project), configuration)
|
//
|
||||||
success = trMaven.success
|
val trMaven = jcenter.uploadMaven(project, findArtifactFiles(project), configuration)
|
||||||
if (! success) messages.add(trMaven.errorMessage!!)
|
success = trMaven.success
|
||||||
|
if (! success) messages.add(trMaven.errorMessage!!)
|
||||||
|
|
||||||
//
|
//
|
||||||
// Upload individual files, if applicable
|
// Upload individual files, if applicable
|
||||||
//
|
//
|
||||||
configuration.files.forEach {
|
configuration.files.forEach {
|
||||||
val taskResult = jcenter.uploadFile(project, File(project.directory, it.first), configuration)
|
val taskResult = jcenter.uploadFile(project, File(project.directory, it.first), configuration)
|
||||||
success = success and taskResult.success
|
success = success and taskResult.success
|
||||||
if (!taskResult.success) {
|
if (!taskResult.success) {
|
||||||
messages.add(taskResult.errorMessage!!)
|
messages.add(taskResult.errorMessage!!)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
git.maybeTagRelease(project, TaskResult(), configuration.autoGitTag)
|
||||||
|
} else {
|
||||||
|
context.logger.log(project.name, 2, "Couldn't find any jcenter{} configuration, not uploading anything")
|
||||||
|
TaskResult()
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
context.logger.log(project.name, 2, "Couldn't find any jcenter{} configuration, not uploading anything")
|
|
||||||
success = true
|
|
||||||
}
|
|
||||||
|
|
||||||
return TaskResult(success, messages.joinToString("\n "))
|
val result = TaskResult(tmpResult.success, messages.joinToString("\n "))
|
||||||
|
|
||||||
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
@Task(name = TASK_UPLOAD_GITHUB, description = "Upload files to Github",
|
@Task(name = TASK_UPLOAD_GITHUB, description = "Upload files to Github",
|
||||||
|
@ -157,16 +157,19 @@ public class PublishPlugin @Inject constructor(val files: KFiles, val factory: P
|
||||||
//
|
//
|
||||||
// Upload individual files, if applicable
|
// Upload individual files, if applicable
|
||||||
//
|
//
|
||||||
if (configuration != null) {
|
val result =
|
||||||
configuration.files.forEach {
|
if (configuration != null) {
|
||||||
logk(project.name, 2, "Uploading $it tag: ${project.version}")
|
configuration.files.forEach {
|
||||||
github.uploadRelease(project.name, project.version!!, it)
|
logk(project.name, 2, "Uploading $it tag: ${project.version}")
|
||||||
|
github.uploadRelease(project.name, project.version!!, it)
|
||||||
|
}
|
||||||
|
git.maybeTagRelease(project, TaskResult(), configuration.autoGitTag)
|
||||||
|
} else {
|
||||||
|
warn("Couldn't find any github{} configuration, not uploading anything")
|
||||||
|
TaskResult()
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
warn("Couldn't find any github{} configuration, not uploading anything")
|
|
||||||
}
|
|
||||||
|
|
||||||
return TaskResult()
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -189,8 +192,15 @@ public class PublishPlugin @Inject constructor(val files: KFiles, val factory: P
|
||||||
data class GithubConfig(val project: Project) {
|
data class GithubConfig(val project: Project) {
|
||||||
val files = arrayListOf<File>()
|
val files = arrayListOf<File>()
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If true, automatically tag this release with the current version number and push that tag to origin when
|
||||||
|
* the uploadGithub task is called.
|
||||||
|
*/
|
||||||
@Directive
|
@Directive
|
||||||
public fun file(filePath: String, url: String) {
|
var autoGitTag: Boolean = false
|
||||||
|
|
||||||
|
@Directive
|
||||||
|
fun file(filePath: String, url: String) {
|
||||||
files.add(File(filePath))
|
files.add(File(filePath))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -219,6 +229,13 @@ data class BintrayConfig(val project: Project) {
|
||||||
@Directive
|
@Directive
|
||||||
var sign: Boolean = false
|
var sign: Boolean = false
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If true, automatically tag this release with the current version number and push that tag to origin when
|
||||||
|
* the uploadBintray task is called.
|
||||||
|
*/
|
||||||
|
@Directive
|
||||||
|
var autoGitTag: Boolean = true
|
||||||
|
|
||||||
val files = arrayListOf<Pair<String, String>>()
|
val files = arrayListOf<Pair<String, String>>()
|
||||||
|
|
||||||
@Directive
|
@Directive
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue