Skip to content

Commit

Permalink
refactor(gradle): utility method to find dbImage
Browse files Browse the repository at this point in the history
  • Loading branch information
zero88 committed Mar 30, 2024
1 parent 251f854 commit a8aac59
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 8 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/jooqx.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ jobs:
# java: [ '8', '17', '21' ]
java: [ '8', '17' ]
os: [ 'ubuntu-latest' ]
itProfile: [ 'pg:10-alpine', 'pg:12-alpine', 'pg:14-alpine', 'pg:16-alpine', 'h2', 'mysql:8.3', 'mysql:8.0', 'mysql:5.7' ]
sonarProfile: [ 'pg:16-alpine' ]
itProfile: [ 'postgres:12-alpine', 'postgres:14-alpine', 'postgres:16-alpine', 'h2', 'mysql:8.3', 'mysql:8.0' ]
sonarProfile: [ 'postgres:16-alpine' ]
fail-fast: false
name: Test ${{ matrix.itProfile }} | Java ${{ matrix.java }} (${{ matrix.os }})
with:
Expand Down
26 changes: 23 additions & 3 deletions buildSrc/src/main/kotlin/Dependencies.kt
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import org.gradle.api.Project

private fun Map<Int, List<Int>>.ver(minor: Int, patch: Int): String = "${minor}.${this[minor]?.get(patch)}"

object UtilLibs {
Expand Down Expand Up @@ -37,7 +39,8 @@ object TestLibs {
object Version {

const val junit5 = "5.10.2"
// const val pioneer = "2.2.0" // java > 11

// const val pioneer = "2.2.0" // java > 11
const val pioneer = "1.9.1" // java 8
const val testContainer = "1.19.7"
}
Expand Down Expand Up @@ -165,8 +168,25 @@ object DatabaseLibs {

object DatabaseContainer {

val postgres = listOf("16-alpine", "14-alpine", "12-alpine")
val mysql = listOf("8.3", "8.0", "5.7")
data class Container(val defaultImage: String, val jdbcPrefix: String, val supportedVersions: List<String>) {}

enum class Containers(val container: Container) {
// https://endoflife.date/postgresql
postgres(Container("postgres:16-alpine", "postgresql", listOf("16-alpine", "14-alpine", "12-alpine"))),

// https://endoflife.date/mysql
mysql(Container("mysql:8.3", "mysql", listOf("8.3", "8.0")))
}

fun findImage(project: Project): String {
val container = Containers.valueOf(project.name).container
val version = project.findProperty("dbVersion");
val jdbcDbImage: String = when (version) {
in container.supportedVersions -> container.defaultImage.replaceAfter(":", "$version")
else -> container.defaultImage
}
return jdbcDbImage.replaceBefore(":", container.jdbcPrefix)
}
}

object ZeroLibs {
Expand Down
2 changes: 1 addition & 1 deletion integtest/mysql/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ dependencies {
}

val dialect = "org.jooq.meta.mysql.MySQLDatabase"
val dbImage = "mysql:${prop(project, "dbVersion", DatabaseContainer.mysql[0])}"
val dbImage = DatabaseContainer.findImage(project)
fun getSchema(schemaFile: String): String = "${buildDir}/resources/main/${schemaFile}"

jooq {
Expand Down
3 changes: 1 addition & 2 deletions integtest/postgres/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import cloud.playio.gradle.jooq.JooqJdbcContainer
import cloud.playio.gradle.shared.prop
import nu.studer.gradle.jooq.JooqGenerate
import org.jooq.meta.jaxb.ForcedType
import org.jooq.meta.jaxb.Logging
Expand All @@ -24,7 +23,7 @@ dependencies {
}

val dialect = "org.jooq.meta.postgres.PostgresDatabase"
val dbImage = "postgresql:${prop(project, "dbVersion", DatabaseContainer.postgres[0])}"
val dbImage = DatabaseContainer.findImage(project)
fun getSchema(schemaFile: String): String = "${buildDir}/resources/main/${schemaFile}"

jooq {
Expand Down

0 comments on commit a8aac59

Please sign in to comment.