Skip to content

Commit dec5eef

Browse files
authored
Merge pull request #2121 from Urgau/gha_logs-status
Improve GHA logs viewer title and use custom colored Rust logo to indicate job status
2 parents 456030e + a5ae650 commit dec5eef

File tree

5 files changed

+181
-3
lines changed

5 files changed

+181
-3
lines changed

src/gha_logs.rs

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ use std::sync::Arc;
1010
use uuid::Uuid;
1111

1212
pub const ANSI_UP_URL: &str = "/gha_logs/[email protected]";
13+
pub const SUCCESS_URL: &str = "/gha_logs/[email protected]";
14+
pub const FAILURE_URL: &str = "/gha_logs/[email protected]";
15+
1316
const MAX_CACHE_CAPACITY_BYTES: u64 = 50 * 1024 * 1024; // 50 Mb
1417

1518
#[derive(Default)]
@@ -177,16 +180,30 @@ async fn process_logs(
177180
};
178181

179182
let nonce = Uuid::new_v4().to_hyphenated().to_string();
183+
let job_name = &*job.name;
180184
let sha = &*job.head_sha;
185+
let short_sha = &job.head_sha[..7];
186+
187+
let icon_status = match job.conclusion {
188+
Some(github::JobConclusion::Failure | github::JobConclusion::TimedOut) => {
189+
format!(r#"<link rel="icon" sizes="any" type="image/svg+xml" href="{FAILURE_URL}">"#)
190+
}
191+
Some(github::JobConclusion::Success) => {
192+
format!(r#"<link rel="icon" sizes="any" type="image/svg+xml" href="{SUCCESS_URL}">"#)
193+
}
194+
_ => {
195+
r#"<link rel="icon" sizes="32x32" type="image/png" href="https://www.rust-lang.org/static/images/favicon-32x32.png">"#.to_string()
196+
}
197+
};
181198

182199
let html = format!(
183200
r###"<!DOCTYPE html>
184201
<html lang="en" translate="no">
185202
<head>
186203
<meta charset="UTF-8">
187204
<meta name="viewport" content="width=device-width, initial-scale=1.0">
188-
<title>{log_id} - {owner}/{repo}</title>
189-
<link rel="icon" sizes="32x32" type="image/png" href="https://www.rust-lang.org/static/images/favicon-32x32.png">
205+
<title>{job_name} - {owner}/{repo}@{short_sha}</title>
206+
{icon_status}
190207
<style>
191208
body {{
192209
font: 14px SFMono-Regular, Consolas, Liberation Mono, Menlo, monospace;
@@ -290,7 +307,7 @@ async fn process_logs(
290307
.header(
291308
CONTENT_SECURITY_POLICY,
292309
format!(
293-
"default-src 'none'; script-src 'nonce-{nonce}' 'self'; style-src 'unsafe-inline'; img-src www.rust-lang.org"
310+
"default-src 'none'; script-src 'nonce-{nonce}' 'self'; style-src 'unsafe-inline'; img-src 'self' www.rust-lang.org"
294311
),
295312
)
296313
.body(Body::from(html))?);
@@ -306,3 +323,25 @@ pub fn ansi_up_min_js() -> anyhow::Result<Response<Body>, hyper::Error> {
306323
.body(Body::from(ANSI_UP_MIN_JS))
307324
.unwrap())
308325
}
326+
327+
pub fn success_svg() -> anyhow::Result<Response<Body>, hyper::Error> {
328+
const SUCCESS_SVG: &str = include_str!("gha_logs/success.svg");
329+
330+
Ok(Response::builder()
331+
.status(StatusCode::OK)
332+
.header(CACHE_CONTROL, "public, max-age=15552000, immutable")
333+
.header(CONTENT_TYPE, "image/svg+xml; charset=utf-8")
334+
.body(Body::from(SUCCESS_SVG))
335+
.unwrap())
336+
}
337+
338+
pub fn failure_svg() -> anyhow::Result<Response<Body>, hyper::Error> {
339+
const FAILURE_SVG: &str = include_str!("gha_logs/failure.svg");
340+
341+
Ok(Response::builder()
342+
.status(StatusCode::OK)
343+
.header(CACHE_CONTROL, "public, max-age=15552000, immutable")
344+
.header(CONTENT_TYPE, "image/svg+xml; charset=utf-8")
345+
.body(Body::from(FAILURE_SVG))
346+
.unwrap())
347+
}

src/gha_logs/failure.svg

Lines changed: 59 additions & 0 deletions
Loading

0 commit comments

Comments
 (0)