Merge "Update to global-jjb v0.12.1"
[releng/builder.git] / jjb / packaging / build-rpm.sh
1 #!/bin/bash
2
3 # Options:
4 #   -x: Echo commands
5 #   -e: Fail on errors
6 #   -o pipefail: Fail on errors in scripts this calls, give stacktrace
7 set -ex -o pipefail
8
9 # Install required packages
10 virtualenv rpm_build
11 # shellcheck disable=SC1091
12 source rpm_build/bin/activate
13 PYTHON="rpm_build/bin/python"
14 $PYTHON -m pip install --upgrade pip
15 $PYTHON -m pip install -r "$WORKSPACE/packaging/packages/requirements.txt"
16
17 # Packaging logic needs a tarball, but can repackage a zip into tar.gz
18 # if needed. All builds except multipatch-test publish both a tar.gz and zip.
19 # Autorelease passes DOWNLOAD_URL to zip, others typically use tar.gz.
20 # If URL is to zip, check if there's a tar.gz available to avoid repackaging.
21 if [[ $DOWNLOAD_URL = *.zip ]]; then
22   # shellcheck disable=SC2154
23   candidate_tarball_url="${{DOWNLOAD_URL//zip/tar.gz}}"
24   # shellcheck disable=SC2154
25   url_status=$(curl --silent --head --location --output /dev/null --write-out \
26     '%{{http_code}}' "$candidate_tarball_url")
27   if [[ $url_status = 2* ]]; then
28     DOWNLOAD_URL="$candidate_tarball_url"
29   fi
30 fi
31
32 # Build release specified by build params
33 "$WORKSPACE/packaging/packages/build.py" --rpm \
34                                          --changelog_name "$CHANGELOG_NAME" \
35                                          --changelog_email "$CHANGELOG_EMAIL" \
36                                          direct \
37                                          --download_url "$DOWNLOAD_URL"
38
39 # Publish RPMs to Nexus if in production Jenkins, else host on sandbox Jenkins
40 if [ "$SILO" == "sandbox" ]; then
41   # TODO: Host RPMs on Jenkins temporarily
42   echo "Not uploading RPMs to Nexus because running in sandbox"
43 elif  [ "$SILO" == "releng" ]; then
44   # Move RPMs (SRPM and noarch) to dir of files that will be uploaded to Nexus
45   UPLOAD_FILES_PATH="$WORKSPACE/upload_files"
46   mkdir -p "$UPLOAD_FILES_PATH"
47   mv "/home/$USER/rpmbuild/RPMS/noarch/"*.rpm "$_"
48   mv "/home/$USER/rpmbuild/SRPMS/"*.rpm "$_"
49 else
50   echo "Unknown Jenkins silo: $SILO"
51   exit 1
52 fi