Skip to content

Commit

Permalink
Merge branch 'feature/github-upload' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
gciatto committed Apr 15, 2020
2 parents eeb9742 + 8ad125e commit 55031ea
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 10 deletions.
15 changes: 12 additions & 3 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ variables:
BINTRAY_TASK: "publishAllToBintray"
JS_COMPILE_TASK: "clean jsMain"
NPM_PUBLISH_TASK: "npmPublish"
GITHUB_PUBLISH_TASK: "githubRelease"
PAGES_TASK: "orchidBuild"
ORG_GRADLE_PROJECT_orchidBaseUrl: "https://pika-lab.gitlab.io/tuprolog/2p-in-kotlin/"

Expand All @@ -21,9 +22,7 @@ before_script:

cache:
paths:
- $HOME/.gradle/caches
- $HOME/.gradle/wrapper
- $HOME/.gradle/nodejs
- $HOME/.gradle/
- gradle/
- .gradle/

Expand Down Expand Up @@ -59,6 +58,16 @@ Deploy to NPM:
only:
- /^(master)|(release)|(develop)$/

Deploy to GitHub:
stage: deploy
script:
- $GCMD $BEFORE_TASK $GITHUB_PUBLISH_TASK $AFTER_TASK $GOPTS
environment:
name: GitHub
url: "https://github.com/tuProlog/2p-kt/releases"
only:
- /^(master)|(release)|(develop)$/

pages:
script:
- mkdir public
Expand Down
55 changes: 48 additions & 7 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import com.github.breadmoirai.githubreleaseplugin.GithubReleaseExtension
import com.github.breadmoirai.githubreleaseplugin.GithubReleaseTask
import com.jfrog.bintray.gradle.tasks.BintrayUploadTask
import node.Bugs
import node.NpmPublishExtension
Expand All @@ -19,6 +21,7 @@ plugins {
id("com.jfrog.bintray") version Versions.com_jfrog_bintray_gradle_plugin
id("org.danilopianini.git-sensitive-semantic-versioning") version Versions.org_danilopianini_git_sensitive_semantic_versioning_gradle_plugin
id("de.fayard.buildSrcVersions") version Versions.de_fayard_buildsrcversions_gradle_plugin
id("com.github.breadmoirai.github-release") version Versions.com_github_breadmoirai_github_release_gradle_plugin
}

repositories {
Expand Down Expand Up @@ -49,13 +52,17 @@ val bintrayRepo: String by project
val bintrayUserOrg: String by project
val projectLicense: String by project
val projectIssues: String by project
val githubOwner: String by project
val githubRepo: String by project

val signingKey = getPropertyOrWarnForAbsence("signingKey")
val signingPassword = getPropertyOrWarnForAbsence("signingPassword")
val bintrayUser = getPropertyOrWarnForAbsence("bintrayUser")
val bintrayKey = getPropertyOrWarnForAbsence("bintrayKey")
val ossrhUsername = getPropertyOrWarnForAbsence("ossrhUsername")
val ossrhPassword = getPropertyOrWarnForAbsence("ossrhPassword")
val githubToken = getPropertyOrWarnForAbsence("githubToken")
val npmToken = getPropertyOrWarnForAbsence("npmToken")

val allSubprojects = subprojects.map { it.name }.toSet()
val jvmSubprojects = setOf("parser-jvm")
Expand Down Expand Up @@ -165,6 +172,7 @@ ktSubprojects.forEachProject {
configureUploadToBintray("kotlinMultiplatform", "js", "jvm", "metadata")
configureSigning()
configureJsPackage()
configureUploadToGithub({ "jvm" in it })
}

jvmSubprojects.forEachProject {
Expand All @@ -180,6 +188,7 @@ jvmSubprojects.forEachProject {
configureUploadToMavenCentral()
configureUploadToBintray()
configureSigning()
configureUploadToGithub()
}

jsSubprojects.forEachProject {
Expand All @@ -196,6 +205,41 @@ jsSubprojects.forEachProject {
configureSigning()
}

configure<GithubReleaseExtension> {
token(githubToken)
owner(githubOwner)
repo(githubRepo)
tagName { version.toString() }
releaseName { version.toString() }
allowUploadToExisting { true }
prerelease { !isFullVersion }
draft { false }
body(
"""|## CHANGELOG
|${changelog().call()}
""".trimMargin()
)
}

fun Project.configureUploadToGithub(
jarTaskPositiveFilter: (String) -> Boolean = { "jar" in it },
jarTaskNegativeFilter: (String) -> Boolean = { "dokka" in it || "source" in it }
) {
val jarTasks = tasks.withType(Jar::class).asSequence()
.filter { jarTaskPositiveFilter(it.name.toLowerCase()) }
.filter { !jarTaskNegativeFilter(it.name.toLowerCase()) }
.map { it.archiveFile }
.toList()

rootProject.configure<GithubReleaseExtension> {
releaseAssets(*(releaseAssets.toList() + jarTasks).toTypedArray())
}

rootProject.tasks.withType(GithubReleaseTask::class) {
dependsOn(*jarTasks.toTypedArray())
}
}

fun Project.configureDokka(vararg platforms: String) {
tasks.withType<DokkaTask> {
outputDirectory = docDir
Expand All @@ -206,10 +250,9 @@ fun Project.configureDokka(vararg platforms: String) {
platforms.forEach { registerPlatform(it) }
}
}

}

task<DefaultTask>("packAllDokka") {
val packAllDokka: DefaultTask by tasks.creating(DefaultTask::class.java) {
group = "documentation"
}

Expand All @@ -229,7 +272,7 @@ fun Project.configureDokka(vararg platforms: String) {
archiveClassifier.set("javadoc")
}

tasks.getByName("packAllDokka").dependsOn(packDokkaForPlatform)
packAllDokka.dependsOn(packDokkaForPlatform)
}
} else {
val packDokka by tasks.creating(Jar::class) {
Expand All @@ -241,7 +284,7 @@ fun Project.configureDokka(vararg platforms: String) {
archiveClassifier.set("javadoc")
}

tasks.getByName("packAllDokka").dependsOn(packDokka)
packAllDokka.dependsOn(packDokka)
}
}

Expand Down Expand Up @@ -393,11 +436,9 @@ fun NamedDomainObjectContainerScope<GradlePassConfigurationImpl>.registerPlatfor
fun Project.configureJsPackage(packageJsonTask: String = "jsPackageJson", compileTask: String = "jsMainClasses") {
apply<NpmPublishPlugin>()

val npmToken: String by this

configure<NpmPublishExtension> {
nodeRoot = rootProject.tasks.withType<NodeJsSetupTask>().asSequence().map { it.destination }.first()
token = npmToken
token = npmToken ?: ""
packageJson = tasks.getByName<KotlinPackageJsonTask>(packageJsonTask).packageJson
nodeSetupTask = rootProject.tasks.getByName("kotlinNodeJsSetup").path
jsCompileTask = compileTask
Expand Down
5 changes: 5 additions & 0 deletions buildSrc/src/main/kotlin/Extensions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ import org.gradle.api.tasks.testing.TestResult
import org.gradle.kotlin.dsl.KotlinClosure2
import org.gradle.kotlin.dsl.withType

private val FULL_VERSION_REGEX = "^[0-9]+\\.[0-9]+\\.[0-9]+$".toRegex()

val Project.isFullVersion: Boolean
get() = version.toString().matches(FULL_VERSION_REGEX)

fun Project.configureTestResultPrinting() {
tasks.withType<AbstractTestTask> {
afterSuite(KotlinClosure2({ desc: TestDescriptor, result: TestResult ->
Expand Down
4 changes: 4 additions & 0 deletions buildSrc/src/main/kotlin/Libs.kt
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@ object Libs {
"org.danilopianini.git-sensitive-semantic-versioning:org.danilopianini.git-sensitive-semantic-versioning.gradle.plugin:" +
Versions.org_danilopianini_git_sensitive_semantic_versioning_gradle_plugin

const val com_github_breadmoirai_github_release_gradle_plugin: String =
"com.github.breadmoirai.github-release:com.github.breadmoirai.github-release.gradle.plugin:" +
Versions.com_github_breadmoirai_github_release_gradle_plugin

const val org_jetbrains_kotlin_multiplatform_gradle_plugin: String =
"org.jetbrains.kotlin.multiplatform:org.jetbrains.kotlin.multiplatform.gradle.plugin:" +
Versions.org_jetbrains_kotlin_multiplatform_gradle_plugin
Expand Down
2 changes: 2 additions & 0 deletions buildSrc/src/main/kotlin/Versions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ object Versions {

const val org_danilopianini_git_sensitive_semantic_versioning_gradle_plugin: String = "0.2.2"

const val com_github_breadmoirai_github_release_gradle_plugin: String = "2.2.12"

const val org_jetbrains_kotlin_multiplatform_gradle_plugin: String = "1.3.72"

const val de_fayard_buildsrcversions_gradle_plugin: String = "0.7.0"
Expand Down
5 changes: 5 additions & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ bintrayKey=
# NPM
npmToken=

# GitHub
githubToken=
githubOwner=tuProlog
githubRepo=2p-kt

# Misc
sonatypeUrl=https://oss.sonatype.org/content/repositories/snapshots/
gcName=Giovanni Ciatto
Expand Down

0 comments on commit 55031ea

Please sign in to comment.