forked from cms-sw/cms-bot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cms-externals-pr-test
executable file
·152 lines (125 loc) · 5.55 KB
/
cms-externals-pr-test
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
#!/bin/sh -ex
env
# The following should be set by jenkins or in the parameters if run in docker:
# - SCRAM_ARCH
# - RELEASE_QUEUE
# - CMSDIST_PR is the pull request in cmsdist that you want to test. It must have the format
# #<pr-number>
# - EXTERNAL_PR is a pull request made to a repository in cms-externals it need. It must
# have the format: cms-externals/<package-repo>#<pr-number>
# - FINAL_PACKAGE is the package that you want to force to test. For example cmssw-tool-conf
# if you don't set it, the package of te external pr will be used. If you are only testing
# a cmsdist pr, you must use -fp to set it
# If it is not run by jenkins it sets up a default workspace
WORKSPACE=${WORKSPACE-/build}
CMSDIST_PATH=$WORKSPACE/cmsdist
PKGTOOLS_PATH=$WORKSPACE/pkgtools
INTERACTIVE=${INTERACTIVE-}
JOBS=${JOBS-1}
export SCRAM_ARCH=$ARCHITECTURE
RESULTS_DIR=$WORKSPACE/results
mkdir -p $RESULTS_DIR
while [ X$# != X0 ] ; do
case $1 in
-c) shift ; CMSDIST_PATH=$1 ; shift ;;
-p) shift ; PKGTOOLS_PATH=$1 ; shift ;;
-a) shift ; SCRAM_ARCH=$1 ; shift ;;
-q) shift ; RELEASE_QUEUE=$1 ; shift ;;
-i) shift ; INTERACTIVE=$1 ; shift ;;
-j) shift ; JOBS=$1 ; shift ;;
-pr) shift ; EXTERNAL_PR=$1 ; shift ;;
-fp) shift ; FINAL_PACKAGE=$1 ; shift ;;
-cpr) shift ; CMSDIST_PR=$1 ; shift ;;
*) shift ; echo unknown option ;;
esac
done
if [ "X$SCRAM_ARCH" = X ] || [ "X$RELEASE_QUEUE" = X ]; then
echo "You need to specify SCRAM_ARCH (-a) and RELEASE_QUEUE (-q)"
exit 1
fi
eval `curl https://raw.githubusercontent.com/cms-sw/cms-bot/master/config.map | grep "SCRAM_ARCH=$SCRAM_ARCH;" | grep "RELEASE_QUEUE=$RELEASE_QUEUE;"`
if [ ! -d "$CMSDIST_PATH" ]; then
git clone https://github.com/cms-sw/cmsdist.git $CMSDIST_PATH
fi
if [ ! -d "$PKGTOOLS_PATH" ]; then
git clone https://github.com/cms-sw/pkgtools.git $PKGTOOLS_PATH
fi
pushd $PKGTOOLS_PATH ; git fetch origin ; git checkout $PKGTOOLS_TAG; popd
pushd $CMSDIST_PATH ; git remote -v ; git fetch origin $CMSDIST_TAG ; git checkout FETCH_HEAD; popd
BUILD_REPO=`echo $EXTERNAL_PR | sed -e 's|[#@].*||;s|/.*||'`
BUILD_PACKAGE=`echo $EXTERNAL_PR | sed -e 's|[#@].*||;s|.*/||'`
LAST_COMMIT='undefined'
case $EXTERNAL_PR in
*[#]*)
BUILD_PR=`echo $EXTERNAL_PR | sed -e 's|.*#||'`
BUILD_PR_URL=`echo https://api.github.com/repos/$EXTERNAL_PR | sed -e "s|#|/pulls/|"`
# Find out basic details about the PR
BASE_REPO=`curl -s $BUILD_PR_URL | jq '.["base"]["repo"]["clone_url"]' | sed -e 's/"//g'`
BASE_BRANCH=`curl -s $BUILD_PR_URL | jq '.["base"]["ref"]' | sed -e 's/"//g'`
HEAD_REPO=`curl -s $BUILD_PR_URL | jq '.["head"]["repo"]["clone_url"]' | sed -e 's/"//g'`
HEAD_BRANCH=`curl -s $BUILD_PR_URL | jq '.["head"]["ref"]' | sed -e 's/"//g'`
;;
*[@]*)
# This is in case we want to specify a given version of the external.
BASE_REPO=https://github.com/$BUILD_REPO/$BUILD_PACKAGE
BASE_BRANCH=`echo $EXTERAL_PR | sed -e 's|.*[@]||'`
HEAD_REPO=$BASE_REPO
HEAD_BRANCH=$BASE_BRANCH
;;
*)
echo "No PR specified, will not checkout any external."
;;
esac
if [ ! "X$EXTERNAL_PR" = X ]; then
# Clone the repository and merge the pull request.
git clone -b $BASE_BRANCH $BASE_REPO $BUILD_PACKAGE
pushd $WORKSPACE/$BUILD_PACKAGE
git config user.email "[email protected]"
git config user.name "CMS BOT"
git pull $HEAD_REPO $HEAD_BRANCH
HEAD_REF=`git rev-parse HEAD`
popd
fi
# Merge CMSDIST_PR if found.
if [ ! X$CMSDIST_PR = X ]; then
CMSDIST_BUILD_PR_URL="https://api.github.com/repos/cms-sw/cmsdist/pulls/$CMSDIST_PR"
CMSDIST_BASE_BRANCH=`curl -s $CMSDIST_BUILD_PR_URL | jq '.["base"]["ref"]' | sed -e 's/"//g'`
CMSDIST_HEAD_REPO=`curl -s $CMSDIST_BUILD_PR_URL | jq '.["head"]["repo"]["clone_url"]' | sed -e 's/"//g'`
CMSDIST_HEAD_BRANCH=`curl -s $CMSDIST_BUILD_PR_URL | jq '.["head"]["ref"]' | sed -e 's/"//g'`
# Workaround needed since git pull for cmsdist does not work, for some reason
# inside a docker container.
git clone -b $CMSDIST_HEAD_BRANCH $CMSDIST_HEAD_REPO $WORKSPACE/cmsdist-pr
pushd $CMSDIST_PATH
git checkout $CMSDIST_BASE_BRANCH
git config user.email "[email protected]"
git config user.name "CMS BOT"
git pull $WORKSPACE/cmsdist-pr/.git $CMSDIST_HEAD_BRANCH
LAST_COMMIT=`git log --pretty="%H" | head -n1`
popd
fi
# If a PR is specified for an external, we rewrite the spec file
# to point out to it.
if [ ! X$EXTERNAL_PR = X ]; then
perl -p -i -e "s|%define branch.*|%define branch ${BASE_BRANCH}|" cmsdist/${BUILD_PACKAGE}.spec
perl -p -i -e "s|%define tag.*|%define tag ${HEAD_REF}|" cmsdist/${BUILD_PACKAGE}.spec
perl -p -i -e "s|^Source.*|Source: git:$WORKSPACE/$BUILD_PACKAGE/.git?obj=${BASE_BRANCH}/%{tag}&export=%{n}-%{realversion}&output=/%{n}-%{realversion}-%{tag}.tgz|" cmsdist/${BUILD_PACKAGE}.spec
fi
# In case we do not pass -fp we build the package to which the PR refers to.
# You can use this for example to force building cmssw-tool-conf.
FINAL_PACKAGE=${FINAL_PACKAGE-$BUILD_PACKAGE}
if [ X$INTERACTIVE = X1 ]; then
echo "Run "
echo
echo pkgtools/cmsBuild -c cmsdist -a $SCRAM_ARCH -j $JOBS --work-dir w build $FINAL_PACKAGE
echo
echo to build
bash
fi
if [ "X$AUTO_POST_MESSAGE_CMSDIST" = Xtrue ]; then
# For now it will only work if a cmsdist pr is specified.
$WORKSPACE/report-cmsdist-pull-request-results ${BUILD_NUMBER} $CMSDIST_PR $SCRAM_ARCH $LAST_COMMIT TESTING $FINAL_PACKAGE || true
fi
pushd $RESULTS_DIR
$PKGTOOLS_PATH/cmsBuild -c $CMSDIST_PATH -a $SCRAM_ARCH -j $JOBS --work-dir $RESULTS_DIR/w build $FINAL_PACKAGE 2>&1 | tee -a $RESULTS_DIR/build.log
popd
echo 'ALL_OK'