Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add custom node script #72

Merged
merged 2 commits into from
Jun 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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/')
art049 marked this conversation as resolved.
Show resolved Hide resolved

# 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[@]}" "$@"
14 changes: 7 additions & 7 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.

5 changes: 4 additions & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import run from "./run";
import upload from "./upload";

const VERSION = process.env.VERSION;
const CODSPEED_SKIP_UPLOAD = process.env.CODSPEED_SKIP_UPLOAD === "true";

const banner = String.raw`
______ __ _____ __
Expand All @@ -22,7 +23,9 @@ async function main(): Promise<void> {
const inputs = getActionInputs();
await prepare();
const {profileFolder} = await run(inputs);
await upload(inputs, profileFolder);
if (!CODSPEED_SKIP_UPLOAD) {
await upload(inputs, profileFolder);
}
} catch (error) {
if (error instanceof Error) core.setFailed(error.message);
}
Expand Down
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