-
-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathjobset-eval-failure
executable file
·88 lines (69 loc) · 2.12 KB
/
jobset-eval-failure
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#!/usr/bin/env nix-shell
require "fileutils"
require "open3"
require "time"
require File.join(__dir__(), "lib/hydra")
require File.join(__dir__(), "lib/md")
abort "Usage: jobset-eval-failure [-f] <id>" unless ARGV[0]
# Options, set by parameters
$force = false
# Parameters parsing (destructive)
until ARGV.length == 0 do
val = ARGV.shift
if val == "--force" or val == "-f" then
$force = true
else
$id = val
end
end
# Gets the jobset
jobset = Hydra::Jobset.get($id)
# Filename to track whether we've seen this eval or not already
filename = "eval-report-#{jobset.id}@#{jobset.last_evaluation}.md"
# When the file exists, it assumes the report is produced and known.
if File.exist?(filename) and !$force
url = File.read(filename)
puts "Job status is already known, skipping\n\nSee #{url}\n"
exit 0
end
# Use this **only** for the generation time.
now = Time.now.utc.iso8601
# User friendly status
status = case jobset.status
when :success
"succeded"
when :warning
"succeded with warnings"
when :error
"failed"
else
"':jobset.status.to_s'"
end
# Document for the report.
document = []
document << MD.title("Jobset #{jobset.id} status for eval @ #{jobset.last_evaluation}")
document << MD.paragraph(MD.italics("Generated at #{now}"))
document << MD.paragraph("This evaluation #{status}.")
# This is not useful as this information *changes*.
#document << MD.paragraph("(An evaluation is pending since #{jobset.evaluation_pending_since}.)") if jobset.evaluation_pending
# Section with the error log
document << MD.subtitle("stderr for eval @ #{jobset.last_evaluation}")
document << MD.code(jobset.errors_log)
# Create a text document
text = MD.join(*document)
# Prepares a command to output a gist
gist = [
"gist",
"-p",
"-f", filename,
]
# Creates the gist (hopefully)
out, status = Open3.capture2(*gist, stdin_data: text)
# FIXME : error condition
# Write the status to stdout
puts "Generated report:\n"
puts out
# And mark the jobset eval as seen!
File.write(filename, out)
#!nix-shell shell.nix -i "bundle exec ruby"
# vim: set ft=ruby: