Created
October 30, 2020 01:03
-
-
Save GreyCat/29344a50835756382f807e7ed796056d to your computer and use it in GitHub Desktop.
A quick way to validate current state of official builds / release deployments
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require 'fileutils' | |
require 'rexml/document' | |
require 'json' | |
require 'date' | |
class VersionInfo | |
attr_accessor :version | |
attr_accessor :date | |
def initialize(version, date) | |
@version = version | |
@date = date.is_a?(String) ? DateTime.parse(date).to_time : date | |
end | |
def inspect | |
r = "#{version}" | |
r << " on #{date.strftime('%Y-%m-%d %H:%M')}" if date | |
r | |
end | |
end | |
class ReleaseStatusReporter | |
CACHE_DIR = 'cache' | |
def download(url, id = nil) | |
FileUtils::mkdir_p(CACHE_DIR) | |
if id.nil? | |
id = url.tr('/:', '_') | |
end | |
target_file = "#{CACHE_DIR}/#{id}" | |
unless File.exists?(target_file) | |
system("curl -s #{url} --output #{CACHE_DIR}/#{id}") | |
end | |
File.read(target_file) | |
end | |
def get_json(url) | |
JSON.load(download(url)) | |
end | |
def get_xml(url) | |
REXML::Document.new(download(url)) | |
end | |
def info_on_bintray(org_name, repo_name, package_name) | |
q = get_json("https://api.bintray.com/packages/#{org_name}/#{repo_name}/#{package_name}") | |
VersionInfo.new(q['latest_version'], q['updated']) | |
end | |
def info_on_npmjs(package_name) | |
q = get_json("http://registry.npmjs.org/#{package_name}") | |
version = q['dist-tags']['latest'] | |
VersionInfo.new(version, q['time'][version]) | |
end | |
def info_on_maven(path) | |
q = get_xml("https://repo1.maven.org/maven2/#{path}/maven-metadata.xml").root | |
VersionInfo.new(q.elements["versioning/release"].text, DateTime.parse(q.elements['versioning/lastUpdated'].text).to_time) | |
end | |
def info_on_nuget(package_name) | |
q = get_xml("https://www.nuget.org/packages/#{package_name}/atom.xml").root | |
id = q.elements["entry[1]/id"].text | |
# https://www.nuget.org/packages/KaitaiStruct.Runtime.CSharp/0.9.0 | |
version = id.split(/\//).last | |
VersionInfo.new(version, q.elements["entry[1]/published"].text) | |
end | |
def info_on_pypi(package_name) | |
q = get_xml('https://pypi.org/rss/project/kaitaistruct/releases.xml').root | |
VersionInfo.new(q.elements["channel/item[1]/title"].text, q.elements["channel/item[1]/pubDate"].text) | |
end | |
def info_on_rubygems(package_name) | |
q = get_json('https://rubygems.org/api/v1/gems/kaitai-struct.json') | |
VersionInfo.new(q['version'], q['date']) | |
end | |
def info_on_webide_compiler | |
s = download("https://ide.kaitai.io/lib/_npm/kaitai-struct-compiler/kaitai-struct-compiler.js") | |
return nil unless s =~ /^\$c_Lio_kaitai_struct_Version\$\.prototype\.init___ = \(function\(\) \{(.*?)\}/m | |
body = $1 | |
version = nil | |
version = $1 if body =~ /this.version\$1 = "(.*?)";/ | |
date = nil | |
date = $1 if body =~ /this.gitTime\$1 = "(.*?)";/ | |
VersionInfo.new(version, date) | |
end | |
def report | |
puts "### Compiler" | |
puts | |
print "* Debian package at BinTray - " | |
p info_on_bintray('kaitai-io', 'debian', 'kaitai-struct-compiler') | |
print "* Universal package at BinTray - " | |
p info_on_bintray('kaitai-io', 'universal', 'kaitai-struct-compiler') | |
print "* Java library at Maven - " | |
p info_on_maven('io/kaitai/kaitai-struct-compiler_2.12') | |
print "* JavaScript library at Maven - " | |
p info_on_maven('io/kaitai/kaitai-struct-compiler-js_sjs0.6_2.12') | |
print "* JavaScript library at npmjs - " | |
p info_on_npmjs('kaitai-struct-compiler') | |
puts | |
puts "### Runtimes" | |
puts | |
print "* C# at NuGet.org - " | |
p info_on_nuget('KaitaiStruct.Runtime.CSharp') | |
print "* Java at Maven - " | |
p info_on_maven('io/kaitai/kaitai-struct-runtime') | |
print "* JavaScript at npmjs - " | |
p info_on_npmjs('kaitai-struct') | |
print "* Python at PyPI - " | |
p info_on_pypi('kaitaistruct') | |
print "* Ruby at RubyGems - " | |
p info_on_rubygems('kaitai-struct') | |
puts | |
puts "### Web" | |
puts | |
print "* WebIDE compiler - " | |
p info_on_webide_compiler | |
end | |
end | |
r = ReleaseStatusReporter.new | |
r.report |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment