Skip to content
New issue

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

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

Already on GitHub? # to your account

Packaging #10

Merged
merged 1 commit into from
Jun 17, 2020
Merged
Show file tree
Hide file tree
Changes from all 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
42 changes: 42 additions & 0 deletions .github/workflows/deploy-snapshot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: Deploy Snapshot

on:
push:
branches:
- master

jobs:
gradle:
runs-on: ubuntu-latest
if: ${{ !contains(github.event.head_commit.message, 'ci skip') }}
env:
GRADLE_OPTS: -Dorg.gradle.daemon=false
steps:
- name: Checkout Repo
uses: actions/checkout@v2

- name: Cache Gradle Folders
uses: actions/cache@v2
with:
path: |
~/.gradle/caches/
~/.gradle/wrapper/
key: cache-gradle-${{ hashFiles('kile-bom/build.gradle.kts') }}
restore-keys: |
cache-gradle-

- name: Setup Java
uses: actions/setup-java@v1
with:
java-version: 8

- name: Build kile
run: ./gradlew build --build-cache --parallel -PwarningsAsErrors=true

- name: Deploy Snapshot to Github Packages
if: ${{ github.repository == 'RealAd/kile'}}
env:
REPOSITORY_USERNAME: $GITHUB_ACTOR
REPOSITORY_PASSWORD: ${{ secrets.GITHUB_TOKEN }}
run: |
./gradlew publish --stacktrace
115 changes: 16 additions & 99 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,112 +1,29 @@
import io.gitlab.arturbosch.detekt.Detekt
import io.gitlab.arturbosch.detekt.DetektPlugin
import org.jetbrains.dokka.gradle.DokkaTask

plugins {
jacoco
kotlin("multiplatform") version Libs.kotlinVersion
id("org.sonarqube") version Libs.sonarqubeVersion
id("io.gitlab.arturbosch.detekt") version Libs.detektVersion
id("org.jetbrains.dokka") version Libs.dokkaVersion
id("com.github.ben-manes.versions") version Libs.gradleVersionsPluginVersion
}

jacoco {
toolVersion = "0.8.5"
}

sonarqube {
properties {
property("sonar.organization", "realad")
property("sonar.projectKey", "io.realad.kile")
property("sonar.java.coveragePlugin", "jacoco")
property("sonar.coverage.jacoco.xmlReportPaths", "$buildDir/reports/jacoco/jacocoTestReport/jacocoTestReport.xml")
property("sonar.kotlin.detekt.reportPaths", "$buildDir/reports/detekt/detekt.xml")
}
detekt
coverage
dokka
sonarqube
versions
}

tasks {
withType<DokkaTask> {
outputFormat = "html"
outputDirectory = "$buildDir/dokka"
subProjects = listOf("core", "fp")
}

// Inspired by https://docs.gradle.org/6.5/samples/sample_jvm_multi_project_with_code_coverage.html
val jacocoTestReport by register<JacocoReport>("jacocoTestReport") {
val excludes = listOf("**/*Test*.*")
val sourceDirs = arrayListOf<Any>()
val classDirs = arrayListOf<Any>()
val executionDataDirs = arrayListOf<Any>()
subprojects
.filter { subproject -> subproject.plugins.hasPlugin(JacocoPlugin::class) }
.forEach { subproject ->
sourceDirs.addAll(subproject.projectDir.listFiles { file -> file.name == "src" }
?.flatMap { src -> src.listFiles { file -> file.name.endsWith("Main") }?.toList() ?: listOf() }
?.flatMap { main -> main.listFiles { file -> file.name == "kotlin" }?.toList() ?: listOf() }
?.map { kotlin -> kotlin.path } ?: listOf())
classDirs.add(fileTree("${subproject.buildDir}/classes/kotlin/jvm/").exclude(excludes))
executionDataDirs.add(fileTree("${subproject.buildDir}/jacoco/").include("*.exec"))
subproject.tasks.matching { it.extensions.findByType<JacocoTaskExtension>() != null }.forEach {
rootProject.tasks["jacocoTestReport"].dependsOn(it)
}
}
sourceDirectories.setFrom(files(sourceDirs))
classDirectories.setFrom(files(classDirs))
executionData.setFrom(files(executionDataDirs))
reports {
xml.isEnabled = true
html.isEnabled = true
}
}
}

subprojects {
val subproject = this
apply<DetektPlugin>()
apply<JacocoPlugin>()

jacoco {
reportsDir = file("${subproject.buildDir}/reports/jacoco/")
}

sonarqube {
properties {
val dirs = file("src").listFiles()
?.mapNotNull { it.path.substring("${subproject.projectDir.path}/".length) } ?: listOf()

val sources = dirs.filter { it.contains("Main") }
val tests = dirs.filter { it.contains("Test") }

property("sonar.sources", sources.joinToString(","))
property("sonar.tests", tests.joinToString(","))
property(
"sonar.exclusions", "**/jsMain/**,**/jsTest/**," +
"**/src/commonMain/kotlin/io/realad/kile/adapters/ftp/FtpConnectionOptions.kt," +
"**/src/commonMain/kotlin/io/realad/kile/adapters/ftp/FtpConnectionProvider.kt"
)
property("sonar.kotlin.detekt.reportPaths", "${subproject.buildDir}/reports/detekt/detekt.xml")
}
}

tasks {
withType<Detekt> {
parallel = true
ignoreFailures = true
setSource(files("src"))
include("**/*.kt")
exclude("**/resources/**")
}
}
// Configure existing Dokka task to output HTML to typical Javadoc directory
tasks.dokka {
outputFormat = "html"
outputDirectory = "$buildDir/javadoc"
}

allprojects {
repositories {
mavenCentral()
jcenter()
google()
}

group = "io.realad.kile"
version = "0.0.0"
version = Ci.publishVersion.value
}

subprojects {
apply{
plugin("kotlin-multiplatform")
}
}
59 changes: 59 additions & 0 deletions buildSrc/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,65 @@ plugins {
`kotlin-dsl`
}

kotlinDslPluginOptions {
experimentalWarning.set(false)
}

repositories {
jcenter()
}

/**
* Information about gradle plugins and their versions.
*/
object Plugins {

/**
* https://mvnrepository.com/artifact/org.jetbrains.kotlin/kotlin-gradle-plugin
*/
object Kotlin {
private const val version = "1.3.72"
const val gradlePlugin = "org.jetbrains.kotlin:kotlin-gradle-plugin:$version"
}

/**
* https://plugins.gradle.org/plugin/io.gitlab.arturbosch.detekt
*/
object Detekt {
private const val version = "1.9.1"
const val gradlePlugin = "io.gitlab.arturbosch.detekt:detekt-gradle-plugin:$version"
}

/**
* https://plugins.gradle.org/plugin/org.jetbrains.dokka
*/
object Dokka {
private const val version = "0.10.1"
const val gradlePlugin = "org.jetbrains.dokka:dokka-gradle-plugin:$version"
}

/**
* https://plugins.gradle.org/plugin/org.sonarqube
*/
object SonarQube {
private const val version = "3.0"
const val gradlePlugin = "org.sonarsource.scanner.gradle:sonarqube-gradle-plugin:$version"
}

/**
* https://plugins.gradle.org/plugin/com.github.ben-manes.versions
*/
object GradleVersions {
private const val version = "0.28.0"
const val gradlePlugin = "com.github.ben-manes:gradle-versions-plugin:$version"
}

}

dependencies {
implementation(Plugins.Kotlin.gradlePlugin)
implementation(Plugins.Detekt.gradlePlugin)
implementation(Plugins.Dokka.gradlePlugin)
implementation(Plugins.SonarQube.gradlePlugin)
implementation(Plugins.GradleVersions.gradlePlugin)
}
15 changes: 15 additions & 0 deletions buildSrc/src/main/kotlin/Ci.kt
Original file line number Diff line number Diff line change
@@ -1,4 +1,19 @@
object Ci {
private val isGithub = System.getenv("GITHUB_ACTIONS") == "true"
private val githubBuildNumber: String = System.getenv("GITHUB_RUN_NUMBER") ?: "0"
val isReleaseVersion = !isGithub

val ideaActive = System.getProperty("idea.active") == "true"
val os = org.gradle.internal.os.OperatingSystem.current()

private val snapshotBuildNumber = lazy {
Runtime.getRuntime().exec("git rev-list --count master")
val number = System.`in`.bufferedReader().read()
println("Snapshot build number: $number")
number
}

private const val releaseVersion = "0.0.0"
private val snapshotVersion = lazy { "0.0.0.${githubBuildNumber}-SNAPSHOT" }
val publishVersion = lazy { if (isReleaseVersion) releaseVersion else snapshotVersion.value }
}
6 changes: 0 additions & 6 deletions buildSrc/src/main/kotlin/Libs.kt
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
object Libs {

const val kotlinVersion = "1.3.72"
const val dokkaVersion = "0.10.1"
const val gradleVersionsPluginVersion = "0.28.0"
const val sonarqubeVersion = "3.0"
const val detektVersion = "1.9.1"

object Napier {
private const val version = "1.3.0"
const val common = "com.github.aakira:napier:$version"
Expand Down
46 changes: 46 additions & 0 deletions buildSrc/src/main/kotlin/coverage.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
plugins {
jacoco
}

jacoco {
toolVersion = "0.8.5"
}

tasks {
// Inspired by https://docs.gradle.org/6.5/samples/sample_jvm_multi_project_with_code_coverage.html
val jacocoTestReport by register<JacocoReport>("jacocoTestReport") {
val excludes = listOf("**/*Test*.*")
val sourceDirs = arrayListOf<Any>()
val classDirs = arrayListOf<Any>()
val executionDataDirs = arrayListOf<Any>()
subprojects
.filter { subproject -> subproject.plugins.hasPlugin(JacocoPlugin::class) }
.forEach { subproject ->
sourceDirs.addAll(subproject.projectDir.listFiles { file -> file.name == "src" }
?.flatMap { src -> src.listFiles { file -> file.name.endsWith("Main") }?.toList() ?: listOf() }
?.flatMap { main -> main.listFiles { file -> file.name == "kotlin" }?.toList() ?: listOf() }
?.map { kotlin -> kotlin.path } ?: listOf())
classDirs.add(fileTree("${subproject.buildDir}/classes/kotlin/jvm/").exclude(excludes))
executionDataDirs.add(fileTree("${subproject.buildDir}/jacoco/").include("*.exec"))
subproject.tasks.matching { it.extensions.findByType<JacocoTaskExtension>() != null }.forEach {
rootProject.tasks["jacocoTestReport"].dependsOn(it)
}
}
sourceDirectories.setFrom(files(sourceDirs))
classDirectories.setFrom(files(classDirs))
executionData.setFrom(files(executionDataDirs))
reports {
xml.isEnabled = true
html.isEnabled = true
}
}
}

subprojects {
val subproject = this
apply<JacocoPlugin>()

jacoco {
reportsDir = file("${subproject.buildDir}/reports/jacoco/")
}
}
20 changes: 20 additions & 0 deletions buildSrc/src/main/kotlin/detekt.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import io.gitlab.arturbosch.detekt.Detekt
import io.gitlab.arturbosch.detekt.DetektPlugin

plugins {
id("io.gitlab.arturbosch.detekt")
}

subprojects {
apply<DetektPlugin>()

tasks {
withType<Detekt> {
parallel = true
ignoreFailures = true
setSource(files("src"))
include("**/*.kt")
exclude("**/resources/**")
}
}
}
22 changes: 22 additions & 0 deletions buildSrc/src/main/kotlin/dokka.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import org.jetbrains.dokka.gradle.DokkaPlugin
import org.jetbrains.dokka.gradle.DokkaTask

plugins {
id("org.jetbrains.dokka")
}

subprojects {
apply<DokkaPlugin>()

tasks {
val dokka by getting(DokkaTask::class) {
outputDirectory = "$buildDir/dokka"
outputFormat = "html"

multiplatform {
val js by creating
val jvm by creating
}
}
}
}
Loading