forked from truenas/middleware
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkins-depends.sh
executable file
·98 lines (83 loc) · 3.33 KB
/
Jenkins-depends.sh
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
#!/bin/sh
# Helper script which reads some pipeline ENV settings and figures out GH PR details
populate_pr_pipeline()
{
if [ -z "$CHANGE_ID" ] ; then return 0; fi
if [ -z "$GH_ORG" ] ; then return 0; fi
if [ -z "$GH_REPO" ] ; then return 0; fi
ORG="$GH_ORG"
PRBUILDER="$GH_REPO"
# Fetch the details from github API
echo "curl https://api.github.com/repos/$ORG/$PRBUILDER/pulls/$CHANGE_ID"
curl "https://api.github.com/repos/$ORG/$PRBUILDER/pulls/$CHANGE_ID" > /tmp/jsonout.$$
#echo "Raw GH output:"
#cat /tmp/jsonout.$$
ghprbTargetBranch=$(cat /tmp/jsonout.$$ | jq -r '.base.ref')
ghprbSourceBranch=$(cat /tmp/jsonout.$$ | jq -r '.base.ref')
ghprbCommentBody=$(cat /tmp/jsonout.$$ | jq -r '.body')
ghprbPullLongDescription=$(cat /tmp/jsonout.$$ | jq -r '.body')
rm /tmp/jsonout.$$
export ghprbTargetBranch ghprbSourceBranch ghprbCommentBody ghprbPullLongDescription
export PRBUILDER
export BUILDINCREMENTAL="YES"
export ARTIFACTONFAIL=yes
export ARTIFACTONSUCCESS=yes
echo "** Populated GitHub PR details: **"
echo "ghprbTargetBranch: $ghprbTargetBranch"
echo "ghprbSourceBranch: $ghprbSourceBranch"
echo "ghprbCommentBody: $ghprbCommentBody"
echo "ghprbPullLongDescription: $ghprbPullLongDescription"
# Something went wrong?
if [ -z "$ghprbTargetBranch" ] ; then exit 1 ; fi
}
get_depends()
{
if [ -z "$ghprbPullLongDescription" ] ; then return 0; fi
# Are there DEPENDS listed?
echo "$ghprbPullLongDescription" | grep -q "DEPENDS:"
if [ $? -ne 0 ] ; then return 0; fi
echo -e "$ghprbPullLongDescription" > /tmp/.depsParse.$$
while read line
do
echo $line | grep -q "DEPENDS:"
if [ $? -ne 0 ] ; then continue; fi
_depsLine=`echo $line | sed -n -e 's/^.*DEPENDS: //p' | cut -d '\' -f 1`
echo "*** Found PR DEPENDS Line: $_depsLine ***"
_deps="$_deps $_depsLine"
done < /tmp/.depsParse.$$
rm /tmp/.depsParse.$$
for prtgt in $_deps
do
if [ -z "$prtgt" ] ; then continue ; fi
if [ "$prtgt" = " " ] ; then continue ; fi
echo "*** Found PR DEPENDS: $_prtgt ***"
# Pull the target PR/Repo
tgt=`echo $prtgt | sed 's|http://||g'`
tgt=`echo $tgt | sed 's|https://||g'`
tgt=`echo $tgt | sed 's|www.github.com||g'`
tgt=`echo $tgt | sed 's|github.com||g'`
tgt=`echo $tgt | sed 's|^/||g'`
tproject=`echo $tgt | cut -d '/' -f 1`
trepo=`echo $tgt | cut -d '/' -f 2`
tbranch=`echo $tgt | cut -d '/' -f 3-`
tbranch=`echo $tbranch | sed 's|^tree/||g' | tr -d '\n\r' | tr -d '\n'`
if [ -d "/freenas-pr/freenas/_BE/${trepo}" ] ; then
rm -rf /freenas-pr/freenas/_BE/${trepo}
else
echo "*** Warning, no such git repo currently checked out: $trepo***"
fi
# TODO, maybe skip git and use fetch to download from githum ala:
# fetch https://github.com/freenas/os/archive/sef-icp-amd64-test.tar.gz
echo "*** Cloning DEPENDS repo https://github.com/$tproject/$trepo $tbranch***"
git clone --depth=1 -b ${tbranch} https://github.com/${tproject}/${trepo} /freenas-pr/freenas/_BE/${trepo} 2>/tmp/.ghClone.$$ >/tmp/.ghClone.$$
if [ $? -ne 0 ] ; then
cat /tmp/.ghClone.$$
rm /tmp/.ghClone.$$
echo "**** ERROR: Failed: git clone --depth=1 -b $tbranch https://github.com/$tproject/$trepo /freenas-pr/freenas/_BE/${trepo} ****"
exit 1
fi
rm /tmp/.ghClone.$$
done
}
populate_pr_pipeline
get_depends