From a075db4267fa1ca9e11c2c3813e3e058da4608ce Mon Sep 17 00:00:00 2001 From: Ed Espino Date: Sun, 22 Jul 2018 13:31:19 -0700 Subject: [PATCH] Save git root, submodule and changelog information. The following information will be saved in ${GREENPLUM_INSTALL_DIR}/etc/git-info.json: * Root repo (uri, sha1) * Submodules (submodule source path, sha1, tag) Save git commits since last release tag into ${GREENPLUM_INSTALL_DIR}/etc/git-current-changelog.txt --- concourse/scripts/compile_gpdb.bash | 20 ++++++++++ concourse/scripts/git_info.bash | 58 +++++++++++++++++++++++++++++ 2 files changed, 78 insertions(+) create mode 100755 concourse/scripts/git_info.bash diff --git a/concourse/scripts/compile_gpdb.bash b/concourse/scripts/compile_gpdb.bash index fbb59266b6..d11467eb8a 100755 --- a/concourse/scripts/compile_gpdb.bash +++ b/concourse/scripts/compile_gpdb.bash @@ -88,6 +88,25 @@ function build_gppkg() { popd } +function git_info() { + pushd ${GPDB_SRC_PATH} + + "${CWDIR}/git_info.bash" | tee ${GREENPLUM_INSTALL_DIR}/etc/git-info.json + + PREV_TAG=$(git describe --tags --abbrev=0 @^) + + cat > ${GREENPLUM_INSTALL_DIR}/etc/git-current-changelog.txt <<-EOF + ====================================================================== + Git log since previous release tag (${PREV_TAG}) + ---------------------------------------------------------------------- + + EOF + + git log --abbrev-commit --date=relative "${PREV_TAG}..@" | tee -a ${GREENPLUM_INSTALL_DIR}/etc/git-current-changelog.txt + + popd +} + function unittest_check_gpdb() { pushd ${GPDB_SRC_PATH} source ${GREENPLUM_INSTALL_DIR}/greenplum_path.sh @@ -172,6 +191,7 @@ function _main() { # the source tree and hence needs to be copied over. rsync -au gpaddon_src/ ${GPDB_SRC_PATH}/gpAux/${ADDON_DIR} build_gpdb "${BLD_TARGET_OPTION[@]}" + git_info build_gppkg if [ "${TARGET_OS}" != "win32" ] ; then # Don't unit test when cross compiling. Tests don't build because they diff --git a/concourse/scripts/git_info.bash b/concourse/scripts/git_info.bash new file mode 100755 index 0000000000..91eccccbae --- /dev/null +++ b/concourse/scripts/git_info.bash @@ -0,0 +1,58 @@ +#!/bin/bash + +set -uo pipefail + +# ---------------------------------------------------------------------- +# Check for prerequisite utilities +# ---------------------------------------------------------------------- + +PREREQ_COMMANDS="git" + +for COMMAND in ${PREREQ_COMMANDS}; do + type "${COMMAND}" >/dev/null 2>&1 || { echo >&2 "Required command line utility \"${COMMAND}\" is not available. Aborting."; exit 1; } +done + +# ---------------------------------------------------------------------- +# Retrieve root URI and commit SHA1 +# ---------------------------------------------------------------------- + +URI=$( git remote -v | grep "fetch" | grep "origin" | awk '{print $2}' ) +SHA1=$( git rev-parse HEAD ) + +# ---------------------------------------------------------------------- +# Generate root JSON record +# ---------------------------------------------------------------------- + +echo -n " +{\"root\": { + \"uri\": \"${URI}\", + \"sha1\": \"${SHA1}\"}, + \"submodules\": [" + +# ---------------------------------------------------------------------- +# Generate submodule records +# ---------------------------------------------------------------------- + +submodules=$( git submodule status ) +submodule_count=$( git submodule status | wc -l | tr -d ' ' ) + +COUNTER=0 +IFS=$'\n' + +for line in $submodules; do + SOURCE_PATH=$( echo "${line}" | cut -d " " -f3 ) + SHA1=$( echo "${line}" | cut -d " " -f2 ) + TAG=$( echo "${line}" | cut -d " " -f4 ) + COUNTER=$((COUNTER+1)) + +echo -n " + {\"source_path\": \"${SOURCE_PATH}\", + \"sha1\": \"${SHA1}\", + \"tag\": \"${TAG//[)(]/}\"}" + + if [ "${COUNTER}" != "${submodule_count}" ]; then + echo -n "," + fi +done + +echo "]}" -- GitLab