From c2717479ba4fd5aa8bc4acca27d70c498be8a55e Mon Sep 17 00:00:00 2001 From: DatLag Date: Fri, 30 Aug 2024 03:57:25 +0200 Subject: [PATCH] check dependency versions --- .github/workflows/dependency-versions.yml | 52 ++++++++++++++ build.gradle.kts | 86 +++++++++++++++++++++++ gradle.properties | 9 ++- gradle/libs.versions.toml | 4 +- 4 files changed, 149 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/dependency-versions.yml diff --git a/.github/workflows/dependency-versions.yml b/.github/workflows/dependency-versions.yml new file mode 100644 index 0000000..d62ada3 --- /dev/null +++ b/.github/workflows/dependency-versions.yml @@ -0,0 +1,52 @@ +name: Check Dependency Versions +on: + push: + +jobs: + dependency-versions: + runs-on: ubuntu-latest + + permissions: + checks: write + pull-requests: write + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Setup Java + uses: actions/setup-java@v4 + with: + distribution: temurin + java-version: 17 + + - name: Setup Gradle + uses: gradle/actions/setup-gradle@v3 + + - name: Check Dependency Versions + run: ./gradlew dependencyUpdates + + - name: Publish version results + run: | + ruby << 'EOF' | gh api -X POST '/repos/${{ github.repository }}/check-runs' --input - + require 'json' + report = { + name: ENV.fetch('REPORT_CHECK_NAME'), + head_sha: ENV.fetch('REPORT_SHA'), + status: 'completed', + conclusion: ENV.fetch('REPORT_CONCLUSION'), + output: { + title: ENV.fetch('REPORT_CHECK_OUTPUT_TITLE'), + summary: File.read(ENV.fetch('REPORT_CHECK_OUTPUT_SUMMARY_FILE')), + }, + } + puts report.to_json + EOF + env: + REPORT_SHA: ${{ github.event.pull_request.head.sha || github.sha }} + GITHUB_TOKEN: ${{ github.token }} + REPORT_CHECK_NAME: Version Results + REPORT_CHECK_OUTPUT_TITLE: ${{ github.event.repository.updated_at }} + REPORT_CHECK_OUTPUT_SUMMARY_FILE: build/dependencyUpdates/report.md + REPORT_CONCLUSION: ${{ job.status }} + shell: bash \ No newline at end of file diff --git a/build.gradle.kts b/build.gradle.kts index 0365c73..e63624c 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,3 +1,4 @@ +import com.github.benmanes.gradle.versions.updates.DependencyUpdatesTask import org.jetbrains.kotlin.gradle.dsl.JvmTarget import org.jetbrains.kotlin.gradle.tasks.KotlinCompile @@ -7,6 +8,7 @@ plugins { alias(libs.plugins.vanniktech.publish) apply false alias(libs.plugins.osdetector) apply false alias(libs.plugins.ksp) apply false + alias(libs.plugins.versions) } buildscript { @@ -35,4 +37,88 @@ allprojects { jvmTarget.set(JvmTarget.JVM_17) } } +} + +tasks.withType { + outputFormatter { + val updatable = this.outdated.dependencies + val markdown = if (updatable.isEmpty()) { + buildString { + append("### Dependencies up-to-date") + appendLine() + appendLine() + appendLine("Everything up-to-date") + appendLine() + appendLine("### Gradle Version") + appendLine() + appendLine("**Current version:** ${this@outputFormatter.gradle.running.version}") + appendLine("**Latest version:** ${this@outputFormatter.gradle.current.version}") + } + } else { + buildString { + append("## Updatable dependencies (${updatable.size})") + appendLine() + appendLine() + append('|') + append("Group") + append('|') + append("Module") + append('|') + append("Used Version") + append('|') + append("Available Version") + append('|') + appendLine() + append('|') + repeat(2) { + append("---") + append('|') + } + repeat(2) { + append(":-:") + append('|') + } + updatable.forEach { dependency -> + appendLine() + append('|') + append(dependency.group ?: ' ') + append('|') + append(dependency.name ?: ' ') + append('|') + append(dependency.version ?: ' ') + append('|') + append(dependency.available.release ?: dependency.available.milestone ?: ' ') + append('|') + } + appendLine() + appendLine() + appendLine("### Gradle Version") + appendLine() + appendLine("**Current version:** ${this@outputFormatter.gradle.running.version}") + appendLine("**Latest version:** ${this@outputFormatter.gradle.current.version}") + } + } + val outputFile = layout.buildDirectory.file("dependencyUpdates/report.md").get().asFile + try { + if (outputFile.exists()) { + outputFile.delete() + } + } catch (ignored: Throwable) { } + try { + outputFile.parentFile.mkdirs() + } catch (ignored: Throwable) { } + try { + outputFile.writeText(markdown) + } catch (ignored: Throwable) { } + } + rejectVersionIf { + isNonStable(candidate.version) && !isNonStable(currentVersion) + } +} + +fun isNonStable(version: String): Boolean { + val stableKeyword = listOf("RELEASE", "FINAL", "GA").any { version.uppercase().contains(it) } + val regex = "^[0-9,.v-]+(-r)?$".toRegex() + val isStable = stableKeyword || regex.matches(version) + return isStable.not() } \ No newline at end of file diff --git a/gradle.properties b/gradle.properties index cae3e34..1910f30 100644 --- a/gradle.properties +++ b/gradle.properties @@ -2,4 +2,11 @@ kotlin.code.style=official kotlin.mpp.enableCInteropCommonization=true org.gradle.jvmargs=-Xmx4096M -Dfile.encoding=UTF-8 -Dkotlin.daemon.jvm.options\="-Xmx4096M" -org.gradle.caching=true \ No newline at end of file +org.gradle.caching=true + +#Gradle +org.gradle.daemon=true +org.gradle.configureondemand=true +systemProp.javax.xml.parsers.SAXParserFactory=com.sun.org.apache.xerces.internal.jaxp.SAXParserFactoryImpl +systemProp.javax.xml.transform.TransformerFactory=com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl +systemProp.javax.xml.parsers.DocumentBuilderFactory=com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl \ No newline at end of file diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index f733e25..2b26729 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -8,6 +8,7 @@ publish = "0.29.0" kase-change = "1.4.1" osdetector = "1.7.3" ksp = "2.0.10-1.0.24" +versions = "0.51.0" [libraries] auto-service = { group = "com.google.auto.service", name = "auto-service", version.ref = "auto-service" } @@ -25,4 +26,5 @@ multiplatform = { id = "org.jetbrains.kotlin.multiplatform", version.ref = "kotl vanniktech-publish = { id = "com.vanniktech.maven.publish", version.ref = "publish" } gradle-plugin = { id = "dev.datlag.sekret", version.ref = "lib" } osdetector = { id = "com.google.osdetector", version.ref = "osdetector" } -ksp = { id = "com.google.devtools.ksp", version.ref = "ksp" } \ No newline at end of file +ksp = { id = "com.google.devtools.ksp", version.ref = "ksp" } +versions = { id = "com.github.ben-manes.versions", version.ref = "versions" } \ No newline at end of file