2021-06-07 11:41:33 -04:00
|
|
|
// This script pushes new WPT results to wpt.fyi. When the `--ghstatus` flag is
|
|
|
|
// passed, will automatically add a status check to the commit with a link to
|
|
|
|
// the wpt.fyi page.
|
|
|
|
|
2021-06-14 07:48:57 -04:00
|
|
|
import { gzip } from "https://deno.land/x/compress@v0.3.8/gzip/mod.ts";
|
|
|
|
|
2021-06-07 11:41:33 -04:00
|
|
|
const user = Deno.env.get("WPT_FYI_STAGING_USER");
|
|
|
|
const password = Deno.env.get("WPT_FYI_STAGING_PW");
|
|
|
|
|
2021-06-14 07:48:57 -04:00
|
|
|
const fromRawFile = Deno.args.includes("--from-raw-file");
|
2021-06-07 11:41:33 -04:00
|
|
|
|
|
|
|
const form = new FormData();
|
2021-06-14 07:48:57 -04:00
|
|
|
form.set("labels", "master,actions");
|
|
|
|
|
|
|
|
if (fromRawFile) {
|
|
|
|
const file = Deno.args[0];
|
|
|
|
const raw = Deno.readFileSync(file);
|
|
|
|
const gzipped = gzip(raw);
|
|
|
|
form.set("result_file", new Blob([gzipped]));
|
|
|
|
} else {
|
|
|
|
const commit = Deno.args[0];
|
|
|
|
form.set(
|
|
|
|
"result_url",
|
|
|
|
`https://dl.deno.land/wpt/${commit}-wptreport.json.gz`,
|
|
|
|
);
|
|
|
|
}
|
2021-06-07 11:41:33 -04:00
|
|
|
|
|
|
|
const basicAuthToken = btoa(`${user}:${password}`);
|
|
|
|
|
|
|
|
const resp = await fetch("https://staging.wpt.fyi/api/results/upload", {
|
|
|
|
method: "POST",
|
|
|
|
body: form,
|
|
|
|
headers: {
|
|
|
|
authorization: `Basic ${basicAuthToken}`,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
console.log(resp.status);
|
|
|
|
console.log(resp.headers);
|
|
|
|
const body = await resp.text();
|
|
|
|
console.log(body);
|
|
|
|
|
|
|
|
if (!resp.ok) {
|
|
|
|
Deno.exit(1);
|
|
|
|
}
|
|
|
|
|
2021-06-14 07:48:57 -04:00
|
|
|
if (!fromRawFile && Deno.args.includes("--ghstatus")) {
|
2021-06-07 11:41:33 -04:00
|
|
|
const githubToken = Deno.env.get("GITHUB_TOKEN");
|
|
|
|
const taskId = body.split(" ")[1];
|
|
|
|
const url = `https://staging.wpt.fyi/results/?run_id=${taskId}`;
|
2021-06-14 07:48:57 -04:00
|
|
|
const commit = Deno.args[0];
|
2021-06-07 11:41:33 -04:00
|
|
|
const resp = await fetch(
|
|
|
|
`https://api.github.com/repos/denoland/deno/statuses/${commit}`,
|
|
|
|
{
|
|
|
|
method: "POST",
|
|
|
|
body: JSON.stringify({
|
|
|
|
state: "success",
|
|
|
|
target_url: url,
|
|
|
|
context: "wpt.fyi",
|
|
|
|
description: "View WPT results on wpt.fyi",
|
|
|
|
}),
|
|
|
|
headers: {
|
|
|
|
authorization: `Bearer ${githubToken}`,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
);
|
|
|
|
console.log(resp.status);
|
|
|
|
console.log(resp.headers);
|
|
|
|
const body2 = await resp.text();
|
|
|
|
console.log(body2);
|
|
|
|
|
|
|
|
if (!resp.ok) {
|
|
|
|
Deno.exit(1);
|
|
|
|
}
|
|
|
|
}
|