ce07fee65b3fe886f1de8776ef21c7c78300c760
[ci-management.git] / jjb / vpp / include-raw-vpp-maven-push.sh
1 #!/bin/bash
2 set -xe -o pipefail
3 echo "*******************************************************************"
4 echo "* STARTING PUSH OF PACKAGES TO REPOS"
5 echo "* NOTHING THAT HAPPENS BELOW THIS POINT IS RELATED TO BUILD FAILURE"
6 echo "*******************************************************************"
7
8 MVN="/opt/apache/maven/bin/mvn"
9 GROUP_ID="io.fd.${PROJECT}"
10 BASEURL="${NEXUSPROXY}/content/repositories/fd.io."
11 BASEREPOID='fdio-'
12
13 function push_file ()
14 {
15     push_file=$1
16     repoId=$2
17     url=$3
18     version=$4
19     artifactId=$5
20     file_type=$6
21     classifier=$7
22
23     if [ "$classifier" ]; then
24         d_classifier="-Dclassifier=$7"
25     fi
26
27     # Disable checks for doublequote to prevent glob / splitting
28     # shellcheck disable=SC2086
29     $MVN org.apache.maven.plugins:maven-deploy-plugin:deploy-file \
30         -Dfile=$push_file -DrepositoryId=$repoId \
31         -Durl=$url -DgroupId=$GROUP_ID \
32         -Dversion=$version -DartifactId=$artifactId \
33         -Dtype=$file_type $d_classifier\
34         -gs $GLOBAL_SETTINGS_FILE -s $SETTINGS_FILE
35
36     # make sure the script bombs if we fail an upload
37     if [ "$?" != '0' ]; then
38         echo "ERROR: There was an error with the upload"
39         exit 1
40     fi
41 }
42
43 function push_jar ()
44 {
45     jarfile=$1
46     repoId="${BASEREPOID}snapshot"
47     url="${BASEURL}snapshot"
48
49     basefile=$(basename -s .jar "$jarfile")
50     artifactId=$(echo "$basefile" | rev | cut -d '-' -f 2-  | rev)
51     version=$(echo "$basefile" | rev | cut -d '-' -f 1  | rev)
52
53     push_file "$jarfile" "$repoId" "$url" "${version}-SNAPSHOT" "$artifactId" jar
54 }
55
56 function push_deb ()
57 {
58     debfile=$1
59     repoId="fd.io.${REPO_NAME}"
60     url="${BASEURL}${REPO_NAME}"
61
62     basefile=$(basename -s .deb "$debfile")
63     artifactId=$(echo "$basefile" | cut -f 1 -d '_')
64     version=$(echo "$basefile" | cut -f 2- -d '_')
65
66     push_file "$debfile" "$repoId" "$url" "$version" "$artifactId" deb deb
67 }
68
69 function push_rpm ()
70 {
71     rpmfile=$1
72     repoId="fd.io.${REPO_NAME}"
73     url="${BASEURL}${REPO_NAME}"
74
75     if grep -qE '\.s(rc\.)?rpm' <<<"$rpmfile"
76     then
77         rpmrelease=$(rpm -qp --queryformat="%{release}.src" "$rpmfile")
78     else
79         rpmrelease=$(rpm -qp --queryformat="%{release}.%{arch}" "$rpmfile")
80     fi
81     artifactId=$(rpm -qp --queryformat="%{name}" "$rpmfile")
82     version=$(rpm -qp --queryformat="%{version}" "$rpmfile")
83     push_file "$rpmfile" "$repoId" "$url" "${version}-${rpmrelease}" "$artifactId" rpm
84 }
85
86 if [ "${OS}" == "ubuntu1404" ]; then
87     # Find the files
88     JARS=$(find . -type f -iname '*.jar')
89     DEBS=$(find . -type f -iname '*.deb')
90     for i in $JARS
91     do
92         push_jar "$i"
93     done
94
95     for i in $DEBS
96     do
97         push_deb "$i"
98     done
99 elif [ "${OS}" == "ubuntu1604" ]; then
100     DEBS=$(find . -type f -iname '*.deb')
101     for i in $DEBS
102     do
103         push_deb "$i"
104     done
105 elif [ "${OS}" == "centos7" ]; then
106     # Find the files
107     RPMS=$(find . -type f -iname '*.rpm')
108     SRPMS=$(find . -type f -iname '*.srpm')
109     SRCRPMS=$(find . -type f -name '*.src.rpm')
110     for i in $RPMS $SRPMS $SRCRPMS
111     do
112         push_rpm "$i"
113     done
114 fi
115 # vim: ts=4 sw=4 sts=4 et ft=sh :