Docs deploy via Terraform
[ci-management.git] / jjb / scripts / packagecloud_push.sh
1 #!/bin/bash
2
3 # Copyright (c) 2021 Cisco and/or its affiliates.
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at:
7 #
8 #     http://www.apache.org/licenses/LICENSE-2.0
9 #
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
15
16 echo "---> jjb/scripts/packagecloud_push.sh"
17
18 set -euxo pipefail
19
20 line="*************************************************************************"
21
22 # Nothing was built if this is a merge job being run when
23 # the git HEAD id is not the same as the Gerrit New Revision ID
24 if [[ ${JOB_NAME} == *merge* ]] && [ -n "${GERRIT_NEWREV:-}" ] &&
25        [ "$GERRIT_NEWREV" != "$GIT_COMMIT" ] ; then
26     echo -e "\n$line\nSkipping package push. A newer patch has been merged.\n$line\n"
27     exit 0
28 fi
29
30 DRYRUN="${DRYRUN:-}"
31 if [ "${DRYRUN,,}" = "true" ] ; then
32     echo -e "\n$line\nSkipping package push because DRYRUN is '${DRYRUN,,}'.\n$line\n"
33     exit 0
34 fi
35
36 echo "STARTING PACKAGECLOUD PUSH"
37
38 sleep 10
39
40 FACTER_OS=$(/usr/bin/facter operatingsystem)
41 push_cmd=""
42 push_ext_deps_cmd=""
43
44 # PCIO_CO and SILO are Jenkins Global Environment variables defined in
45 # .../ci-management/jenkins-config/global-vars-*.sh
46 if [ -f ~/.packagecloud ]; then
47     case "$FACTER_OS" in
48         Debian)
49             FACTER_LSBNAME=$(/usr/bin/facter lsbdistcodename)
50             DEBS=$(find . -type f -iname '*.deb' | grep -v vpp-ext-deps)
51             push_cmd="package_cloud push ${PCIO_CO}/${STREAM}/debian/${FACTER_LSBNAME}/main/ ${DEBS}"
52             EXT_DEPS_DEB=$(find . -type f -iname 'vpp-ext-deps*.deb')
53             if [ -n "$EXT_DEPS_DEB" ] ; then
54                 push_ext_deps_cmd="package_cloud push ${PCIO_CO}/${STREAM}/debian/${FACTER_LSBNAME}/main/ ${EXT_DEPS_DEB}"
55             fi
56             ;;
57         Ubuntu)
58             FACTER_LSBNAME=$(/usr/bin/facter lsbdistcodename)
59             DEBS=$(find . -type f -iname '*.deb' | grep -v vpp-ext-deps)
60             push_cmd="package_cloud push ${PCIO_CO}/${STREAM}/ubuntu/${FACTER_LSBNAME}/main/ ${DEBS}"
61             EXT_DEPS_DEB=$(find . -type f -iname 'vpp-ext-deps*.deb')
62             if [ -n "$EXT_DEPS_DEB" ] ; then
63                 push_ext_deps_cmd="package_cloud push ${PCIO_CO}/${STREAM}/ubuntu/${FACTER_LSBNAME}/main/ ${EXT_DEPS_DEB}"
64             fi
65             ;;
66         CentOS)
67             FACTER_OSMAJREL=$(/usr/bin/facter operatingsystemmajrelease)
68             FACTER_ARCH=$(/usr/bin/facter architecture)
69             RPMS=$(find . -type f -iregex '.*/.*\.\(s\)?rpm' | grep -v vpp-ext-deps)
70             push_cmd="package_cloud push ${PCIO_CO}/${STREAM}/el/${FACTER_OSMAJREL}/os/${FACTER_ARCH}/ ${RPMS}"
71             EXT_DEPS_RPM=$(find . -type f -iname 'vpp-ext-deps*.rpm')
72             if [ -n "$EXT_DEPS_RPM" ] ; then
73                 push_ext_deps_cmd="package_cloud push ${PCIO_CO}/${STREAM}/el/${FACTER_OSMAJREL}/os/${FACTER_ARCH}/ ${EXT_DEPS_RPM}"
74             fi
75             ;;
76         *)
77             echo -e "\n$line\n* ERROR: Unsupported OS '$FACTER_OS'\n* PACKAGECLOUD PUSH FAILED!\n$line\n"
78             exit 1
79             ;;
80     esac
81     if [ "${SILO,,}" = "sandbox" ] ; then
82         echo "SANDBOX: skipping '$push_cmd'"
83         if [ -n "$push_ext_deps_cmd" ] ; then
84             echo "SANDBOX: skipping '$push_ext_deps_cmd'"
85         fi
86     else
87         $push_cmd
88         if [ -n "$push_ext_deps_cmd" ] ; then
89             # Don't fail script if vpp-ext-deps push fails.
90             set +e
91             $push_ext_deps_cmd
92             set -e
93         fi
94     fi
95 else
96     echo "ERROR: Missing '~/.packagecloud' for user '$(id)'"
97     echo "PACKAGECLOUD PUSH FAILED!"
98     exit 1
99 fi
100
101 echo -e "\n$line\n* PACKAGECLOUD PUSH COMPLETE\n$line\n"