Skip to content

Commit 5f9f16a

Browse files
committed
Merge remote-tracking branch 'upstream/master'
2 parents 8711521 + 54569aa commit 5f9f16a

File tree

5 files changed

+11665
-49
lines changed

5 files changed

+11665
-49
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
module.exports = ({ github, context, core }) => {
2+
const fs = require("fs");
3+
4+
const benchmarkResultPathLua = core.getInput("benchmark-result-path-lua", { required: true });
5+
const benchmarkInfoLua = JSON.parse(fs.readFileSync(benchmarkResultPathLua));
6+
7+
const benchmarkResultPathJIT = core.getInput("benchmark-result-path-jit", { required: true });
8+
const benchmarkInfoJIT = JSON.parse(fs.readFileSync(benchmarkResultPathJIT));
9+
10+
// Remove Comparison info to save some bytes
11+
const benchmarkInfoForVizLua = { old: benchmarkInfoLua.old, new: benchmarkInfoLua.new };
12+
const buffer = Buffer.from(JSON.stringify(benchmarkInfoForVizLua));
13+
14+
const zlib = require("zlib");
15+
const compressed = zlib.deflateSync(buffer);
16+
17+
const summary =
18+
`[Open visualizer](https://typescripttolua.github.io/benchviz?d=${compressed.toString("base64")})\n` +
19+
`### Lua5.3\n${benchmarkInfoLua.comparison.summary}\n### LuaJIT\n${benchmarkInfoJIT.comparison.summary}`;
20+
21+
return summary;
22+
};

.github/workflows/ci.yml

Lines changed: 14 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ jobs:
4545
steps:
4646
- name: Lua Install
4747
run: sudo apt-get install lua5.3 luajit
48+
- name: Glow Install
49+
run: brew install glow
4850
# Checkout master & commit
4951
- name: Checkout master
5052
uses: actions/checkout@v2
@@ -93,50 +95,24 @@ jobs:
9395
working-directory: commit/benchmark
9496
- name: Run benchmark Lua 5.3 commit
9597
id: benchmark-lua-commit
96-
run: echo ::set-output name=info::`lua5.3 -- run.lua ../data/benchmark_commit_53.json ../data/benchmark_master_53.json`
98+
run: lua5.3 -- run.lua ../data/benchmark_master_vs_commit_53.json ../data/benchmark_master_53.json
9799
working-directory: commit/benchmark/dist
98100
- name: Build benchmark LuaJIT commit
99101
run: node ../dist/tstl.js -p tsconfig.jit.json
100102
working-directory: commit/benchmark
101103
- name: Run benchmark LuaJIT commit
102104
id: benchmark-jit-commit
103-
run: echo ::set-output name=info::`luajit -- run.lua ../data/benchmark_commit_jit.json ../data/benchmark_master_jit.json`
105+
run: luajit -- run.lua ../data/benchmark_master_vs_commit_jit.json ../data/benchmark_master_jit.json
104106
working-directory: commit/benchmark/dist
105-
- name: Create benchmark check
106-
uses: actions/github-script@0.9.0
107+
- name: Combine benchmark results
108+
id: script-combine-results
109+
uses: actions/github-script@v3
107110
with:
108-
benchmark-info-lua: ${{steps.benchmark-lua-commit.outputs.info}}
109-
benchmark-info-jit: ${{steps.benchmark-jit-commit.outputs.info}}
111+
benchmark-result-path-lua: commit/benchmark/data/benchmark_master_vs_commit_53.json
112+
benchmark-result-path-jit: commit/benchmark/data/benchmark_master_vs_commit_jit.json
113+
result-encoding: string
110114
script: |
111-
const benchmarkInfoLua = JSON.parse(core.getInput('benchmark-info-lua', { required: true }));
112-
const benchmarkInfoJIT = JSON.parse(core.getInput('benchmark-info-jit', { required: true }));
113-
114-
const zlib = require('zlib');
115-
const buffer = Buffer.from(core.getInput('benchmark-info-lua', { required: true }));
116-
const compressed = zlib.deflateSync(buffer);
117-
118-
const summary = `[Open visualizer](https://typescripttolua.github.io/benchviz?d=${compressed.toString('base64')})\n`
119-
+ `### Lua5.3\n${benchmarkInfoLua.summary}\n### LuaJIT\n${benchmarkInfoJIT.summary}`;
120-
121-
const text = `### Lua5.3\n${benchmarkInfoLua.text}\n### LuaJIT\n${benchmarkInfoJIT.text}`;
122-
123-
const pull_request = context.payload.pull_request;
124-
if (!pull_request || pull_request.head.repo.url === pull_request.base.repo.url) {
125-
// This only works if not in a fork.
126-
github.checks.create({
127-
owner: context.repo.owner,
128-
repo: context.repo.repo,
129-
name: "Benchmark results",
130-
head_sha: context.sha,
131-
status: "completed",
132-
conclusion: "neutral",
133-
output: {
134-
title: "Benchmark results",
135-
summary: summary,
136-
text: text
137-
}
138-
});
139-
} else {
140-
console.log(summary);
141-
console.log(text);
142-
}
115+
const createBenchmarkCheck = require(`${process.env.GITHUB_WORKSPACE}/commit/.github/scripts/create_benchmark_check.js`);
116+
return createBenchmarkCheck({ github, context, core });
117+
- name: Benchmark results
118+
run: echo "${{steps.script-combine-results.outputs.result}}" | glow -s dark -w 120 -

benchmark/src/run.ts

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -42,19 +42,23 @@ function compareBenchmarks(oldResults: BenchmarkResult[], newResults: BenchmarkR
4242
}
4343

4444
function outputBenchmarkData(oldResults: BenchmarkResult[], newResults: BenchmarkResult[]): void {
45-
if (!arg[2]) {
46-
// Output to stdout as json by default, this is used by the CI to retrieve the info
47-
print(json.encode({ old: oldResults, new: newResults }));
48-
} else {
45+
// Output benchmark results to json
46+
if (arg[0]) {
47+
if (arg[1]) {
48+
// if baseline is provide output full comparison info
49+
const comparisonInfo = compareBenchmarks(oldResults, newResults);
50+
const jsonDataFile = io.open(arg[0], "w+")[0]!;
51+
jsonDataFile.write(json.encode({ old: oldResults, new: newResults, comparison: comparisonInfo }));
52+
} else {
53+
const jsonDataFile = io.open(arg[0], "w+")[0]!;
54+
jsonDataFile.write(json.encode(newResults));
55+
}
56+
}
57+
if (arg[2]) {
4958
// Output to file as markdown if arg[2] is set, this is useful for local development
5059
// Compare results
5160
const comparisonInfo = compareBenchmarks(oldResults, newResults);
5261
const markdownDataFile = io.open(arg[2], "w+")[0]!;
5362
markdownDataFile.write(comparisonInfo.summary + comparisonInfo.text);
5463
}
55-
// Output benchmark results to json
56-
if (arg[0]) {
57-
const jsonDataFile = io.open(arg[0], "w+")[0]!;
58-
jsonDataFile.write(json.encode(newResults));
59-
}
6064
}

0 commit comments

Comments
 (0)