Skip to content

Commit

Permalink
feat: add a custom node script that adds codspeed v8 flags
Browse files Browse the repository at this point in the history
  • Loading branch information
adriencaccia committed Jun 27, 2023
1 parent ff68429 commit e688eae
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 19 deletions.
3 changes: 2 additions & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
dist/** -diff linguist-generated=true
dist/** -diff linguist-generated=true
dist/bin/node -diff linguist-generated=false
48 changes: 48 additions & 0 deletions dist/bin/node
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#!/bin/bash
set -eo pipefail

# Custom script to replace node and run with V8 flags that make the execution of the
# benchmarks more predictable.
# Depending on the version of node, some flags may be deprecated.

# Retrieve the original path by removing the folder containing CodSpeedHQ/action from the path.
ORIGINAL_PATH=$(echo "$PATH" | tr ":" "\n" | grep -v "CodSpeedHQ/action" | tr "\n" ":")
# Check if node is in the original path.
if ! env PATH="$ORIGINAL_PATH" which node &>/dev/null; then
echo "Error: node not found in PATH. There might be a problem with the node installation."
exit 1
fi
# Save the real node path.
REAL_NODE_PATH=$(env PATH="$ORIGINAL_PATH" which node)

V8_FLAGS=(
"--hash-seed=1"
"--random-seed=1"
"--no-opt"
"--predictable"
"--predictable-gc-schedule"
)

# get node major version, using bash regex
NODE_MAJOR_VERSION=$($REAL_NODE_PATH --version | sed -E 's/^v([0-9]+)\..*$/\1/')

# add flags deprecated in node 18 in older versions
if [ "$NODE_MAJOR_VERSION" -lt 18 ]; then
V8_FLAGS=(
"${V8_FLAGS[@]}"
"--no-randomize-hashes"
)
fi
# add flags deprecated in node 20 in older versions
if [ "$NODE_MAJOR_VERSION" -lt 20 ]; then
V8_FLAGS=(
"${V8_FLAGS[@]}"
"--no-scavenge-task"
)
fi

echo "::debug::Running the CodSpeed node script, the node command that will be run:"
echo "::debug::$REAL_NODE_PATH" "${V8_FLAGS[@]}" "$@"

# Call the real "node" command with any arguments passed to this script.
$REAL_NODE_PATH "${V8_FLAGS[@]}" "$@"
12 changes: 6 additions & 6 deletions dist/index.js

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions dist/index.js.map

Large diffs are not rendered by default.

14 changes: 5 additions & 9 deletions src/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ const run = async (inputs: ActionInputs): Promise<{profileFolder: string}> => {
// Fixes a compatibility issue with cargo 1.66+ running directly under valgrind <3.20
const benchCommand = inputs.run.replace("cargo codspeed", "cargo-codspeed");

const customBinPath = `${__dirname}/bin`;
core.debug(`custom bin path: ${customBinPath}`);

try {
await exec(
[
Expand All @@ -85,17 +88,10 @@ const run = async (inputs: ActionInputs): Promise<{profileFolder: string}> => {
{
env: {
...process.env,
// prepend the custom dist/bin folder to the path, to run our custom node script instead of the regular node
PATH: `${customBinPath}:${process.env.PATH}`,
PYTHONMALLOC: "malloc",
PYTHONHASHSEED: "0",
CODSPEED_V8_FLAGS: [
"--hash-seed=1",
"--random-seed=1",
"--no-randomize-hashes",
"--no-scavenge-task",
"--no-opt ",
"--predictable ",
"--predictable-gc-schedule",
].join(" "),
ARCH: arch,
CODSPEED_ENV: "github",
},
Expand Down

0 comments on commit e688eae

Please sign in to comment.