Unverified Commit 7e01dc01 authored by Alexey Tsvetkov's avatar Alexey Tsvetkov Committed by GitHub

Add task to create Github release (#10)

parent e5421fa9
...@@ -10,23 +10,21 @@ plugins { ...@@ -10,23 +10,21 @@ plugins {
id("de.undercouch.download") version "4.1.1" id("de.undercouch.download") version "4.1.1"
} }
val properties = SkikoProperties(rootProject) buildscript {
dependencies {
group = "org.jetbrains.skiko" classpath("org.kohsuke:github-api:1.116")
version = run { }
val suffix = if (properties.isRelease) "" else "-SNAPSHOT" repositories {
properties.deployVersion + suffix mavenCentral()
}
} }
val hostOs = System.getProperty("os.name") val skiko = SkikoProperties(rootProject)
val target = when {
hostOs == "Mac OS X" -> "macos"
hostOs == "Linux" -> "linux"
hostOs.startsWith("Win") -> "windows"
else -> throw Error("Unknown os $hostOs")
}
val jdkHome = System.getProperty("java.home") ?: error("'java.home' is null") allprojects {
group = "org.jetbrains.skiko"
version = skiko.deployVersion
}
repositories { repositories {
mavenCentral() mavenCentral()
...@@ -36,12 +34,12 @@ repositories { ...@@ -36,12 +34,12 @@ repositories {
} }
val skiaZip = run { val skiaZip = run {
val zipName = properties.skiaReleaseForCurrentOS + ".zip" val zipName = skiko.skiaReleaseForCurrentOS + ".zip"
val zipFile = properties.dependenciesDir.resolve("skia/$zipName") val zipFile = skiko.dependenciesDir.resolve("skia/$zipName")
tasks.register("downloadSkia", Download::class) { tasks.register("downloadSkia", Download::class) {
onlyIf { properties.skiaDir == null && !zipFile.exists() } onlyIf { skiko.skiaDir == null && !zipFile.exists() }
inputs.property("skia.release.for.current.os", properties.skiaReleaseForCurrentOS) inputs.property("skia.release.for.current.os", skiko.skiaReleaseForCurrentOS)
src("https://bintray.com/api/ui/download/jetbrains/skija/$zipName") src("https://bintray.com/api/ui/download/jetbrains/skija/$zipName")
dest(zipFile) dest(zipFile)
onlyIfModified(true) onlyIfModified(true)
...@@ -82,16 +80,16 @@ fun AbstractCopyTask.configureSkiaCopy(targetDir: File) { ...@@ -82,16 +80,16 @@ fun AbstractCopyTask.configureSkiaCopy(targetDir: File) {
} }
val skiaDir = run { val skiaDir = run {
if (properties.skiaDir != null) { if (skiko.skiaDir != null) {
tasks.register("skiaDir", DefaultTask::class) { tasks.register("skiaDir", DefaultTask::class) {
// dummy task to simplify usage of the resulting provider (see `else` branch) // dummy task to simplify usage of the resulting provider (see `else` branch)
// if a file provider is not created from a task provider, // if a file provider is not created from a task provider,
// then it cannot be used instead of a task in `dependsOn` clauses of other tasks. // then it cannot be used instead of a task in `dependsOn` clauses of other tasks.
// e.g. the resulting `skiaDir` could not be used in `dependsOn` of CppCompile configuration // e.g. the resulting `skiaDir` could not be used in `dependsOn` of CppCompile configuration
enabled = false enabled = false
}.map { properties.skiaDir!! } }.map { skiko.skiaDir!! }
} else { } else {
val targetDir = properties.dependenciesDir.resolve("skia/skia") val targetDir = skiko.dependenciesDir.resolve("skia/skia")
tasks.register("unzipSkia", Copy::class) { tasks.register("unzipSkia", Copy::class) {
from(skiaZip.map { zipTree(it) }) from(skiaZip.map { zipTree(it) })
configureSkiaCopy(targetDir) configureSkiaCopy(targetDir)
...@@ -100,27 +98,27 @@ val skiaDir = run { ...@@ -100,27 +98,27 @@ val skiaDir = run {
} }
val skijaZip = run { val skijaZip = run {
val zipFile = properties.dependenciesDir.resolve("skija/${properties.skijaCommitHash}.zip") val zipFile = skiko.dependenciesDir.resolve("skija/${skiko.skijaCommitHash}.zip")
tasks.register("downloadSkija", Download::class) { tasks.register("downloadSkija", Download::class) {
onlyIf { properties.skijaDir == null && !zipFile.exists() } onlyIf { skiko.skijaDir == null && !zipFile.exists() }
inputs.property("skija.commit.hash", properties.skijaCommitHash) inputs.property("skija.commit.hash", skiko.skijaCommitHash)
src("https://github.com/JetBrains/skija/archive/${properties.skijaCommitHash}.zip") src("https://github.com/JetBrains/skija/archive/${skiko.skijaCommitHash}.zip")
dest(zipFile) dest(zipFile)
onlyIfModified(true) onlyIfModified(true)
}.map { zipFile } }.map { zipFile }
} }
val skijaDir = run { val skijaDir = run {
if (properties.skijaDir != null) { if (skiko.skijaDir != null) {
tasks.register("skijaDir", DefaultTask::class) { tasks.register("skijaDir", DefaultTask::class) {
enabled = false enabled = false
}.map { properties.skijaDir!! } }.map { skiko.skijaDir!! }
} else { } else {
val skijaDest = properties.dependenciesDir.resolve("skija/skija").apply { mkdirs() } val skijaDest = skiko.dependenciesDir.resolve("skija/skija").apply { mkdirs() }
tasks.register("unzipSkija", Copy::class) { tasks.register("unzipSkija", Copy::class) {
from(skijaZip.map { zipTree(it) }) { from(skijaZip.map { zipTree(it) }) {
include("skija-${properties.skijaCommitHash}/**") include("skija-${skiko.skijaCommitHash}/**")
eachFile { eachFile {
// drop skija-<COMMIT> subdir // drop skija-<COMMIT> subdir
relativePath = RelativePath(true, *relativePath.segments.drop(1).toTypedArray()) relativePath = RelativePath(true, *relativePath.segments.drop(1).toTypedArray())
...@@ -132,6 +130,8 @@ val skijaDir = run { ...@@ -132,6 +130,8 @@ val skijaDir = run {
} }
} }
val lombok by configurations.creating val lombok by configurations.creating
val jetbrainsAnnotations by configurations.creating val jetbrainsAnnotations by configurations.creating
dependencies { dependencies {
...@@ -366,7 +366,7 @@ library { ...@@ -366,7 +366,7 @@ library {
withType(VisualCpp::class.java) { withType(VisualCpp::class.java) {
// In some cases Gradle is unable to find VC++ toolchain // In some cases Gradle is unable to find VC++ toolchain
// https://github.com/gradle/gradle-native/issues/617 // https://github.com/gradle/gradle-native/issues/617
properties.visualStudioBuildToolsDir?.let { skiko.visualStudioBuildToolsDir?.let {
setInstallDir(it) setInstallDir(it)
} }
} }
...@@ -504,32 +504,3 @@ publishing { ...@@ -504,32 +504,3 @@ publishing {
} }
} }
} }
class SkikoProperties(private val myProject: Project) {
val isCIBuild: Boolean
get() = myProject.hasProperty("teamcity")
val deployVersion: String
get() = myProject.property("deploy.version") as String
val isRelease: Boolean
get() = myProject.findProperty("deploy.release") == "true"
val skijaCommitHash: String
get() = myProject.property("dependencies.skija.git.commit") as String
val skiaReleaseForCurrentOS: String
get() = (myProject.property("dependencies.skia.$target") as String)
val visualStudioBuildToolsDir: File?
get() = System.getenv()["SKIKO_VSBT_PATH"]?.let { File(it) }?.takeIf { it.isDirectory }
val skijaDir: File?
get() = System.getenv()["SKIJA_DIR"]?.let { File(it) }?.takeIf { it.isDirectory }
val skiaDir: File?
get() = (System.getenv()["SKIA_DIR"] ?: System.getProperty("skia.dir"))?.let { File(it) }?.takeIf { it.isDirectory }
val dependenciesDir: File
get() = myProject.rootProject.projectDir.resolve("dependencies")
}
plugins {
`kotlin-dsl`
}
repositories {
mavenCentral()
jcenter()
}
dependencies {
implementation(kotlin("stdlib"))
compileOnly(gradleApi())
}
import org.gradle.api.Project
import java.io.File
val hostOs = System.getProperty("os.name")
val target = when {
hostOs == "Mac OS X" -> "macos"
hostOs == "Linux" -> "linux"
hostOs.startsWith("Win") -> "windows"
else -> throw Error("Unknown os $hostOs")
}
val jdkHome = System.getProperty("java.home") ?: error("'java.home' is null")
class SkikoProperties(private val myProject: Project) {
val isCIBuild: Boolean
get() = myProject.hasProperty("teamcity")
val deployVersion: String
get() {
val version = myProject.property("deploy.version") as String
return if (isRelease) version else "$version-SNAPSHOT"
}
val isRelease: Boolean
get() = myProject.findProperty("deploy.release") == "true"
val skijaCommitHash: String
get() = myProject.property("dependencies.skija.git.commit") as String
val skiaReleaseForCurrentOS: String
get() = (myProject.property("dependencies.skia.$target") as String)
val releaseGithubVersion: String
get() = (myProject.property("release.github.version") as String)
val releaseGithubCommit: String
get() = (myProject.property("release.github.commit") as String)
val visualStudioBuildToolsDir: File?
get() = System.getenv()["SKIKO_VSBT_PATH"]?.let { File(it) }?.takeIf { it.isDirectory }
val skijaDir: File?
get() = System.getenv()["SKIJA_DIR"]?.let { File(it) }?.takeIf { it.isDirectory }
val skiaDir: File?
get() = (System.getenv()["SKIA_DIR"] ?: System.getProperty("skia.dir"))?.let { File(it) }?.takeIf { it.isDirectory }
val dependenciesDir: File
get() = myProject.rootProject.projectDir.resolve("dependencies")
}
\ No newline at end of file
import org.kohsuke.github.*
val skiko = SkikoProperties(project)
val GITHUB_REPO = "JetBrains/skiko"
fun connectToGitHub() =
GitHubBuilder()
.withOAuthToken(System.getenv("SKIKO_GH_RELEASE_TOKEN"))
.build()
repositories {
maven("https://packages.jetbrains.team/maven/p/ui/dev")
}
val skikoArtifacts by configurations.creating
dependencies {
fun skikoDep(artifact: String) {
skikoArtifacts("org.jetbrains.skiko:$artifact:${skiko.deployVersion}") {
isTransitive = false
}
}
skikoDep("skiko-jvm")
skikoDep("skiko-jvm-runtime-windows")
skikoDep("skiko-jvm-runtime-linux")
skikoDep("skiko-jvm-runtime-macos")
}
val createGithubRelease by tasks.registering {
doLast {
check(skiko.isRelease) { "This task should only be called for releases!" }
val gh = connectToGitHub()
val githubVersion = skiko.releaseGithubVersion
val githubCommit = skiko.releaseGithubCommit
val repo = gh.getRepository("JetBrains/skiko")
val release = repo.createRelease("v$githubVersion")
.name("Version $githubVersion")
.commitish(githubCommit)
.create()
skikoArtifacts
.filter { it.extension == "jar" }
.forEach { release.uploadAsset(it, "application/zip") }
}
}
val deleteGithubRelease by tasks.registering {
doLast {
val gh = connectToGitHub()
val repo = gh.getRepository(GITHUB_REPO)
repo.listReleases().firstOrNull { it.tagName == "v${skiko.releaseGithubVersion}" }?.delete()
}
}
\ No newline at end of file
...@@ -9,3 +9,4 @@ pluginManagement { ...@@ -9,3 +9,4 @@ pluginManagement {
} }
rootProject.name = "skiko" rootProject.name = "skiko"
include("ci")
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment