From eaab410c62fb372f556776c610f70b794c33d941 Mon Sep 17 00:00:00 2001 From: Luka Vandervelden Date: Thu, 8 Aug 2019 12:01:35 +0200 Subject: [PATCH] Initial commit. Stores and lists test results. Summaries are missing ATM. --- shard.yml | 21 ++++++++++ src/main.cr | 110 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 131 insertions(+) create mode 100644 shard.yml create mode 100644 src/main.cr diff --git a/shard.yml b/shard.yml new file mode 100644 index 0000000..fb5bf28 --- /dev/null +++ b/shard.yml @@ -0,0 +1,21 @@ +name: tap-aggregator +version: 0.1.0 + +# authors: +# - name + +# description: | +# Short description of tap-aggregator + +dependencies: + tap: + git: https://git.karchnu.fr/JunkOS/tap-parser +# pg: +# github: will/crystal-pg +# version: "~> 0.5" + +# development_dependencies: +# webmock: +# github: manastech/webmock.cr + +# license: MIT diff --git a/src/main.cr b/src/main.cr new file mode 100644 index 0000000..f8e5632 --- /dev/null +++ b/src/main.cr @@ -0,0 +1,110 @@ +require "tap" +require "option_parser" + +args = Array(String).new + +OptionParser.parse! do |parser| + parser.banner = "usage: tap-aggregator [options]" + + parser.on("-h", "--help", "Show this help") do + puts parser + exit 0 + end + + parser.invalid_option do |flag| + STDERR.puts "ERROR: #{flag} is not a valid option." + STDERR.puts parser + exit 1 + end + + parser.unknown_args do |x| + args = x + + if args.size < 1 + puts parser + exit 1 + end + end +end + +command = args[0] + +class Storage + def initialize(@root : String = "storage") + end + + def store(project, environment, revision, content) + date = Time.now.to_unix + file_path = "#{@root}/#{project}/#{environment}/#{date}##{revision}.tap" + Dir.mkdir_p File.dirname file_path + File.write file_path, content + end + + def projects + Dir.children @root + end + + def environments(project) + Dir.children "#{@root}/#{project}" + end + + def results(project, environment) + dir_name = "#{@root}/#{project}/#{environment}" + Dir.children(dir_name).compact_map do |file_name| + unless file_name.match /.tap$/ + next + end + + tap = Tap.parse File.read "#{dir_name}/#{file_name}" + next unless tap + + md = file_name.match /^([^#]*)#(.*).tap$/ + unless md + next + end + + revision = md[2] + timestamp = md[1] + + {revision, timestamp, tap} + end + end +end + +storage = Storage.new + +enum Tap::Entry::Status + def to_s + if self == NotOk + "not ok" + elsif self == Ok + "ok" + end + end +end + +case command +when "add" + if args.size != 4 + STDERR.puts "usage: tap-aggregator add [options]" + exit 1 + end + + project = args[1] + environment = args[2] + revision = args[3] + + storage.store project, environment, revision, STDIN.gets_to_end +when "show" + storage.projects.each do |project| + storage.environments(project).each do |environment| + storage.results(project, environment).each do |revision, timestamp, suite| + puts "#{project}, #{environment}, #{revision} (#{timestamp}) [ #{suite.size} tests ]" + suite.each do |test| + puts " -> #{test.id} #{test.status} #{test.title}" + end + end + end + end +end +