Post response to PR with benchmark results

pull/1786/head
Paul Sauve 8 years ago
parent 68763bae82
commit 179bb5eb32

@ -22,4 +22,5 @@ jobs:
node_js: '6'
addons:
jwt:
secure: paQL489vgNsfNpPW7cZw6lp0ludg05A3j1ZohzSnW/qMwdR4NEp2Dmpag+BTbB86dUK7uVEJCGQ0sASRpDXJjVuWfFLwUehuPwmREggy6O4TLpkRS3Evju2LdKZWF46bkJcf257R/CdfRD1ug1r83wQEzJCAje8mRyPDRucZy6oEYqy7Q+qs5HOfGDHP3giFnbiweqxjscP1et/+PA2wQmdnxTdIZTJ7qs0/vwD8bGlDz8qt/h9X4CAv2KgT0Mw1kYocC/pZExPgfHbbS7nYIWHtwl3I9SPgZ/Hd+cDu2F8AHVppeoJyFJ6N+lxlqfnPyShFzXrXD5phJwKjEfcQAb7VyWNYbX+kYKPd4RCoYP4RBaiSqR3NKz5lgJCRhPmaDxQD3aDkJ/Uc6uU++x+t6vdxEtPH8OgywoPJrAWtFmJppInR79KJstGe6K0/kwQ3eLWos+lDd3dxsQmMAOUqxmSREeY5trHSK/jb70VfafqMCEgvSVkyJNKUqqXivXg4NhxPKWCE62XoWtDxXq+0OzYZGMJx2pKjIrINo8Q8uFy+yjVyw6WUq7L/JStZU7mwotzUzLuoIisx/3W5qaw1atjd4e13M+NBx5G6f/RrGTWSma5iHmIjGgBmz1biPamNxGlHetfaonohRcYHGS8egeUHlWpyyQ20iSvtgiZBjAE=
- secure: paQL489vgNsfNpPW7cZw6lp0ludg05A3j1ZohzSnW/qMwdR4NEp2Dmpag+BTbB86dUK7uVEJCGQ0sASRpDXJjVuWfFLwUehuPwmREggy6O4TLpkRS3Evju2LdKZWF46bkJcf257R/CdfRD1ug1r83wQEzJCAje8mRyPDRucZy6oEYqy7Q+qs5HOfGDHP3giFnbiweqxjscP1et/+PA2wQmdnxTdIZTJ7qs0/vwD8bGlDz8qt/h9X4CAv2KgT0Mw1kYocC/pZExPgfHbbS7nYIWHtwl3I9SPgZ/Hd+cDu2F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w3dF3BV3aU= # github_access_token

@ -68,6 +68,7 @@
"locate-character": "^2.0.0",
"magic-string": "^0.21.1",
"mocha": "^3.2.0",
"node-fetch": "^1.7.1",
"node-resolve": "^1.3.3",
"nyc": "^10.0.0",
"prettier": "^1.4.1",

@ -1,9 +1,11 @@
const path = require('path');
const childProcess = require('child_process');
const fetch = require('node-fetch');
const username = process.env.SAUCE_USERNAME;
const accessKey = process.env.SAUCE_ACCESS_KEY;
const build = process.env.TRAVIS_BUILD_NUMBER;
const pullRequest = process.env.TRAVIS_PULL_REQUEST;
const tags = [ process.env.TRAVIS_NODE_VERSION, 'CI' ];
const idleTimeout = 30;
@ -54,11 +56,87 @@ const args = [
`--server=http://${username}:${accessKey}@ondemand.saucelabs.com/wd/hub`
];
let stdout;
try {
childProcess.execFileSync(path.join(__dirname, 'benchmark.sh'), args, {
stdout = childProcess.execFileSync(path.join(__dirname, 'benchmark.sh'), args, {
cwd: process.cwd(),
stdio: 'inherit'
stdio: [
0,
]
});
} catch (err) {
console.error('An error occurred running the benchmark!');
}
if (typeof stdout !== 'string') {
stdout = stdout.toString('utf8');
}
const outputs = [];
let index = 0;
let started = false;
// parse the output to find what we want
const split = stdout.split('\n');
split.forEach((line, lineNum) => {
if (started) {
if (line.indexOf('Running capability') === 0 || line.indexOf('Took ') === 0) {
started = false;
index++;
} else {
if (outputs.length <= index) {
outputs[index] = [];
}
outputs[index].push(line);
}
} else if (lineNum > 0 && line === '' && split[lineNum - 1].indexOf('Testing ') === 0) {
started = true;
}
});
if (pullRequest !== 'false') {
const githubUsername = 'Svelte-Bot';
const id = 29757693;
const githubToken = process.env.GITHUB_ACCESS_TOKEN;
fetch(`https://${githubUsername}:${githubToken}@api.github.com/repos/sveltejs/svelte/issues/${pullRequest}/comments`)
.then(res => res.json())
.then(res => {
let addComment = false;
let editId = null;
if (res.length === 0) {
addComment = true;
} else if (res[res.length - 1].user.id !== id) {
addComment = true;
res.forEach(reply => {
if (reply.user.id === id) {
editId = reply.id;
}
});
}
if (addComment) {
const contents = '<details><summary>Benchmark Results</summary>' +
outputs.map(output => output.join('\n')).join('\n----------------------------------------------------------------------\n') +
'</details>';
if (editId === null) {
return fetch(`https://${githubUsername}:${githubToken}@api.github.com/repos/sveltejs/svelte/issues/${pullRequest}/comments`, {
method: 'POST',
body: JSON.stringify({
body: contents
})
});
} else {
return fetch(`https://${githubUsername}:${githubToken}@api.github.com/repos/sveltejs/svelte/issues/comments/${editId}`, {
method: 'PATCH',
body: JSON.stringify({
body: contents
})
});
}
}
});
}

@ -1014,6 +1014,12 @@ electron-to-chromium@^1.2.7:
version "1.3.8"
resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.3.8.tgz#b2c8a2c79bb89fbbfd3724d9555e15095b5f5fb6"
encoding@^0.1.11:
version "0.1.12"
resolved "https://registry.yarnpkg.com/encoding/-/encoding-0.1.12.tgz#538b66f3ee62cd1ab51ec323829d1f9480c74beb"
dependencies:
iconv-lite "~0.4.13"
entities@^1.1.1, entities@~1.1.1:
version "1.1.1"
resolved "https://registry.yarnpkg.com/entities/-/entities-1.1.1.tgz#6e5c2d0a5621b5dadaecef80b90edfb5cd7772f0"
@ -1529,7 +1535,7 @@ http-signature@~1.1.0:
jsprim "^1.2.2"
sshpk "^1.7.0"
iconv-lite@0.4.13:
iconv-lite@0.4.13, iconv-lite@~0.4.13:
version "0.4.13"
resolved "https://registry.yarnpkg.com/iconv-lite/-/iconv-lite-0.4.13.tgz#1f88aba4ab0b1508e8312acc39345f36e992e2f2"
@ -1687,6 +1693,10 @@ is-resolvable@^1.0.0:
dependencies:
tryit "^1.0.1"
is-stream@^1.0.1:
version "1.1.0"
resolved "https://registry.yarnpkg.com/is-stream/-/is-stream-1.1.0.tgz#12d4a3dd4e68e0b79ceb8dbc84173ae80d91ca44"
is-typedarray@~1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/is-typedarray/-/is-typedarray-1.0.0.tgz#e479c80858df0c1b11ddda6940f96011fcda4a9a"
@ -2078,6 +2088,13 @@ natural-compare@^1.4.0:
version "1.4.0"
resolved "https://registry.yarnpkg.com/natural-compare/-/natural-compare-1.4.0.tgz#4abebfeed7541f2c27acfb29bdbbd15c8d5ba4f7"
node-fetch@^1.7.1:
version "1.7.1"
resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-1.7.1.tgz#899cb3d0a3c92f952c47f1b876f4c8aeabd400d5"
dependencies:
encoding "^0.1.11"
is-stream "^1.0.1"
node-resolve@^1.3.3:
version "1.3.3"
resolved "https://registry.yarnpkg.com/node-resolve/-/node-resolve-1.3.3.tgz#74c7f5d3373e4bb2f60182e3a96dde0f8aacb0ce"

Loading…
Cancel
Save