Skip to content

Commit

Permalink
Restructure project, add integration tests, gradle for github issues (#…
Browse files Browse the repository at this point in the history
…32)

* chore: remove old typescript launch options

* chore: update gradle to 8.12, use source/javadoc version

* refactor(gradle): Create version catalog for dependencies

* refactor(gradle): Create convention plugin

* build: create plugin for remote integration test (testing in prod)

* build: create plugin for creating/closing github issues based on test results

* refactor: Split project to modules, seperate by 'internal' keyword, add HTLBProxyServer class for testing

* build: Add caching and parallel execution, disable conf cache

Configuration cache is disabled because Gradle returns errors when
you execute github issue plugins

* refactor(IDE): Change "run server" to server module and port to 13370

* build(docker): Update gradle version, jdk to 23, use new path to jar

* fix(parsing): When value cannot be parsed, return null instead of 0

* cleanup(gradle): Remove useless parentheses
  • Loading branch information
DareFox authored Jan 22, 2025
1 parent 0659d30 commit f18f4d1
Show file tree
Hide file tree
Showing 60 changed files with 950 additions and 162 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="Run 256M app at :1337" type="JetRunConfigurationType">
<configuration default="false" name="Run 256M app at :13370" type="JetRunConfigurationType">
<envs>
<env name="PORT" value="1337" />
<env name="PORT" value="13370" />
</envs>
<option name="MAIN_CLASS_NAME" value="io.github.darefox.hltbproxy.MainKt" />
<module name="HowLongToBeat-Proxy-API.main" />
<module name="HowLongToBeat-Proxy-API.server.main" />
<shortenClasspath name="NONE" />
<option name="VM_PARAMETERS" value="-Xmx256M" />
<method v="2">
Expand Down
16 changes: 0 additions & 16 deletions .vscode/launch.json

This file was deleted.

10 changes: 5 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
FROM gradle:8.10.1-jdk21 AS build
FROM gradle:8.12.0-jdk23 AS build
COPY --chown=gradle:gradle . /home/gradle/src
WORKDIR /home/gradle/src
RUN gradle shadowJar --no-daemon
RUN gradle :server:shadowJar --no-daemon

FROM eclipse-temurin:21-jre-alpine
FROM eclipse-temurin:23-jre-alpine

COPY --from=build /home/gradle/src/build/libs/ /app/
ENTRYPOINT ["java","-jar","/app/HowLongToBeat-Proxy-API-1.0-SNAPSHOT-all.jar"]
COPY --from=build /home/gradle/src/server/build/libs/ /app/
ENTRYPOINT ["java","-jar","/app/server-all.jar"]
62 changes: 0 additions & 62 deletions build.gradle.kts

This file was deleted.

38 changes: 38 additions & 0 deletions buildSrc/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
plugins {
// The Kotlin DSL plugin provides a convenient way to develop convention plugins.
// Convention plugins are located in `src/main/kotlin`, with the file extension `.gradle.kts`,
// and are applied in the project's `build.gradle.kts.backup` files as required.
`kotlin-dsl`
alias(libs.plugins.kotlinSerialization)
idea
}


idea {
module {
isDownloadJavadoc = true
isDownloadSources = true
}
}

kotlin {
jvmToolchain(23)
}

java {
toolchain {
languageVersion = JavaLanguageVersion.of(23)
}
}

dependencies {
// Add a dependency on the Kotlin Gradle plugin, so that convention plugins can apply it.
implementation(libs.kotlinGradlePlugin)
implementation(libs.bundles.kotlinxXml)
implementation(libs.githubApi)
testImplementation(kotlin("test"))
}

tasks.test {
useJUnitPlatform()
}
15 changes: 15 additions & 0 deletions buildSrc/settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
dependencyResolutionManagement {

// Use Maven Central and the Gradle Plugin Portal for resolving dependencies in the shared build logic (`buildSrc`) project.
@Suppress("UnstableApiUsage")
repositories {
mavenCentral()
}

// Reuse the version catalog from the main build.
versionCatalogs {
create("libs") {
from(files("../gradle/libs.versions.toml"))
}
}
}
86 changes: 86 additions & 0 deletions buildSrc/src/main/kotlin/MarkdownConverter.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
import junitParse.TestCase
import junitParse.TestSuite

object MarkdownConverter {
fun convert(tests: List<TestSuite>): Sequence<String> {
require(tests.isNotEmpty()) { "There's no tests to convert to markdown" }
return sequence {
for ((index, test) in tests.withIndex()) {
if (index != 0) {
yield("-----------")
}
yield(test.toMarkdown())
}
}
}

private fun markdownDetails(summary: String, content: () -> String): String {
return """
|<details>
|<summary>$summary</summary>
|
|${content()}
|
|</details>
""".trimMargin("|")
}

private fun TestSuite.toMarkdown(): String {
val markdownCases = cases.joinToString(separator = "\n") { it.toMarkdown() }
val markdownStdout = markdownDetails("STDOUT") {
"""
|```java
|${systemOut.data}
|```
""".trimMargin("|")
}
val markdownStderr = markdownDetails("STDERR") {
"""
|```java
|${systemErr.data}
|```
""".trimMargin("|")
}


return """
|# ${this.name}
|- Tests: ${this.tests}
|- Skipped: ${this.skipped}
|- Failures: ${this.failures}
|- Errors: ${this.failures}
|- Timestamp: ${this.timestamp}
|- Execution time: ${this.time}
|
|## Cases
|$markdownCases
|
|## Outputs
|$markdownStdout
|
|$markdownStderr
""".trimMargin("|")
}


private fun TestCase.toMarkdown(): String {
val emojiStatus = if (this.failure == null) "" else ""
val failureDetails = failure?.run {
"""
|- Error type: `$type`
|- Message:
|```java
|$message
|```
|
""".trimMargin("|")
}
return markdownDetails("$name $emojiStatus") {
"""
|- Classname: $classname
|- Execution time: $time
|${failureDetails ?: ""}
""".trimMargin("|")
}
}
}
35 changes: 35 additions & 0 deletions buildSrc/src/main/kotlin/convention.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
plugins {
kotlin("jvm")
idea
}

group = "io.github.darefox"

repositories {
mavenCentral()
}

kotlin {
jvmToolchain(23)
}

java {
toolchain {
languageVersion = JavaLanguageVersion.of(23)
}
}

idea {
module {
isDownloadJavadoc = true
isDownloadSources = true
}
}

dependencies {
testImplementation(kotlin("test"))
}

tasks.test {
useJUnitPlatform()
}
24 changes: 24 additions & 0 deletions buildSrc/src/main/kotlin/extendedTests.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import java.net.URL

interface RemoteTest {
val enabled: Property<Boolean>
val url: Property<URL>
}

val remoteTestExt = extensions.create<RemoteTest>("remoteTest")
remoteTestExt.enabled = false

afterEvaluate {
val tests = tasks.withType<Test>()
for (test in tests) {
val location = test.reports.junitXml.outputLocation
tasks.register<Delete>("${test.name}-cleanResults") {
setDelete(location)
}
}
}

tasks.register("remoteSystemTest") {
remoteTestExt.enabled = true
dependsOn("systemTest")
}
Loading

0 comments on commit f18f4d1

Please sign in to comment.