-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpathogen-workflows.html.js
executable file
·157 lines (139 loc) · 5.18 KB
/
pathogen-workflows.html.js
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
#!/usr/bin/env node
import { groups, sort } from "d3-array";
import { DateTime } from "luxon";
import fs from "node:fs";
import path from "node:path";
import process from "node:process";
import html from "./html.js";
const generatedAt = DateTime.utc();
// Read data from stdin
if (process.stdin.isTTY) {
process.stderr.write("error: stdin is a tty; please provide data (e.g. pathogen-workflows.json) on stdin\n");
process.exit(1);
}
const workflowRuns = JSON.parse(await readStream(process.stdin));
const runsByRepoAndWorkflow =
groups(
sort(
workflowRuns,
d => d.repository_full_name.toLowerCase(),
d => d.workflow_name.toLowerCase(),
d => -d.created_at,
d => -d.id),
d => d.repository_full_name,
d => d.workflow_name );
const someFailure =
runsByRepoAndWorkflow
.flatMap(([, workflows]) =>
workflows.map(([, runs]) =>
runs[0].conclusion ?? runs[0].status))
.some(x => x === "failure");
// Generate HTML to stdout
process.stdout.write(String(html`
<!doctype html>
<html class="inhibit-transitions">
<head>
<meta charset="utf-8">
<title>Pathogen workflow status</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="icon" href="favicon-${someFailure ? "failure" : "success"}.svg" />
<link rel="stylesheet" href="pathogen-workflows.css">
</head>
<body>
<h1>Pathogen workflow status</h1>
<nav aria-label="repo-list">
<ul>
${
runsByRepoAndWorkflow.map(([repository_full_name, workflows]) => html`
<li>
<a href="#${repoShortName(repository_full_name)}">
${
workflows
.map(([, runs]) => runs[0].conclusion ?? runs[0].status)
.some(x => x === "failure")
? html`<span class="indicator failure">${indicator({conclusion: "failure"})} </span>`
: ""
}${repoShortName(repository_full_name)}
</a>
</li>
`)
}
</ul>
</nav>
<nav aria-labelledby="layout-toggle">
<span id="layout-toggle">layout:</span>
<a href="?">compact</a>
/ <a href="?time-relative">time-relative</a>
</nav>
<p class="display-offline-only offline-warning">
You’re offline. Automatic refresh is paused and information may be stale.
</p>
<p class="generated-at">
Generated at <time datetime="${generatedAt}">${generatedAt}</time>
by <a href="https://github.com/nextstrain/status">nextstrain/status</a>
for repos using our shared <a href="https://github.com/nextstrain/.github/blob/HEAD/.github/workflows/pathogen-repo-build.yaml"><code>pathogen-repo-build.yaml</code> workflow</a>.
</p>
${
runsByRepoAndWorkflow.map(([repository_full_name, workflows]) => html`
<h2 id="${repoShortName(repository_full_name)}">
<a href="https://github.com/${repository_full_name}">${repoShortName(repository_full_name)}</a>
<a href="#${repoShortName(repository_full_name)}">#</a>
</h2>
${
workflows.map(([workflow_name, runs]) => html`
<h3>
<a href="https://github.com/${repository_full_name}/actions/${encodeURI(runs[0].workflow_path.replace(/^[.]github\//, ""))}">${workflow_name}</a>
<span>(<a href="${runs[0].workflow_html_url}"><code>${runs[0].workflow_path}</code></a>)</span>
</h3>
<ol>
${
runs.map(run => html`
<li class="${(run.conclusion ?? run.status).replace(/_/g, "-")}" data-run="${JSON.stringify(run)}">
<details>
<summary>${indicator(run)}</summary>
<div>
<time datetime="${run.created_at}">${run.created_at}</time>
<time datetime="${run.duration}">${run.duration}</time>
<a href="${run.html_url}">run details</a>
${
run.attempt > 1
? html`attempt #${run.attempt}`
: ''
}
<code>${run.event}</code>
<code>${run.commit_id.slice(0, 8)}</code>
</div>
</details>
</li>
`)
}
</ol>
`)
}
`)
}
</body>
<script src="luxon.min.js"></script>
<script src="pathogen-workflows.js"></script>
</html>
`).replace(/^ /gm, '').trim() + "\n");
function repoShortName(repository_full_name) {
return repository_full_name.replace(/^nextstrain\//, "");
}
function indicator(run) {
switch (run.conclusion ?? run.status) {
case "success": return "✔";
case "failure": return "✘";
case "in_progress": return "⋯";
case "cancelled": return "🛇";
default: return run.conclusion;
}
}
async function readStream(stream) {
stream.setEncoding("utf-8");
let data = "";
for await (const chunk of stream) {
data += chunk;
}
return data;
}