Skip to content

Commit 69a992f

Browse files
committed
Run performance tests on all PR against base branch
Based on #1629 This PR proposes two things: 1. To run performance tests in CI for all PR 2. Run performance tests against the base branch (and not against the last RxPlayer release)
1 parent 9cb66c1 commit 69a992f

File tree

2 files changed

+84
-24
lines changed

2 files changed

+84
-24
lines changed

.github/workflows/perfs.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
name: Performance tests
22
on:
33
pull_request:
4-
types: [labeled]
4+
types: [opened, synchronize, reopened]
55

66
jobs:
77
perf-tests:
8-
if: ${{ github.event.label.name == 'Performance checks' }}
98
runs-on: [ubuntu-latest]
109
steps:
1110
- uses: actions/checkout@v2
@@ -21,4 +20,5 @@ jobs:
2120
- run: npm ci
2221
- run: export DISPLAY=:99
2322
- run: sudo Xvfb -ac :99 -screen 0 1280x1024x24 > /dev/null 2>&1 & # optional
24-
- run: node tests/performance/run.mjs
23+
- run: git fetch
24+
- run: node tests/performance/run.mjs -b $GITHUB_BASE_REF

tests/performance/run.mjs

Lines changed: 81 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import esbuild from "esbuild";
66
import * as fs from "fs/promises";
77
import { createServer } from "http";
88
import * as path from "path";
9-
import { fileURLToPath } from "url";
9+
import { fileURLToPath, pathToFileURL } from "url";
1010
import launchStaticServer from "../../scripts/launch_static_server.mjs";
1111
import getHumanReadableHours from "../../scripts/utils/get_human_readable_hours.mjs";
1212
import removeDir from "../../scripts/utils/remove_dir.mjs";
@@ -115,15 +115,47 @@ const servers = [];
115115
*/
116116
let onFinished = () => {};
117117

118-
start().catch((err) => {
119-
// eslint-disable-next-line no-console
120-
console.error("Error:", err);
121-
return process.exit(1);
122-
});
118+
// If true, this script is called directly
119+
if (import.meta.url === pathToFileURL(process.argv[1]).href) {
120+
const args = process.argv.slice(2);
121+
if (args.includes("-h") || args.includes("--help")) {
122+
displayHelp();
123+
process.exit(0);
124+
}
125+
126+
let branchName;
127+
{
128+
let branchNameIndex = args.indexOf("-b");
129+
if (branchNameIndex < 0) {
130+
branchNameIndex = args.indexOf("--branch");
131+
}
132+
if (branchNameIndex >= 0) {
133+
const wantedbranchName = args[branchNameIndex + 1];
134+
if (wantedbranchName === undefined) {
135+
// eslint-disable-next-line no-console
136+
console.error("ERROR: no branch name provided\n");
137+
displayHelp();
138+
process.exit(1);
139+
}
140+
branchName = path.normalize(wantedbranchName);
141+
}
142+
}
143+
144+
startPerformanceTests({ branchName }).catch((err) => {
145+
// eslint-disable-next-line no-console
146+
console.error("Error:", err);
147+
return process.exit(1);
148+
});
149+
}
123150

124-
/** Initialize and start all tests on Chrome. */
125-
async function start() {
126-
await initScripts();
151+
/**
152+
* Initialize and start all tests on Chrome.
153+
* @param {Object} opts - Various options to configure performance tests.
154+
* @param {string} opts.branchName - The name of the branch results should be
155+
* compared to.
156+
*/
157+
export default async function startPerformanceTests({ branchName } = {}) {
158+
await initScripts(branchName ?? "dev");
127159
await initServers();
128160

129161
onFinished = () => {
@@ -183,11 +215,13 @@ async function initServers() {
183215

184216
/**
185217
* Prepare all scripts needed for the performance tests.
218+
* @param {string} branchName - The name of the branch results should be
219+
* compared to.
186220
* @returns {Promise} - Resolves when the initialization is finished.
187221
*/
188-
async function initScripts() {
222+
async function initScripts(branchName) {
189223
await prepareCurrentRxPlayerTests();
190-
await prepareLastRxPlayerTests();
224+
await prepareLastRxPlayerTests(branchName);
191225
}
192226

193227
/**
@@ -201,10 +235,12 @@ async function prepareCurrentRxPlayerTests() {
201235

202236
/**
203237
* Build test file for testing the last version of the RxPlayer.
238+
* @param {string} branchName - The name of the branch results should be
239+
* compared to.
204240
* @returns {Promise}
205241
*/
206-
async function prepareLastRxPlayerTests() {
207-
await linkLastRxPlayer();
242+
async function prepareLastRxPlayerTests(branchName) {
243+
await linkRxPlayerBranch(branchName);
208244
await createBundle({ output: "bundle2.js", minify: false, production: true });
209245
}
210246

@@ -219,26 +255,36 @@ async function linkCurrentRxPlayer() {
219255
await spawnProc(
220256
"npm run build",
221257
[],
222-
(code) => new Error(`npm install exited with code ${code}`),
258+
(code) => new Error(`npm run build exited with code ${code}`),
223259
).promise;
224-
await fs.symlink(
225-
path.join(currentDirectory, "..", ".."),
226-
path.join(currentDirectory, "node_modules", "rx-player"),
227-
);
228260
}
229261

230262
/**
231263
* Link the last published RxPlayer version to the performance tests, so
232264
* performance of new code can be compared to it.
265+
* @param {string} branchName - The name of the branch results should be
266+
* compared to.
233267
* @returns {Promise}
234268
*/
235-
async function linkLastRxPlayer() {
269+
async function linkRxPlayerBranch(branchName) {
236270
await removeDir(path.join(currentDirectory, "node_modules"));
271+
await fs.mkdir(path.join(currentDirectory, "node_modules"));
272+
const rxPlayerPath = path.join(currentDirectory, "node_modules", "rx-player");
237273
await spawnProc(
238-
"npm install",
239-
["--prefix", currentDirectory, "rx-player"],
274+
`git worktree add -f ${rxPlayerPath} ${branchName}`,
275+
[],
240276
(code) => new Error(`npm install exited with code ${code}`),
241277
).promise;
278+
await spawnProc(
279+
`cd ${rxPlayerPath} && npm install`,
280+
[],
281+
(code) => new Error(`npm install failed with code ${code}`),
282+
).promise;
283+
await spawnProc(
284+
`cd ${rxPlayerPath} && npm run build`,
285+
[],
286+
(code) => new Error(`npm run build exited with code ${code}`),
287+
).promise;
242288
}
243289

244290
/**
@@ -881,3 +927,17 @@ function execCommandAndGetFirstOutput(command) {
881927
});
882928
});
883929
}
930+
931+
/**
932+
* Display through `console.log` an helping message relative to how to run this
933+
* script.
934+
*/
935+
function displayHelp() {
936+
console.log(
937+
`Usage: node run_bundler.mjs input-file [options]
938+
Available options:
939+
-h, --help Display this help message
940+
-b <branch>, --branch <branch> Specify the branch name the performance results should be compared to.
941+
Defaults to the "dev" branch.`,
942+
);
943+
}

0 commit comments

Comments
 (0)