From 88b1065414853a687dd95765c13f955b4b14a675 Mon Sep 17 00:00:00 2001 From: FyloZ Date: Thu, 4 Mar 2021 13:05:23 -0500 Subject: [PATCH] CI/CD --- .gitlab-ci.yml | 22 +++++++++ build.gradle.kts | 47 ++++++++++++++++++- settings.gradle.kts | 2 +- .../databasemanager/Database.kt | 2 +- 4 files changed, 69 insertions(+), 4 deletions(-) create mode 100644 .gitlab-ci.yml diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml new file mode 100644 index 0000000..4c9afe1 --- /dev/null +++ b/.gitlab-ci.yml @@ -0,0 +1,22 @@ +image: gradle:$GRADLE_VERSION-jdk$JDK_VERSION + +stages: + - test + - deploy + +test: + stage: test + script: + - gradle test + artifacts: + when: always + reports: + junit: build/test-results/test/TEST-*.xml + +deploy-maven: + stage: deploy + needs: [ 'test' ] + only: + - master + script: + docker publish diff --git a/build.gradle.kts b/build.gradle.kts index 6ed2868..6b5b4b1 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -5,10 +5,13 @@ version = "1.0" plugins { kotlin("jvm") version "1.4.30" + id("org.jetbrains.dokka") version "1.4.20" + id("maven-publish") id("com.github.johnrengelman.shadow") version "6.1.0" } repositories { + jcenter() mavenCentral() } @@ -21,15 +24,51 @@ dependencies { implementation("ch.qos.logback:logback-classic:1.0.13") // Database drivers - implementation("mysql:mysql-connector-java:8.0.22") + runtimeOnly("com.h2database:h2:1.4.199") + runtimeOnly("mysql:mysql-connector-java:8.0.22") + runtimeOnly("org.postgresql:postgresql:42.2.16") + runtimeOnly("com.microsoft.sqlserver:mssql-jdbc:9.2.1.jre11") testImplementation("io.mockk:mockk:1.10.6") testImplementation("io.kotest:kotest-runner-junit5:4.4.1") - implementation(kotlin("stdlib-jdk8")) +} + +publishing { + publications { + create("cre-database-manager") { + from(components["kotlin"]) + } + } + + repositories { + maven { + url = uri("https://git.fyloz.dev/api/v4/projects/40/packages/maven") + name = "Gitlab" + + credentials(HttpHeaderCredentials::class.java) { + val gitlabPrivateTokens: String? by project + + name = "Private-Token" + value = gitlabPrivateTokens ?: System.getenv("CI_JOB_TOKEN") + } + authentication { + create("header") + } + } + } } tasks.test { useJUnitPlatform() + + testLogging { + events("failed") + } + + reports { + junitXml.isEnabled = true + html.isEnabled = false + } } tasks.withType() { @@ -42,3 +81,7 @@ tasks.withType { attributes["Main-Class"] = "dev.fyloz.colorrecipesexplorer.databasemanager.DatabaseUpdaterKt" } } + +tasks.dokkaHtml { + outputDirectory.set(rootDir.resolve("dokka")) +} diff --git a/settings.gradle.kts b/settings.gradle.kts index 10ee092..b919f24 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -1,3 +1,3 @@ -rootProject.name = "DatabaseManager" +rootProject.name = "database-manager" diff --git a/src/main/kotlin/dev/fyloz/colorrecipesexplorer/databasemanager/Database.kt b/src/main/kotlin/dev/fyloz/colorrecipesexplorer/databasemanager/Database.kt index 2f18b02..f5ad381 100644 --- a/src/main/kotlin/dev/fyloz/colorrecipesexplorer/databasemanager/Database.kt +++ b/src/main/kotlin/dev/fyloz/colorrecipesexplorer/databasemanager/Database.kt @@ -54,7 +54,7 @@ class CreDatabase( } private var databaseOpen = false - val database by lazy { + private val database by lazy { DatabaseFactory.getInstance().findCorrectDatabaseImplementation(JdbcConnection(databaseConnection)) .apply { databaseOpen = true } }