homebrew-cask/cmd/lib/travis.rb

39 lines
719 B
Ruby
Raw Normal View History

2018-08-02 00:39:26 +08:00
module Travis
module_function
@start = {}
def fold(id, &block)
2018-08-13 13:54:34 +08:00
print fold_start(id)
time(rand(2**32).to_s(16), &block)
print fold_end(id)
2018-08-02 00:39:26 +08:00
end
def fold_start(id)
2018-08-13 13:54:34 +08:00
"travis_fold:start:#{id}\r\033[0K"
2018-08-02 00:39:26 +08:00
end
def fold_end(id)
2018-08-13 13:54:34 +08:00
"travis_fold:end:#{id}\r\033[0K"
2018-08-02 00:39:26 +08:00
end
def time(id)
2018-08-13 13:54:34 +08:00
print time_start(id)
2018-08-02 00:39:26 +08:00
yield
2018-08-13 13:54:34 +08:00
print time_end(id)
2018-08-02 00:39:26 +08:00
end
def time_start(id)
@start[id] = Time.now
2018-08-13 13:54:34 +08:00
"travis_time:start:#{id}\r\033[0K"
2018-08-02 00:39:26 +08:00
end
def time_end(id)
start = (@start[id].to_f * 1_000_000_000).to_i
finish = (Time.now.to_f * 1_000_000_000).to_i
duration = finish - start
2018-08-13 13:54:34 +08:00
"travis_time:end:#{id},start=#{start},finish=#{finish},duration=#{duration}\r\033[0K"
2018-08-02 00:39:26 +08:00
end
end