Permalink
Browse files

add checkVersion Task to keep track of published gem versions

  • Loading branch information...
1 parent f15ca7c commit 1fc26280a11c69eb9e6de2d5733379682c56c912 @ancho ancho committed Jun 27, 2016
@@ -1,2 +1,3 @@
properName=AsciidoctorJ
description=AsciidoctorJ provides Java bindings for the Asciidoctor RubyGem (asciidoctor) using JRuby.
+gem_name=asciidoctor
@@ -1,3 +1,4 @@
properName=AsciidoctorJ Diagram
description=AsciidoctorJ Diagram bundles the Asciidoctor Diagram RubyGem (asciidoctor-diagram) so it can be loaded into the JVM using JRuby.
version=1.3.1
+gem_name=asciidoctor-diagram
@@ -1,3 +1,4 @@
properName=AsciidoctorJ EPUB3
description=AsciidoctorJ EPUB3 bundles the Asciidoctor EPUB3 RubyGem (asciidoctor-epub3) so it can be loaded into the JVM using JRuby.
version=1.5.0-alpha.6
+gem_name=asciidoctor-epub3
@@ -1,3 +1,4 @@
properName=AsciidoctorJ PDF
description=AsciidoctorJ PDF bundles the Asciidoctor PDF RubyGem (asciidoctor-pdf) so it can be loaded into the JVM using JRuby.
version=1.5.0-alpha.11
+gem_name=asciidoctor-pdf
View
@@ -130,6 +130,7 @@ configure(subprojects.findAll { !it.isDistribution() }) {
apply plugin: 'com.github.jruby-gradle.base'
apply from: rootProject.file('gradle/eclipse.gradle')
+ apply from: rootProject.file('gradle/versioncheck.gradle')
repositories {
maven {
@@ -0,0 +1,54 @@
+buildscript {
+ repositories {
+ jcenter()
+ }
+ dependencies {
+ classpath 'com.github.zafarkhaja:java-semver:0.9.0'
+ }
+}
+
+import groovy.json.JsonSlurper
+import com.github.zafarkhaja.semver.Version
+
+task checkVersion() {
+ group "verification"
+ description "Check if current project version is behind published gem version. (skip with -P skip.checkVersion)"
+
+ if ( !project.hasProperty("gem_name")) {
+ throw new GradleException("I need the gem name to check the version. Add a 'gem_name' property to the gradle.properties file. (e.g.: gem_name=asciidoctor-diagram)")
+ }
+
+ def gem_version_pattern = ~/(((\d+\.){1,2}\d+)(\.)?(.*))/
+ def gem_latest_version_url = "https://rubygems.org/api/v1/versions/${gem_name}/latest.json".toURL()
+
+ def json = new JsonSlurper().parse( gem_latest_version_url )
+ def gem_latest_version = json.version
+
+ def matcher = gem_latest_version =~ gem_version_pattern
+ def javaVersion = gem_latest_version
+
+ doLast {
+
+ if ( gem_latest_version ==~ gem_version_pattern ) {
+ matcher.find()
+ if (matcher.group(4)) {
+ javaVersion = "${matcher.group(2)}-${matcher.group(5)}"
+ }
+ }
+
+
+ Version projectVersion = Version.valueOf(version)
+ Version gemJavaVersion = Version.valueOf(javaVersion)
+
+ if ( projectVersion.lessThan(gemJavaVersion) ) {
+ logger.warn "\nWARNING\nVersion mismatch: Current Version: $version, Gem Version: $gem_latest_version\n"
+ }
+ else {
+ println "up-to-date"
+ }
+ }
+}
+
+checkVersion.onlyIf { !gradle.startParameter.isOffline() }
+checkVersion.onlyIf { !project.hasProperty("skip.checkVersion") }
+check.dependsOn checkVersion

0 comments on commit 1fc2628

Please sign in to comment.