Merge "Fix: bashisms - step 2"
[releng/builder.git] / jjb / integration / integration-compare-distributions.sh
1 #!/bin/bash -l
2
3 # Depends on variables created and published from the integration-set-variables script
4
5 # Do not fail the build if there is trouble trying to collect distribution patch diffs
6 set +e
7
8 NEXUSURL_PREFIX=${ODLNEXUSPROXY:-https://nexus.opendaylight.org}
9 ODL_NEXUS_REPO=${ODL_NEXUS_REPO:-content/repositories/opendaylight.snapshot}
10 GERRIT_PATH=${GERRIT_PATH:-git.opendaylight.org/gerrit}
11 DISTROBRANCH=${DISTROBRANCH:-$GERRIT_BRANCH}
12
13 # Obtain current pom.xml of integration/distribution, correct branch.
14 if [[ "$KARAF_ARTIFACT" == "opendaylight" ]]; then
15     wget "http://${GERRIT_PATH}/gitweb?p=integration/distribution.git;a=blob_plain;f=opendaylight/pom.xml;hb=refs/heads/$DISTROBRANCH" -O "pom.xml"
16 elif [[ "$KARAF_ARTIFACT" == "karaf" ]]; then
17     wget "http://${GERRIT_PATH}/gitweb?p=integration/distribution.git;a=blob_plain;f=pom.xml;hb=refs/heads/$DISTROBRANCH" -O "pom.xml"
18 elif [[ "$KARAF_ARTIFACT" == "netconf-karaf" ]]; then
19     wget "http://${GERRIT_PATH}/gitweb?p=${KARAF_PROJECT}.git;a=blob_plain;f=karaf/pom.xml;hb=refs/heads/$DISTROBRANCH" -O "pom.xml"
20 elif [[ "$KARAF_ARTIFACT" == "controller-test-karaf" ]]; then
21     wget "http://${GERRIT_PATH}/gitweb?p=${KARAF_PROJECT}.git;a=blob_plain;f=karaf/pom.xml;hb=refs/heads/$DISTROBRANCH" -O "pom.xml"
22 elif [[ "$KARAF_ARTIFACT" == "bgpcep-karaf" ]]; then
23     wget "http://${GERRIT_PATH}/gitweb?p=${KARAF_PROJECT}.git;a=blob_plain;f=distribution-karaf/pom.xml;hb=refs/heads/$DISTROBRANCH" -O "pom.xml"
24 else
25     wget "http://${GERRIT_PATH}/gitweb?p=integration/distribution.git;a=blob_plain;f=pom.xml;hb=refs/heads/$DISTROBRANCH" -O "pom.xml"
26 fi
27
28 # Extract the BUNDLE_VERSION from the pom.xml
29 # TODO: remove the second xpath command once the old version in CentOS 7 is not used any more
30 BUNDLE_VERSION=$(xpath -e '/project/version/text()' pom.xml 2>/dev/null ||
31     xpath pom.xml '/project/version/text()' 2>/dev/null)
32 echo "Bundle version is ${BUNDLE_VERSION}"
33 # Acquire the timestamp information from maven-metadata.xml
34 NEXUSPATH="${NEXUSURL_PREFIX}/${ODL_NEXUS_REPO}/org/opendaylight/${KARAF_PROJECT}/${KARAF_ARTIFACT}"
35 wget "${NEXUSPATH}/${BUNDLE_VERSION}/maven-metadata.xml"
36
37 # shellcheck disable=SC2181
38 if [ $? -ne 0 ]; then
39   echo "unable to find maven-metadata.xml. no need to continue..."
40   exit 0
41 fi
42
43 less maven-metadata.xml
44 # TODO: remove the second xpath command once the old version in CentOS 7 is not used any more
45 TIMESTAMP=$(xpath -e "//snapshotVersion[extension='zip'][1]/value/text()" maven-metadata.xml 2>/dev/null ||
46     xpath maven-metadata.xml "//snapshotVersion[extension='zip'][1]/value/text()" 2>/dev/null)
47 echo "Nexus timestamp is ${TIMESTAMP}"
48 BUNDLEFOLDER="${KARAF_ARTIFACT}-${BUNDLE_VERSION}"
49 BUNDLE="${KARAF_ARTIFACT}-${TIMESTAMP}.zip"
50 ACTUAL_BUNDLE_URL="${NEXUSPATH}/${BUNDLE_VERSION}/${BUNDLE}"
51
52 wget --progress=dot:mega "$ACTUAL_BUNDLE_URL"
53 echo "Extracting the last distribution found on nexus..."
54 unzip -q "$BUNDLE"
55 mv "$BUNDLEFOLDER" /tmp/distro_old
56 rm "$BUNDLE"
57
58 echo "Extracting the distribution just created by this job..."
59 NEW_DISTRO="$(find "$WORKSPACE" -name "${KARAF_ARTIFACT}*.zip")"
60 NEW_DISTRO_BASENAME="$(basename "$NEW_DISTRO")"
61 cp "$NEW_DISTRO" /tmp/
62 cd /tmp/ || exit
63 unzip "$NEW_DISTRO_BASENAME"
64 mv "$BUNDLEFOLDER" distro_new
65
66 git clone https://git.opendaylight.org/gerrit/integration/test.git
67 cd test/tools/distchanges || exit
68 mkdir -p "$WORKSPACE"/archives
69
70 # Full output of compare tool will be in temp file /tmp/dist_diff.txt
71 # The file/report to be archived will only list the distribution in the comparison and the patches that
72 # are different.
73 python distcompare.py -r "ssh://jenkins-$SILO@git.opendaylight.org:29418" | tee /tmp/dist_diff.txt
74 echo -e "Patch differences listed are in comparison to:\n\t$ACTUAL_BUNDLE_URL\n\n" > "$WORKSPACE"/archives/distribution_differences.txt
75 sed -ne '/Patch differences/,$ p' /tmp/dist_diff.txt >> "$WORKSPACE"/archives/distribution_differences.txt
76
77 # Check OpenDaylight YANG modules:
78 echo "Installing pyang"
79 pip install --user pyang
80 if [ -f /tmp/distro_new/bin/extract_modules.sh ]; then
81     echo "Extracting YANG modules"
82     /tmp/distro_new/bin/extract_modules.sh
83     echo "Checking YANG modules"
84     /tmp/distro_new/bin/check_modules.sh
85     mv /tmp/distro_new/opendaylight-models "$WORKSPACE"/archives
86 fi