Skip to content

Commit

Permalink
feat: Add Sentry and SonarQube (#7)
Browse files Browse the repository at this point in the history
* feat: Add Sentry and SonarQube

* feat: only upload on CI and make gradlew executable
  • Loading branch information
cranberry3148 authored Apr 22, 2024
1 parent 2186346 commit a4c1205
Show file tree
Hide file tree
Showing 5 changed files with 111 additions and 5 deletions.
38 changes: 38 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: Build

on:
push:
branches:
- main

jobs:
build:
name: Build
runs-on: ubuntu-latest
permissions: read-all
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up JDK 21
uses: actions/setup-java@v1
with:
java-version: 21
- name: Cache SonarQube packages
uses: actions/cache@v4
with:
path: ~/.sonar/cache
key: ${{ runner.os }}-sonar
restore-keys: ${{ runner.os }}-sonar
- name: Cache Gradle packages
uses: actions/cache@v4
with:
path: ~/.gradle/caches
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle') }}
restore-keys: ${{ runner.os }}-gradle
- name: Build and analyze
env:
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
SONAR_HOST_URL: ${{ secrets.SONAR_HOST_URL }}
SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }}
run: ./gradlew build sonar runSentry --info
50 changes: 45 additions & 5 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,33 @@ import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
plugins {
kotlin("jvm") version "1.9.23"
id("com.github.johnrengelman.shadow") version "8.1.1"
id("org.sonarqube") version "5.0.0.4638"
id("io.sentry.jvm.gradle") version "3.12.0"
}

sonar {
properties {
property("sonar.projectKey", "BlockVentureMC_BlockVenturePlugin_f0f84c38-f5bd-478b-871c-99d4b33cb318")
property("sonar.projectName", "BlockVenturePlugin")
}
}

sentry {
// Generates a JVM (Java, Kotlin, etc.) source bundle and uploads your source code to Sentry.
// This enables source context, allowing you to see your source
// code as part of your stack traces in Sentry.
includeSourceContext = true

org = "flawcra"
projectName = "blockventure-plugin"
authToken = System.getenv("SENTRY_AUTH_TOKEN")
}

group = "net.blockventuremc"
version = "1.0"

repositories {
mavenCentral()
maven("https://jitpack.io/")
maven("https://repo.fruxz.dev/releases/")
maven("https://repo.papermc.io/repository/maven-public/")
maven("https://nexus.flawcra.cc/repository/maven-mirrors/")
}

val exposedVersion = "0.49.0"
Expand All @@ -30,7 +47,6 @@ val deps = listOf(
"org.jetbrains.exposed:exposed-java-time:$exposedVersion",
"com.zaxxer:HikariCP:5.1.0",
"org.mariadb.jdbc:mariadb-java-client:3.3.3",
"io.sentry:sentry:6.17.0"
)


Expand All @@ -44,8 +60,32 @@ dependencies {
}
}

open class RunSentryTask : DefaultTask() {
init {
group = "io.sentry"
description = "Enables and runs the Sentry source bundling task"
}

@TaskAction
fun runSentry() {
println("Sentry task will run just before this task.")
}
}


tasks {
findByName("sentryBundleSourcesJava")?.enabled = false

register<RunSentryTask>("runSentry") {
val sentryTask = project.tasks.findByName("sentryBundleSourcesJava")
if (sentryTask != null) {
sentryTask.enabled = true
dependsOn(sentryTask)
} else {
println("Sentry task not found")
}
}

build {
dependsOn("shadowJar")
}
Expand Down
Empty file modified gradlew
100644 → 100755
Empty file.
6 changes: 6 additions & 0 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -1 +1,7 @@
pluginManagement {
repositories {
maven("https://nexus.flawcra.cc/repository/maven-mirrors/")
}
}

rootProject.name = "BlockVenturePlugin"
22 changes: 22 additions & 0 deletions src/main/resources/logback.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<configuration>
<!-- Configure the Console appender -->
<appender name="Console" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
</encoder>
</appender>

<!-- Configure the Sentry appender, overriding the logging threshold to the WARN level -->
<appender name="Sentry" class="io.sentry.logback.SentryAppender">
<options>
<dsn>https://[email protected]/37</dsn>
</options>
</appender>

<!-- Enable the Console and Sentry appenders, Console is provided as an example
of a non-Sentry logger that is set to a different logging threshold -->
<root level="INFO">
<appender-ref ref="Console" />
<appender-ref ref="Sentry" />
</root>
</configuration>

0 comments on commit a4c1205

Please sign in to comment.