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

Harden benchmark script against pull request changes #185

Merged
merged 3 commits into from
Apr 8, 2025
Merged

Conversation

richardlau
Copy link
Member

Require a new TARGET variable specifying the expected SHA of the commit at the HEAD of the pull request when running the benchmark script for pull requests.

@richardlau
Copy link
Member Author

Temporarily switched the benchmark job to use the branch for this PR and will need to switch it back to main (either when this is merged or closed).

Test CI: https://ci.nodejs.org/job/benchmark-node-micro-benchmarks/1690/

Comment on lines 10 to 11
if [[ ! "$(git ls-remote origin refs/pull/${!2}/head)" =~ ^${!1}.*refs/pull/${!2}/head$ ]]; then
echo "${1} (${!1}) does not match HEAD for pull request ${!2}"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we use named variable here instead of numbers for better readability?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Require a new `TARGET` variable specifying the expected SHA of the
commit at the HEAD of the pull request when running the benchmark
script for pull requests.
@richardlau
Copy link
Member Author

@@ -59,10 +81,12 @@ getMACHINE_THREADS=`cat /proc/cpuinfo |grep processor|tail -n1|awk {'print $3'}`
let getMACHINE_THREADS=getMACHINE_THREADS+1 #getting threads this way is 0 based. Add one
optional MACHINE_THREADS $getMACHINE_THREADS
rm -rf node
git clone https://github.com/nodejs/node.git
git clone --depth=1 https://github.com/nodejs/node.git
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
git clone --depth=1 https://github.com/nodejs/node.git
git clone --depth=1 --branch "$BASE" https://github.com/nodejs/node.git

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll leave this for a follow up. Note that I think the suggestion will also require adding a fetch for TARGET in use case 2 to allow git checkout TARGET to succeed when TARGET points to a different branch or commit not on BASE.

cd node
case $USE_CASE in
1)
# Validate TARGET and pull request HEAD are consistent
assertMatchesPullRequest TARGET PULL_ID
git checkout $BRANCH
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The checkout is not necessary on a shallow clone, we can only get the only ref we've pulled during the clone

Suggested change
git checkout $BRANCH

Copy link

@aduh95 aduh95 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Feel free to ignore my comments, I can open a follow up

Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@richardlau
Copy link
Member Author

Feel free to ignore my comments, I can open a follow up

@aduh95 I'll rename BRANCH to BASE as the job in Jenkins would need to be updated to match so that it passes the expected parameters into the script.

I'll leave the single branch clone optimization and case statement simplification to you for a follow up -- I think with that change the script would need to add a fetch for TARGET for use case 2 to be able to check out another branch/commit (not on the BASE branch).

For consistency, rename the BRANCH parameter from use case 1 in the
benchmark script to BASE.
@richardlau
Copy link
Member Author

Test run (BRANCH renamed to BASE): https://ci.nodejs.org/job/benchmark-node-micro-benchmarks/1692/

@richardlau richardlau merged commit 91443a3 into main Apr 8, 2025
@richardlau richardlau deleted the harden branch April 8, 2025 11:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants