#!/bin/bash # IBM_PROLOG_BEGIN_TAG # This is an automatically generated prolog. # # $Source: src/build/citest/auto-release $ # # OpenPOWER HostBoot Project # # Contributors Listed Below - COPYRIGHT 2016,2017 # [+] International Business Machines Corp. # # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or # implied. See the License for the specific language governing # permissions and limitations under the License. # # IBM_PROLOG_END_TAG function setup { cd $HOSTBOOT_WORKSPACE # Set up environment source "$HOSTBOOT_WORKSPACE/env.bash" || exit -1 # Create cmvc checkout directory if [ -n "$CMVC_DIR" ]; then mkdir -p $CMVC_DIR || exit -1 fi } function build { ### Define and setup release branch export PATH=${PATH}:$HOSTBOOT_WORKSPACE/src/build/tools hbRelease define --level $RELEASE_NAME --released $PREVIOUS_RELEASE --base $BASE --branch $GIT_BRANCH || exit -1 hbRelease release --level $RELEASE_NAME || exit -1 ### Compile and provide binaries setup if echo $FIPS_RELEASE | grep -q fips9; then export CONFIG_FILE="$HOSTBOOT_WORKSPACE/src/build/configs/fsprelease.config" fi BUILD_MINIMAL=1 nice -+20 make -j16 || exit -1 # Run hb distribute to put binaries in cmvc checkout directory export SANDBOXROOT=$WORKSPACE export SANDBOXNAME=$RELEASE_NAME export SANDBOXBASE=$SANDBOXROOT/$SANDBOXNAME mkdir -p $SANDBOXBASE hb prime --release $SANDBOXBASE || exit -1 mkdir -p $CMVC_DIR/src/hbfw || exit -1 cp -rf $SANDBOXBASE/fsp/* $CMVC_DIR/src/hbfw || exit -1 rm -rf $SANDBOXBASE/fsp || exit -1 ### Push tag to gerrit, create track and checkin files git push ssh://hostboot-us@gerrit-server/hostboot $RELEASE_NAME || exit -1 git checkout gerrit/master || exit -1 hbRelease pre-release --level $RELEASE_NAME --release $FIPS_RELEASE --checkInDir $CMVC_DIR --released $PREVIOUS_RELEASE --track $EXISTING_TRACK || exit -1 # Check if feature was successfully created and if so set $FEATURE if [ -f $CMVC_FEATURE_FILE ]; then FEATURE=`cat $CMVC_FEATURE_FILE`; else echo "No feature created" exit -1 fi ### @todo RTC:171143 ### Sleep for 5 minutes to allow time for CMVC req's to take effect echo "Waiting for fspCI requirements to take effect. 5 minutes..." sleep 5m } function fsp-ci-wait { joburl=$1 build_result="unknown" rc=1 if [ -z "$joburl" ]; then echo "Invalid or empty job URL." exit -1 fi # No timeout is implemented here. Timeout would happen at the Jenkins # project level echo "Waiting for $joburl build status..." while true; do sleep 10 # use silent flag (-s) to omit progress meter output curl -s ${joburl}/api/json | grep building\":false >/dev/null 2>&1 if [ $? -eq 0 ]; then break fi done # The job is not building anymore. Check the build result. CURL_OUT="$(curl -s ${joburl}/api/json)" if [ $? -ne 0 ]; then echo "Error verifying build result..." echo "curl returned $?\n$CURL_OUT" exit -1 fi echo $CURL_OUT | grep result\":\"SUCCESS if [ $? -eq 0 ]; then echo "Build $joburl passed" build_result="passed" rc=0 fi echo $CURL_OUT | grep result\":\"FAILURE if [ $? -eq 0 ]; then echo "Build $joburl failed." build_result="failed" rc=1 fi echo $CURL_OUT | grep result\":\"ABORTED if [ $? -eq 0 ]; then echo "Build $joburl aborted." build_result="aborted" rc=1 fi if [ "$build_result" == "unknown" ]; then echo "Build result for $joburl: unknown." echo "curl output: $CURL_OUT" rc=1 fi return $rc } function run_fsp_ci { ### Call fsp-ci to test hostboot release # Start fsp-CI job and set URL retries=3 # Retry loop for fsp-CI-jenkins while true; do ((retries--)) OUTPUT="$(fsp-CI-jenkins -r $FIPS_RELEASE -t $FEATURE --test_on_hardware=1 --force)"; # Check if fsp-CI-jenkins failed to start if [ $? -eq 0 ]; then URL="$(echo $OUTPUT | grep -o "Check status at .*" | sed -e "s/Check status at//")" break else if [ $retries -lt 1 ]; then exit -1 fi echo "fsp-CI-jenkins command failed returned $?, retrying..." sleep 66 fi done ### Wait on fsp-CI job to complete, whether pass or fail fsp-ci-wait $URL || exit -1 } function release { ### Handle cmvc final commands to integrate track, post notes to BQ hbRelease post-release --level $RELEASE_NAME --released $PREVIOUS_RELEASE --feature $FEATURE --release $FIPS_RELEASE || exit -1 } function usage { echo "Usage: auto-release.sh [OPTIONS]" echo "Runs the steps for Hostboot automated releases" echo "OPTIONS:" echo " -b Run build phase" echo " -t Run test and release phase" echo " -c Run test phase only (fsp-ci)" echo " -h Help" exit 1 } # make sure arguments are provided if [ $# -eq 0 ] then echo "No arguments provided." usage exit 1 fi while getopts "btch" opt; do case $opt in b) build ;; t) setup run_fsp_ci release ;; c) run_fsp_ci ;; h) usage ;; \?) echo "Invalid option: -$OPTARG" >&2 exit 1 ;; :) echo "Option -$OPTARG requires an argument." >&2 exit 1 ;; esac done