Pages

Wednesday, July 12, 2023

Script to find the latest Branches on GIT Repository

 For every release we create a release branch for every microservice. few times we miss few microservice and it'll fail the deployment. hence i created this script to find the latest release branch on each repository to ensure for a smooth deployment.

1. We need to create reference file with GIT remote URL. we can copy the clone SSH git from each repo and generate this file

>> cat branch.txt

git@github.abc.com:DSC/a-frontend.git

git@github.abc.com:DSC/b-service.git

git@github.abc.com:DSC/c-portal.git

git@github.abc.com:DSC/d-service.git

git@github.abc.com:DSC/e-service.git

git@github.abc.com:DSC/f-service.git

git@github.abc.com:DSC/g-service.git

git@github.abc.com:DSC/h-service.git

git@github.abc.com:DSC/i-service.git

git@github.abc.com:DSC/j-service.git


2. We need to create the script,

>>vi find_branch.sh


#!/bin/bash

# Script to pull the GIT Repositories and find the latest branch"


echo -e "       Summary    " > latest.txt

echo -e "-------------------" >> latest.txt


for i in `cat branch.txt`;

  do

   j=`echo $i | cut -d/ -f2 | cut -d. -f1`

   echo "###################################"

   echo "Sync the $j Git Repository"

   echo "###################################"

   #`git clone $i --recurse-submodules`

   cd $j

   git pull --recurse-submodules

   git branch -r --sort=-committerdate | grep release | head -2

   echo "$j = `git branch -r --sort=-committerdate | grep release | head -1`" >> ../latest.txt

   cd ../

   echo -e "###################################\n\n"

done


cat latest.txt


3. Execute the create the script,

>>./find_branch.sh


No comments:

Post a Comment