forked from Baguette/tap-aggregator
Initial commit.
Stores and lists test results. Summaries are missing ATM.
This commit is contained in:
commit
eaab410c62
21
shard.yml
Normal file
21
shard.yml
Normal file
@ -0,0 +1,21 @@
|
||||
name: tap-aggregator
|
||||
version: 0.1.0
|
||||
|
||||
# authors:
|
||||
# - name <email@example.com>
|
||||
|
||||
# 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
|
110
src/main.cr
Normal file
110
src/main.cr
Normal file
@ -0,0 +1,110 @@
|
||||
require "tap"
|
||||
require "option_parser"
|
||||
|
||||
args = Array(String).new
|
||||
|
||||
OptionParser.parse! do |parser|
|
||||
parser.banner = "usage: tap-aggregator <command> [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 <project> <environment> <revision> [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
|
||||
|
Loading…
Reference in New Issue
Block a user