From 25087f30e3f9b27b2b5ce845e90251ee2003ee8b Mon Sep 17 00:00:00 2001 From: Marcelo Vanzin Date: Mon, 12 Dec 2022 11:27:51 -0800 Subject: [PATCH] [DP-1714] Ensure tools repo profile script is updated when needed. (#27) Update the test for the toolrepos step to detect when the profile script needs to be updated; the previous code did not check for that when the git repos were already cloned. --- VERSION | 2 +- formula/ih-core.rb | 2 +- lib/core/toolrepos/step.sh | 8 ++++++-- lib/utils/file.sh | 24 +++++++++++++++++------- 4 files changed, 25 insertions(+), 11 deletions(-) diff --git a/VERSION b/VERSION index 20f4951..0e24a92 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.1.11 +0.1.12 diff --git a/formula/ih-core.rb b/formula/ih-core.rb index 40b0d47..f67c6ca 100644 --- a/formula/ih-core.rb +++ b/formula/ih-core.rb @@ -1,5 +1,5 @@ class IhCore < Formula - VERSION="0.1.11" + VERSION="0.1.12" desc "Brew formula for installing core tools used at Included Health engineering." homepage "https://github.com/ConsultingMD/homebrew-ih-public" license "CC BY-NC-ND 4.0" diff --git a/lib/core/toolrepos/step.sh b/lib/core/toolrepos/step.sh index d18be7f..8754501 100644 --- a/lib/core/toolrepos/step.sh +++ b/lib/core/toolrepos/step.sh @@ -56,11 +56,15 @@ function ih::setup::core.toolrepos::test-or-install() { git clone git@github.com:ConsultingMD/kore.git --filter=blob:limit=1m --depth=5 "${GR_HOME}/kore" || return fi + local toolsrepo_src_path="$IH_CORE_LIB_DIR/core/toolrepos/default/10_toolrepos.sh" + local toolsrepo_tgt_path="$IH_DEFAULT_DIR/10_toolrepos.sh" + if [ "$1" = "test" ]; then - return 0 + ih::file::check-file-in-sync "$toolsrepo_src_path" "$toolsrepo_tgt_path" + return fi export IH_WANT_RE_SOURCE=1 - cp -f "$IH_CORE_LIB_DIR/core/toolrepos/default/10_toolrepos.sh" "$IH_DEFAULT_DIR/10_toolrepos.sh" + cp -f "$toolsrepo_src_path" "$toolsrepo_tgt_path" } diff --git a/lib/utils/file.sh b/lib/utils/file.sh index 6d45b8c..be25417 100644 --- a/lib/utils/file.sh +++ b/lib/utils/file.sh @@ -66,6 +66,22 @@ function ih::file::add-if-not-matched() { echo "$CONTENT" >>"$FILE" } +# Returns 0 if file $2 exists and is the same as file $1. Otherwise returns 1. +function ih::file::check-file-in-sync() { + local SRC=${1:?"src is required"} + local DST=${2:?"dst is required"} + + if [ ! -f "$DST" ]; then + ih::log::debug "File $DST not found." + return 1 + fi + + if ! diff -q "$DST" "$SRC" >/dev/null; then + ih::log::debug "File $DST does not match source" + return 1 + fi +} + # Returns 0 if the directory at $2 has all # the files from the directory at $1, and # the files are all the same. Otherwise returns 1. @@ -76,13 +92,7 @@ function ih::file::check-dir-in-sync() { for SRC in "$SRC_DIR"/*; do local DST="${SRC/$SRC_DIR/$DST_DIR}" - if [ ! -f "$DST" ]; then - ih::log::debug "File $DST not found." - return 1 - fi - - if ! diff -q "$DST" "$SRC" >/dev/null; then - ih::log::debug "File $DST does not match source" + if ! ih::file::check-file-in-sync "$SRC" "$DST"; then return 1 fi done