Chore: Upgrade Jenkins-job-builder to 6.3.0
[releng/global-jjb.git] / shell / packagecloud-push.sh
1 #!/bin/bash -l
2 # SPDX-License-Identifier: EPL-1.0
3 ##############################################################################
4 # Copyright (c) 2020 The Linux Foundation and others.
5 #
6 # All rights reserved. This program and the accompanying materials
7 # are made available under the terms of the Eclipse Public License v1.0
8 # which accompanies this distribution, and is available at
9 # http://www.eclipse.org/legal/epl-v10.html
10 ##############################################################################
11
12 # Prereqs:
13 # The build minion has the ruby gem "package_cloud"
14 # The required credentials and API files have been provisioned
15 # The build directory has .deb/.rpm files
16 # Environment variables:
17 # BUILD_DIR is set and non-empty
18 # DEBIAN_DISTRIBUTION_VERSIONS has distro list like "debian/stretch"
19 # RPM_DISTRIBUTION_VERSIONS has distro list like "el/4 el/5"
20 # PACKAGECLOUD_ACCOUNT is set and non-empty
21 # PACKAGECLOUD_REPO is a value like "staging"
22
23 echo "---> packagecloud-push.sh"
24 set -eu -o pipefail
25
26 # Pushes packages to PackageCloud
27 # $1 is a shell-style glob pattern for package files
28 # $2 is a space-separated list of distribution versions
29 push_packages () {
30     echo "Expanding file pattern $1"
31     # shellcheck disable=SC2206
32     pkgs=($1)
33     if [[ ! -f ${pkgs[0]} ]]; then
34         echo "WARN: no files matched pattern $1"
35         return
36     fi
37     echo "Found package file(s):" "${pkgs[@]}"
38     echo "Processing distribution version(s): $2"
39     for ver in $2; do
40         arg="${PACKAGECLOUD_ACCOUNT}/${PACKAGECLOUD_REPO}/${ver}"
41         for pkg in "${pkgs[@]}"; do
42             echo "Pushing $arg $pkg"
43             package_cloud push "$arg" "$pkg"
44         done
45     done
46 }
47
48 echo "Working in directory $BUILD_DIR"
49 cd "$BUILD_DIR"
50 push_packages "*.deb" "$DEBIAN_DISTRIBUTION_VERSIONS"
51 push_packages "*.rpm" "$RPM_DISTRIBUTION_VERSIONS"
52
53 echo "---> packagecloud-push.sh ends"