diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..e4d4a56 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,19 @@ +name: Build + +on: + workflow_dispatch: + pull_request: + push: + branches: + - main + +jobs: + build: + runs-on: macos-latest + steps: + - name: Checkout sources + uses: actions/checkout@v4 + - name: Build project + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: ./gradlew build -PallWarningsAsErrors=true diff --git a/.github/workflows/code_quality.yml b/.github/workflows/code_quality.yml deleted file mode 100644 index b6f45e2..0000000 --- a/.github/workflows/code_quality.yml +++ /dev/null @@ -1,20 +0,0 @@ -name: Qodana -on: - workflow_dispatch: - pull_request: - push: - branches: - - main - -jobs: - qodana: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - with: - ref: ${{ github.event.pull_request.head.sha }} # to check out the actual pull request commit, not the merge commit - fetch-depth: 0 # a full history is required for pull request analysis - - name: 'Qodana Scan' - uses: JetBrains/qodana-action@v2024.1 - env: - QODANA_TOKEN: ${{ secrets.QODANA_TOKEN }} diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index e0d9185..821c930 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -1,7 +1,7 @@ [versions] -kotlin = "2.0.0" -kotlinDatetime = "0.6.0" -kotlinSerialization = "1.6.3" +kotlin = "2.1.10" +kotlinDatetime = "0.6.2" +kotlinSerialization = "1.8.0" [libraries] kotlin-datetime = { group = "org.jetbrains.kotlinx", name = "kotlinx-datetime", version.ref = "kotlinDatetime" } diff --git a/library/build.gradle.kts b/library/build.gradle.kts index 9defda1..600eaf0 100644 --- a/library/build.gradle.kts +++ b/library/build.gradle.kts @@ -31,6 +31,13 @@ kotlin { } } } + + compilerOptions { + val allWarningsAsErrorsArgument = "allWarningsAsErrors" + if (project.hasProperty(allWarningsAsErrorsArgument)) { + allWarningsAsErrors = (project.property(allWarningsAsErrorsArgument) == "true") + } + } } publishing { diff --git a/library/src/commonMain/kotlin/dk/spilpind/sms/api/RequestSerializerInterceptor.kt b/library/src/commonMain/kotlin/dk/spilpind/sms/api/RequestSerializerInterceptor.kt index 8a80268..b72a2b6 100644 --- a/library/src/commonMain/kotlin/dk/spilpind/sms/api/RequestSerializerInterceptor.kt +++ b/library/src/commonMain/kotlin/dk/spilpind/sms/api/RequestSerializerInterceptor.kt @@ -39,8 +39,8 @@ object RequestSerializerInterceptor : JsonTransformingSerializer(Reques ) : Exception(message) @Suppress("DEPRECATION") // Accept - private val contextActionClassMap = Context.values().associate { context -> - context.contextKey to Action.values().mapNotNull { action -> + private val contextActionClassMap = Context.entries.associate { context -> + context.contextKey to Action.entries.mapNotNull { action -> val actionClass: KSerializer? = when (context) { Context.System -> null Context.Authentication -> when (action) { diff --git a/library/src/commonMain/kotlin/dk/spilpind/sms/api/ResponseSerializerInterceptor.kt b/library/src/commonMain/kotlin/dk/spilpind/sms/api/ResponseSerializerInterceptor.kt index 0f1e92b..640a39e 100644 --- a/library/src/commonMain/kotlin/dk/spilpind/sms/api/ResponseSerializerInterceptor.kt +++ b/library/src/commonMain/kotlin/dk/spilpind/sms/api/ResponseSerializerInterceptor.kt @@ -61,7 +61,7 @@ object ResponseSerializerInterceptor : JsonTransformingSerializer(Resp } @Suppress("DEPRECATION") // Accepted - private val reactionContextClassMap = Reaction.values().associate { reaction -> + private val reactionContextClassMap = Reaction.entries.associate { reaction -> reaction.reactionKey to when (reaction) { Reaction.Informed -> createContextMap { context -> when (context) { @@ -234,7 +234,7 @@ object ResponseSerializerInterceptor : JsonTransformingSerializer(Resp mapper: (Context) -> KSerializer? ): ReactionClassMap { return ReactionClassMap.ContextBased( - serializerMap = Context.values().mapNotNull { context -> + serializerMap = Context.entries.mapNotNull { context -> val serializer = mapper(context) ?: return@mapNotNull null Pair(context, serializer) }.toMap() diff --git a/library/src/commonMain/kotlin/dk/spilpind/sms/api/core/Status.kt b/library/src/commonMain/kotlin/dk/spilpind/sms/api/core/Status.kt index 1c179d4..21fbaee 100644 --- a/library/src/commonMain/kotlin/dk/spilpind/sms/api/core/Status.kt +++ b/library/src/commonMain/kotlin/dk/spilpind/sms/api/core/Status.kt @@ -71,7 +71,7 @@ data class Status( override fun deserialize(decoder: Decoder): Type { val typeName = decoder.decodeString() - return Type.values().find { type -> + return Type.entries.find { type -> type.name.lowercase() == typeName } ?: Type.Unknown } diff --git a/library/src/commonMain/kotlin/dk/spilpind/sms/core/TimeHelper.kt b/library/src/commonMain/kotlin/dk/spilpind/sms/core/TimeHelper.kt index 6bbab3e..0c40223 100644 --- a/library/src/commonMain/kotlin/dk/spilpind/sms/core/TimeHelper.kt +++ b/library/src/commonMain/kotlin/dk/spilpind/sms/core/TimeHelper.kt @@ -32,14 +32,14 @@ object TimeHelper { fun LocalDateTime.toInstant(): Instant = toInstant(timeZone) /** - * Parses [isoDateString] to a date time object. This can e.g. parse values from [currentDateTimeString] + * Parses [isoDateString] to a date time object. This can e.g. parse a value returned by [LocalDateTime.toString] */ fun parse(isoDateString: String): LocalDateTime { return if (isoDateString.length >= 24) { // Javascript Date.toISOString() for instance returns this - isoDateString.toInstant().toLocalDateTime(timeZone) + Instant.parse(isoDateString).toLocalDateTime(timeZone) } else { - isoDateString.toLocalDateTime() + LocalDateTime.parse(isoDateString) } } diff --git a/library/src/commonMain/kotlin/dk/spilpind/sms/core/model/ModelHelper.kt b/library/src/commonMain/kotlin/dk/spilpind/sms/core/model/ModelHelper.kt index c3277f8..98bc5bd 100644 --- a/library/src/commonMain/kotlin/dk/spilpind/sms/core/model/ModelHelper.kt +++ b/library/src/commonMain/kotlin/dk/spilpind/sms/core/model/ModelHelper.kt @@ -36,7 +36,7 @@ object ModelHelper { created = created ) - val type = Event.Type.values().firstOrNull { type -> type.typeId == typeId } + val type = Event.Type.entries.firstOrNull { type -> type.typeId == typeId } ?: throw IllegalStateException("Got unknown event type: $typeId") return when (type) { @@ -72,7 +72,7 @@ object ModelHelper { tournamentId = tournamentId, teamAId = teamAId, teamBId = teamBId, - state = Game.State.values().firstOrNull { state -> state.identifier == gameState } + state = Game.State.entries.firstOrNull { state -> state.identifier == gameState } ?: throw IllegalStateException("Got unknown game state: $gameState"), teamAPoints = teamAPoints, teamBPoints = teamBPoints, diff --git a/library/src/commonMain/kotlin/dk/spilpind/sms/core/model/PendingRequest.kt b/library/src/commonMain/kotlin/dk/spilpind/sms/core/model/PendingRequest.kt index d203eca..6fe5bc9 100644 --- a/library/src/commonMain/kotlin/dk/spilpind/sms/core/model/PendingRequest.kt +++ b/library/src/commonMain/kotlin/dk/spilpind/sms/core/model/PendingRequest.kt @@ -134,7 +134,7 @@ sealed interface PendingRequest { * Finds a [Type] based on the provided parameters or throw an [IllegalArgumentException] if not found */ fun findType(contextIdentifier: String, requestIdentifier: String): Type { - val context = PendingRequestContext.values().firstOrNull { context -> + val context = PendingRequestContext.entries.firstOrNull { context -> context.context.contextKey == contextIdentifier } @@ -160,7 +160,7 @@ sealed interface PendingRequest { } null -> throw IllegalArgumentException( "Context \"$contextIdentifier\" of pending request not found. Available contexts: ${ - PendingRequestContext.values().map { availableContext -> availableContext.context.contextKey } + PendingRequestContext.entries.map { availableContext -> availableContext.context.contextKey } }" ) } diff --git a/library/src/commonMain/kotlin/dk/spilpind/sms/core/model/UserRole.kt b/library/src/commonMain/kotlin/dk/spilpind/sms/core/model/UserRole.kt index 2b31c5b..d65ef46 100644 --- a/library/src/commonMain/kotlin/dk/spilpind/sms/core/model/UserRole.kt +++ b/library/src/commonMain/kotlin/dk/spilpind/sms/core/model/UserRole.kt @@ -131,7 +131,7 @@ sealed interface UserRole { * Finds a [ContextRole] based on the provided parameters or throw an [IllegalArgumentException] if not found */ fun findContext(contextIdentifier: String, roleIdentifier: String): ContextRole { - val context = RoleContext.values().firstOrNull { context -> + val context = RoleContext.entries.firstOrNull { context -> context.context.contextKey == contextIdentifier } @@ -155,7 +155,7 @@ sealed interface UserRole { } null -> throw IllegalArgumentException( "Context \"$contextIdentifier\" not found. Available contexts: " - + "${RoleContext.values().map { availableContext -> availableContext.context.contextKey }}" + + "${RoleContext.entries.map { availableContext -> availableContext.context.contextKey }}" ) } } diff --git a/qodana.yaml b/qodana.yaml deleted file mode 100644 index fe2935c..0000000 --- a/qodana.yaml +++ /dev/null @@ -1,31 +0,0 @@ -#-------------------------------------------------------------------------------# -# Qodana analysis is configured by qodana.yaml file # -# https://www.jetbrains.com/help/qodana/qodana-yaml.html # -#-------------------------------------------------------------------------------# -version: "1.0" - -#Specify inspection profile for code analysis -profile: - name: qodana.starter - -#Enable inspections -#include: -# - name: - -#Disable inspections -#exclude: -# - name: -# paths: -# - - -projectJDK: 15 #(Applied in CI/CD pipeline) - -#Execute shell command before Qodana execution (Applied in CI/CD pipeline) -#bootstrap: sh ./prepare-qodana.sh - -#Install IDE plugins before Qodana execution (Applied in CI/CD pipeline) -#plugins: -# - id: #(plugin id can be found at https://plugins.jetbrains.com) - -#Specify Qodana linter for analysis (Applied in CI/CD pipeline) -linter: jetbrains/qodana-jvm-community:latest