1
1
#! /bin/bash
2
+ function assertShaLike() {
3
+ local shaVarName=" ${1} "
4
+ local sha=" ${! 1} "
5
+ if [ -z " ${sha} " ] || ! echo " ${sha} " | grep -qE ' ^[0-9a-fA-F]+$' ; then
6
+ echo " ${shaVarName} (${sha} ) does not look like a commit SHA"
7
+ exit
8
+ fi
9
+ }
10
+
11
+ function assertMatchesPullRequest() {
12
+ local shaVarName=" ${1} "
13
+ local sha=" ${! 1} "
14
+ local pr_id=" ${! 2} "
15
+ if [[ ! " $( git ls-remote origin refs/pull/${pr_id} /head) " =~ ^${sha} .* refs/pull/${pr_id} /head$ ]]; then
16
+ echo " ${shaVarName} (${sha} ) does not match HEAD for pull request ${pr_id} "
17
+ exit
18
+ fi
19
+ }
20
+
2
21
function mandatory() {
3
22
if [ -z " ${! 1} " ]; then
4
23
echo " ${1} not set"
@@ -25,8 +44,9 @@ echo "Use case 1: We want to test the impact of a PR on a branch."
25
44
echo " To run this, declare:"
26
45
echo " The script expects the following variables to be set:"
27
46
echo " CATEGORY = a category of tests to run - folders in benchmark/"
28
- echo " BRANCH = the branch the test should be based off. e.g. master"
47
+ echo " BASE = the branch the test should be based off. e.g. master"
29
48
echo " PULL_ID = the pull request that contains changes to test"
49
+ echo " TARGET = the SHA of the commit HEAD that contains changes to test"
30
50
echo " -------------------------------------------------------------"
31
51
echo " Use case 2: We want to compare two branches, tags or commits."
32
52
echo " To run this, declare:"
@@ -48,8 +68,10 @@ if [ -z $PULL_ID ]; then
48
68
mandatory TARGET
49
69
else
50
70
export USE_CASE=1
51
- mandatory BRANCH
71
+ mandatory BASE
52
72
mandatory PULL_ID
73
+ mandatory TARGET
74
+ assertShaLike TARGET
53
75
fi
54
76
mandatory CATEGORY
55
77
optional RUNS
@@ -59,11 +81,13 @@ getMACHINE_THREADS=`cat /proc/cpuinfo |grep processor|tail -n1|awk {'print $3'}`
59
81
let getMACHINE_THREADS=getMACHINE_THREADS+1 # getting threads this way is 0 based. Add one
60
82
optional MACHINE_THREADS $getMACHINE_THREADS
61
83
rm -rf node
62
- git clone https://github.com/nodejs/node.git
84
+ git clone --depth=1 https://github.com/nodejs/node.git
63
85
cd node
64
86
case $USE_CASE in
65
87
1)
66
- git checkout $BRANCH
88
+ # Validate TARGET and pull request HEAD are consistent
89
+ assertMatchesPullRequest TARGET PULL_ID
90
+ git checkout $BASE
67
91
;;
68
92
2)
69
93
git checkout $BASE
@@ -81,7 +105,7 @@ mv out/Release/node ./node-master
81
105
# build pr
82
106
case $USE_CASE in
83
107
1)
84
- curl -L https://github.com/nodejs/node/pull/ ${PULL_ID } .patch| git apply -3
108
+ curl -L " https://github.com/nodejs/node/compare/ $( git rev-parse HEAD ) ... ${TARGET } .patch" | git apply -3
85
109
;;
86
110
2)
87
111
git checkout $TARGET
0 commit comments