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"
@@ -27,6 +46,7 @@ echo "The script expects the following variables to be set:"
27
46
echo " CATEGORY = a category of tests to run - folders in benchmark/"
28
47
echo " BRANCH = 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:"
50
70
export USE_CASE=1
51
71
mandatory BRANCH
52
72
mandatory PULL_ID
73
+ mandatory TARGET
74
+ assertShaLike TARGET
53
75
fi
54
76
mandatory CATEGORY
55
77
optional RUNS
@@ -63,6 +85,8 @@ git clone https://github.com/nodejs/node.git
63
85
cd node
64
86
case $USE_CASE in
65
87
1)
88
+ # Validate TARGET and pull request HEAD are consistent
89
+ assertMatchesPullRequest TARGET PULL_ID
66
90
git checkout $BRANCH
67
91
;;
68
92
2)
@@ -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