Skip to content

Commit

Permalink
[DP-1714] Ensure tools repo profile script is updated when needed. (#27)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
vanzin authored Dec 12, 2022
1 parent 1124e96 commit 25087f3
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 11 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.1.11
0.1.12
2 changes: 1 addition & 1 deletion formula/ih-core.rb
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
8 changes: 6 additions & 2 deletions lib/core/toolrepos/step.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
24 changes: 17 additions & 7 deletions lib/utils/file.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
Expand Down

0 comments on commit 25087f3

Please sign in to comment.