Remove functest-parser
[releng.git] / jjb / apex / apex-upload-artifact.sh
1 #!/bin/bash
2 set -o errexit
3 set -o nounset
4 set -o pipefail
5
6 if [ -z "$ARTIFACT_TYPE" ]; then
7   echo "ERROR: ARTIFACT_TYPE not provided...exiting"
8   exit 1
9 fi
10
11 # log info to console
12 echo "Uploading the Apex ${ARTIFACT_TYPE} artifact. This could take some time..."
13 echo "--------------------------------------------------------"
14 echo
15
16 if [[ ! "$ARTIFACT_VERSION" =~ dev ]]; then
17   source $BUILD_DIRECTORY/../opnfv.properties
18 fi
19
20 importkey () {
21   # clone releng repository
22   echo "Cloning releng repository..."
23   [ -d releng ] && rm -rf releng
24   git clone https://gerrit.opnfv.org/gerrit/releng $WORKSPACE/releng/ &> /dev/null
25   #this is where we import the siging key
26   if [ -f $WORKSPACE/releng/utils/gpg_import_key.sh ]; then
27     source $WORKSPACE/releng/utils/gpg_import_key.sh
28   fi
29 }
30
31 signrpm () {
32   for artifact in $RPM_LIST $SRPM_LIST; do
33     echo "Signing artifact: ${artifact}"
34     gpg2 -vvv --batch --yes --no-tty \
35       --default-key opnfv-helpdesk@rt.linuxfoundation.org \
36       --passphrase besteffort \
37       --detach-sig $artifact
38       gsutil cp "$artifact".sig gs://$GS_URL/$(basename "$artifact".sig)
39       echo "Upload complete for ${artifact} signature"
40   done
41 }
42
43 signiso () {
44   gpg2 -vvv --batch --yes --no-tty \
45     --default-key opnfv-helpdesk@rt.linuxfoundation.org  \
46     --passphrase besteffort \
47     --detach-sig $BUILD_DIRECTORY/release/OPNFV-CentOS-7-x86_64-$OPNFV_ARTIFACT_VERSION.iso
48
49   gsutil cp $BUILD_DIRECTORY/release/OPNFV-CentOS-7-x86_64-$OPNFV_ARTIFACT_VERSION.iso.sig gs://$GS_URL/opnfv-$OPNFV_ARTIFACT_VERSION.iso.sig
50   echo "ISO signature Upload Complete!"
51 }
52
53 uploadiso () {
54   gsutil cp $BUILD_DIRECTORY/release/OPNFV-CentOS-7-x86_64-$OPNFV_ARTIFACT_VERSION.iso gs://$GS_URL/opnfv-$OPNFV_ARTIFACT_VERSION.iso > gsutil.iso.log
55   echo "ISO Upload Complete!"
56 }
57
58 uploadrpm () {
59   for artifact in $RPM_LIST $SRPM_LIST; do
60     echo "Uploading artifact: ${artifact}"
61     gsutil cp $artifact gs://$GS_URL/$(basename $artifact) > gsutil.iso.log
62     echo "Upload complete for ${artifact}"
63   done
64   gsutil cp $WORKSPACE/opnfv.properties gs://$GS_URL/opnfv-$OPNFV_ARTIFACT_VERSION.properties > gsutil.properties.log
65   gsutil cp $WORKSPACE/opnfv.properties gs://$GS_URL/latest.properties > gsutil.latest.log
66
67   # Make the property files viewable on the artifact site
68   gsutil -m setmeta \
69     -h "Content-Type:text/html" \
70     -h "Cache-Control:private, max-age=0, no-transform" \
71     gs://$GS_URL/latest.properties \
72     gs://$GS_URL/opnfv-$OPNFV_ARTIFACT_VERSION.properties > /dev/null 2>&1
73 }
74
75 uploadsnap () {
76   # Uploads snapshot artifact and updated properties file
77   echo "Uploading snapshot artifacts"
78   if [ -z "$SNAP_TYPE" ]; then
79     echo "ERROR: SNAP_TYPE not provided...exiting"
80     exit 1
81   fi
82   gsutil cp $WORKSPACE/apex-${SNAP_TYPE}-snap-`date +%Y-%m-%d`.tar.gz gs://$GS_URL/ > gsutil.iso.log
83   if [ "$SNAP_TYPE" == 'csit' ]; then
84     gsutil cp $WORKSPACE/snapshot.properties gs://$GS_URL/snapshot.properties > gsutil.latest.log
85   fi
86   echo "Upload complete for Snapshot"
87 }
88
89 uploadimages () {
90   # Uploads dev tarball
91   GERRIT_PATCHSET_NUMBER=$(echo $GERRIT_REFSPEC | grep -Eo '[0-9]+$')
92   export OPNFV_ARTIFACT_VERSION="dev${GERRIT_CHANGE_NUMBER}_${GERRIT_PATCHSET_NUMBER}"
93   echo "Uploading development build tarball"
94   pushd $BUILD_DIRECTORY > /dev/null
95   tar czf apex-${OPNFV_ARTIFACT_VERSION}.tar.gz *.qcow2 *.vmlinuz *.initrd
96   gsutil cp apex-${OPNFV_ARTIFACT_VERSION}.tar.gz gs://$GS_URL/apex-${OPNFV_ARTIFACT_VERSION}.tar.gz > gsutil.latest.log
97   popd > /dev/null
98 }
99
100 # Always import the signing key, if it's available the artifacts will be
101 # signed before being uploaded
102 importkey
103
104 if gpg2 --list-keys | grep "opnfv-helpdesk@rt.linuxfoundation.org"; then
105   echo "Signing Key avaliable"
106   SIGN_ARTIFACT="true"
107 fi
108
109 if [ "$ARTIFACT_TYPE" == 'snapshot' ]; then
110   uploadsnap
111 elif [ "$ARTIFACT_TYPE" == 'iso' ]; then
112   if [[ "$ARTIFACT_VERSION" =~ dev || "$BRANCH" == 'master' ]]; then
113     echo "Skipping ISO artifact upload for ${ARTIFACT_TYPE} due to dev/master build"
114     exit 0
115   fi
116   if [[ -n "$SIGN_ARTIFACT" && "$SIGN_ARTIFACT" == "true" ]]; then
117     signiso
118   fi
119   uploadiso
120 elif [ "$ARTIFACT_TYPE" == 'rpm' ]; then
121   if [[ "$ARTIFACT_VERSION" =~ dev ]]; then
122     if [ "$BRANCH" == 'master' ]; then
123       echo "will not upload artifacts, master uses upstream"
124       ARTIFACT_TYPE=none
125     else
126       echo "dev build detected, will upload image tarball"
127       ARTIFACT_TYPE=tarball
128       uploadimages
129     fi
130   else
131     RPM_INSTALL_PATH=$BUILD_DIRECTORY/noarch
132     # RPM URL should be python package for master, and is only package we need
133     RPM_LIST=$RPM_INSTALL_PATH/$(basename $OPNFV_RPM_URL)
134     SRPM_INSTALL_PATH=$BUILD_DIRECTORY
135     SRPM_LIST=$SRPM_INSTALL_PATH/$(basename $OPNFV_SRPM_URL)
136     if [ "$BRANCH" != 'master' ]; then
137       VERSION_EXTENSION=$(echo $(basename $OPNFV_RPM_URL) | sed 's/opnfv-apex-//')
138       RPM_LIST+=" ${RPM_INSTALL_PATH}/opnfv-apex-undercloud-${VERSION_EXTENSION}"
139       RPM_LIST+=" ${RPM_INSTALL_PATH}/python34-opnfv-apex-${VERSION_EXTENSION}"
140       VERSION_EXTENSION=$(echo $(basename $OPNFV_SRPM_URL) | sed 's/opnfv-apex-//')
141       SRPM_LIST+=" ${SRPM_INSTALL_PATH}/opnfv-apex-undercloud-${VERSION_EXTENSION}"
142       SRPM_LIST+=" ${SRPM_INSTALL_PATH}/python34-opnfv-apex-${VERSION_EXTENSION}"
143     fi
144
145     if [[ -n "$SIGN_ARTIFACT" && "$SIGN_ARTIFACT" == "true" ]]; then
146       signrpm
147     fi
148     uploadrpm
149   fi
150 else
151   echo "ERROR: Unknown artifact type ${ARTIFACT_TYPE} to upload...exiting"
152   exit 1
153 fi
154
155 echo
156 echo "--------------------------------------------------------"
157 echo "Done!"
158 if [ "$ARTIFACT_TYPE" == 'iso' ]; then echo "ISO Artifact is available as http://$GS_URL/opnfv-$OPNFV_ARTIFACT_VERSION.iso"; fi
159 if [ "$ARTIFACT_TYPE" == 'rpm' ]; then echo "RPM Artifact is available as http://$GS_URL/$(basename $OPNFV_RPM_URL)"; fi
160 if [ "$ARTIFACT_TYPE" == 'tarball' ]; then echo "Dev tarball Artifact is available as http://$GS_URL/apex-${OPNFV_ARTIFACT_VERSION}.tar.gz)"; fi