#!/bin/bash
set -eo pipefail
#set -x

GREENPLUM_INSTALL_DIR=/usr/local/greenplum-db-devel

compare_bin_gpdb_version_with_gpdb_src() {
  local bin_gpdb=$1

  # Install GPDB from bin_gpdb
  rm -rf ${GREENPLUM_INSTALL_DIR}
  mkdir -p ${GREENPLUM_INSTALL_DIR}
  tar -xf "${bin_gpdb}/bin_gpdb.tar.gz" -C "${GREENPLUM_INSTALL_DIR}/"

  # Get gpdb commit SHA
  source "${GREENPLUM_INSTALL_DIR}/greenplum_path.sh"
  bin_gpdb_version=$(postgres --gp-version | sed 's/.*build commit:\(.*\)/\1/')

  if [ "${bin_gpdb_version}" != "${GPDB_SRC_VERSION}" ]; then
    echo "bin_gpdb version: ${bin_gpdb_version} does not match gpdb_src version: ${GPDB_SRC_VERSION}, please wait for the next build. Exiting..."
    exit 1
  fi

}

# Install dependencies
yum -y install git

# Get commit SHA from gpdb_src
pushd gpdb_src
  GPDB_SRC_VERSION=$(git rev-parse HEAD)
popd

for bin_gpdb in bin_gpdb_centos{6,7} ; do
  compare_bin_gpdb_version_with_gpdb_src "${bin_gpdb}"
done

echo "Release Candidate: ${GPDB_SRC_VERSION}"

#!/bin/bash
set -xeo pipefail

install_greenplum() {
  local bin_gpdb=$1
  local install_dir=/usr/local/greenplum-db-devel

  rm -rf "$install_dir"
  mkdir -p "$install_dir"
  tar -xf "${bin_gpdb}/bin_gpdb.tar.gz" -C "$install_dir"
  source "${install_dir}/greenplum_path.sh"
}

assert_postgres_version_matches() {
  local gpdb_src_sha=$1

  if [[ ! "$(postgres --gp-version)" =~ "commit:$gpdb_src_sha" ]]; then
    echo "bin_gpdb version: '$(postgres --gp-version)' does not match gpdb_src commit: '${gpdb_src_sha}'. Exiting..."
    exit 1
  fi
}

yum -d1 -y install git

GPDB_SRC_SHA=$(cd gpdb_src && git rev-parse HEAD)
for bin_gpdb in bin_gpdb_centos{6,7}; do
  install_greenplum "$bin_gpdb"
  assert_postgres_version_matches "$GPDB_SRC_SHA"
done

echo "Release Candidate SHA: ${GPDB_SRC_SHA}"

Refactor Release_Candidate commit SHA test
Refactor Release_Candidate commit SHA test

The logic hasn't actually changed much (we are still validating the the
postgres version and gpdb_src SHA match), but has become clearer and
easier to follow:
* avoids use of globals
* separates assert function into two to have clearer scope separation

Co-authored-by: Soumyadeep Chakraborty <ec19037653195c8fe6913bfa51ee2dd46d490579@pivotal.io>
Co-authored-by: Amil Khanzada <2b2e417ac7ef3455227cad66d1bdb90ea476aac5@pivotal.io>
Co-authored-by: Oliver Albertini <aeef948b459eb58ad41c7f6e2c98cfd4712363b4@pivotal.io>
Co-authored-by: Kris Macoskey <02d17b27bd81bba87d36066114b34c9a266751ac@pivotal.io>
Co-authored-by: Ben Christel <1e6f33b93edb5b67641d5788dfa53877a58fab99@pivotal.io>
