Skip to content

Commit

Permalink
feat: retrieve the v8 flags from @codspeed/core
Browse files Browse the repository at this point in the history
Co-authored-by: @adriencaccia
  • Loading branch information
art049 authored and adriencaccia committed Jun 27, 2023
1 parent f5d6dfd commit 6f23d65
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 30 deletions.
38 changes: 11 additions & 27 deletions dist/bin/node
Original file line number Diff line number Diff line change
Expand Up @@ -9,40 +9,24 @@ set -eo pipefail
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
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
# Retrieve the V8 flags from @codspeed/core
V8_FLAGS=$($REAL_NODE_PATH -e "
try {
const { getV8Flags } = require('@codspeed/core');
console.log(getV8Flags('$NODE_MAJOR_VERSION'))
} catch(e) {}
")

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

# Call the real "node" command with any arguments passed to this script.
$REAL_NODE_PATH "${V8_FLAGS[@]}" "$@"
$REAL_NODE_PATH $V8_FLAGS "$@"
2 changes: 1 addition & 1 deletion dist/index.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dist/index.js.map

Large diffs are not rendered by default.

14 changes: 14 additions & 0 deletions src/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,20 @@ const run = async (inputs: ActionInputs): Promise<{profileFolder: string}> => {
PATH: `${customBinPath}:${process.env.PATH}`,
PYTHONMALLOC: "malloc",
PYTHONHASHSEED: "0",
/**
* @deprecated this should not be used to add new flags and
* the getV8Flags from codspeed-node should be preferred
* (available from 1.2.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 6f23d65

Please sign in to comment.