Merge "Configure tep-ip for genius auto tunnels"
[releng/builder.git] / jjb / integration / multipatch-distribution.sh
1 # TODO: 1) clean up inline todo's below :)
2 # TODO: 2) Use just a topic branch to create a distribution.  see this email:
3 #          https://lists.opendaylight.org/pipermail/discuss/2015-December/006040.html
4 # TODO: 3) Bubble up CSIT jobs that are triggered by the multipatch job to a jenkins
5 #          parameter.  the default can be distribution-test which calls all CSIT jobs
6 #          but being able to easily override it to a smaller subset (or none) will be
7 #          helpful
8
9 # create a fresh empty place to build this custom distribution
10 BUILD_DIR=${WORKSPACE}/patch_tester
11 POM_FILE=${WORKSPACE}/patch_tester/pom.xml
12 DISTRIBUTION_BRANCH_TO_BUILD=$DISTROBRANCH  #renaming variable for clarity
13
14 rm -rf $BUILD_DIR
15 mkdir -p $BUILD_DIR
16 cd $BUILD_DIR || exit 1
17
18 # create a root pom that will contain a module for each project we have a patch for
19 echo "<project>" >> $POM_FILE
20 echo "<groupId>org.opendaylight.test</groupId>" >> $POM_FILE
21 echo "<artifactId>test</artifactId>" >> $POM_FILE
22 echo "<version>0.1</version>" >> $POM_FILE
23 echo "<modelVersion>4.0.0</modelVersion>" >> $POM_FILE
24 echo "<packaging>pom</packaging>" >> $POM_FILE
25 echo "<modules>" >> $POM_FILE
26
27 # Set up git committer name and email, needed for commit creation when cherry-picking.
28 export EMAIL="sandbox@jenkins.opendaylight.org"
29 # TODO: Is there a more appropriate e-mail?
30 export GIT_COMMITTER_NAME="Multipatch Job"
31
32 # TODO: Is "patches" still the correct word?
33 if [ -n "$GERRIT_EVENT_COMMENT_TEXT" ]; then
34     PATCHES_TO_BUILD=$(echo "$GERRIT_EVENT_COMMENT_TEXT" \
35         | grep 'multipatch-build:' | awk -F: '{print $2}')
36 fi
37 IFS=',' read -ra PATCHES <<< "${PATCHES_TO_BUILD}"
38
39 # For each patch:
40 # * Clone the project.
41 # * Optionally, checkout a specific (typically unmerged) Gerrit patch. If none,
42 #   default to Integration/Distribution branch via {branch} JJB param.
43 # * Also optionally, cherry-pick series of patchs on top of the checkout.
44 # * Final option: perform a 'release' by removing "-SNAPSHOT" everywhere within the project.
45 #
46 # Each patch is found in the ${PATCHES_TO_BUILD} variable as a comma separated
47 # list of project[=checkout][:cherry-pick]* values.
48 #
49 # Checkout a (typically unmerged) Gerrit patch on top of odlparent's git clone:
50 #
51 # PATCHES_TO_BUILD='odlparent=45/30045/2'
52 #
53 # Checkout patchs for both odlparent and yangtools.
54 #
55 # PATCHES_TO_BUILD='odlparent=45/30045/2,yangtools:53/26853/25'
56 #
57 # Checkout a patch for controller, cherry-pick another patch on top of it.
58 #
59 # PATCHES_TO_BUILD='controller=61/29761/5:45/29645/6'
60 distribution_status="not_included"
61 for proto_patch in "${PATCHES[@]}"
62 do
63     echo "working on ${proto_patch}"
64     # For patch=controller=61/29761/5:45/29645/6, this gives controller
65     PROJECT="$(echo ${proto_patch} | cut -d\: -f 1 | cut -d\= -f 1)"
66     if [ "${PROJECT}" == "integration/distribution" ]; then
67         distribution_status="included"
68     fi
69     PROJECT_SHORTNAME="${PROJECT##*/}"  # http://stackoverflow.com/a/3162500
70     echo "cloning project ${PROJECT}"
71     git clone "https://git.opendaylight.org/gerrit/p/${PROJECT}"
72     echo "<module>${PROJECT_SHORTNAME}</module>" >> ${POM_FILE}
73     cd ${PROJECT_SHORTNAME} || exit 1
74     if [ "$(echo -n ${proto_patch} | tail -c 1)" == 'r' ]; then
75         pure_patch="$(echo -n $proto_patch | head -c -1)"
76     else
77         pure_patch="$proto_patch"
78     fi
79     # For patch = controller=61/29761/5:45/29645/6, this gives 61/29761/5
80     CHECKOUT="$(echo ${pure_patch} | cut -d\= -s -f 2 | cut -d\: -f 1)"
81     if [ "x${CHECKOUT}" != "x" ]; then
82         echo "checking out ${CHECKOUT}"
83         # TODO: Make this script accept "29645/6" as a shorthand for "45/29645/6".
84         git fetch "https://git.opendaylight.org/gerrit/${PROJECT}" "refs/changes/$CHECKOUT"
85         git checkout FETCH_HEAD
86     else
87         echo "checking out ${DISTRIBUTION_BRANCH_TO_BUILD}"
88         git checkout "${DISTRIBUTION_BRANCH_TO_BUILD}"
89     fi
90     # For patch=controller=61/29761/5:45/29645/6, this gives 45/29645/6
91     PICK_SEGMENT="$(echo "${pure_patch}" | cut -d\: -s -f 2-)"
92     IFS=':' read -ra PICKS <<< "${PICK_SEGMENT}"
93     for pick in "${PICKS[@]}"
94     do
95         echo "cherry-picking ${pick}"
96         git fetch "https://git.opendaylight.org/gerrit/${PROJECT}" "refs/changes/${pick}"
97         git cherry-pick --ff --keep-redundant-commits FETCH_HEAD
98     done
99     if [ "$(echo -n ${proto_patch} | tail -c 1)" == 'r' ]; then
100         # Here 'r' means release. Useful for testing Nitrogen Odlparent changes.
101         find . -name "*.xml" -print0 | xargs -0 sed -i 's/-SNAPSHOT//g'
102     fi
103     cd "${BUILD_DIR}" || exit 1
104 done
105
106 if [ "${distribution_status}" == "not_included" ]; then
107     echo "adding integration/distribution"
108     # clone distribution and add it as a module in root pom
109     git clone "https://git.opendaylight.org/gerrit/p/integration/distribution"
110     cd distribution || exit 1
111     git checkout "${DISTRIBUTION_BRANCH_TO_BUILD}"
112     cd "${BUILD_DIR}" || exit 1
113     echo "<module>distribution</module>" >> ${POM_FILE}
114 fi
115
116 # finish pom file
117 echo "</modules>" >> "${POM_FILE}"
118 echo "</project>" >> "${POM_FILE}"