Skip to content

Commit

Permalink
check dependency versions
Browse files Browse the repository at this point in the history
  • Loading branch information
DatL4g committed Aug 30, 2024
1 parent 062a80f commit c271747
Show file tree
Hide file tree
Showing 4 changed files with 149 additions and 2 deletions.
52 changes: 52 additions & 0 deletions .github/workflows/dependency-versions.yml
Original file line number Diff line number Diff line change
@@ -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
86 changes: 86 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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 {
Expand Down Expand Up @@ -35,4 +37,88 @@ allprojects {
jvmTarget.set(JvmTarget.JVM_17)
}
}
}

tasks.withType<DependencyUpdatesTask> {
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()
}
9 changes: 8 additions & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
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
4 changes: 3 additions & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Expand All @@ -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" }
ksp = { id = "com.google.devtools.ksp", version.ref = "ksp" }
versions = { id = "com.github.ben-manes.versions", version.ref = "versions" }

0 comments on commit c271747

Please sign in to comment.