Monday, May 4, 2020

Resync with upstream git repo

To complete resynch with upstream repo, do the following:

1. git remote add upstream https://github.com/hyperledger-cicd/cello.git
2. git fetch upstream
3. git reset --hard upstream/master
4. git checkout master
5. git merge upstream/master
6. git push --force

Once this is done, your forked repo should be completely insynch with the upstream repo. the word upstream in this case is just a name for the upstream repo, it can be named any thing you like. If you are not using the word upstream, you will have to make sure that the following on commands using the correct upstream name.

Friday, May 1, 2020

Improve bash script with parameter

# parameter should be the component name such as api, dashboard or ansibleagent etc
api=("src/api-engine/"
     "build_image/docker/common/api-engine")
dashboard=("src/dashboard/"
     "build_image/docker/common/dashboard")
ansibleagent=("src/agent/ansible/"
     "build_image/docker/agent/ansible")


cdir=$(pwd)
cd ~/hl/src/github.com/realcello
allchanges=$(git diff --name-only HEAD~15 HEAD~20)
cd $cdir

echo "$allchanges"
hasTopChanges=$(echo "$allchanges" | grep -v '/')
if [ ! -z "$hasTopChanges" ]; then
  echo 'Has changes at the root, need to proceed'
  exit 0
fi

comp=$1
compItems="${comp}[@]"
changesFound='False'
echo 'Items in '${comp}
for item in "${!compItems}"; do
  echo "   checking $item"
  if echo "${allchanges}" | grep -q "$item"
  then
    changesFound='True'
  fi
done

if [ "$changesFound" == 'True' ]; then
  echo 'Need to proceed'
else
  echo "##vso[task.complete result=Succeeded;]No changes found!"
fi

Script to check if changes have happened under a particular directory

api=("src/api-engine/"
     "build_image/docker/common/api-engine")
dashboard=("src/dashboard/"
     "build_image/docker/common/dashboard")
ansibleagent=("src/agent/ansible/"
     "build_image/docker/agent/ansible")

allcomps=("api" "dashboard" "ansibleagent")
declare -A OPS

cdir=$(pwd)
cd ~/hl/src/github.com/realcello
allchanges=$(git diff --name-only HEAD~1 HEAD~10)
cd $cdir

echo "$allchanges"

for value in ${allcomps[@]}; do
  comps="${value}[@]"
  echo 'Items in '${value}
  for item in "${!comps}"; do
    echo "   checking $item"
    if echo "${allchanges}" | grep -q "$item"
    then
      OPS["${value}"]='true'
    fi
  done
done

for item in "${allcomps[@]}"; do
  echo "$item"="${OPS[$item]}"
done