github.com/cactusblossom/fabric-ca@v0.0.0-20200611062428-0082fc643826/scripts/bash_profile (about)

     1  #!/bin/bash
     2  #
     3  # Copyright IBM Corp. All Rights Reserved.
     4  #
     5  # SPDX-License-Identifier: Apache-2.0
     6  #
     7  # This file contains useful functions for fabric development.
     8  # Modify the following environment variables as desired.
     9  # The remaining variables should not need to be change.
    10  # LFID        : your Linux Foundation ID
    11  # REPO        : your repository name
    12  export LFID=YOUR-LINUX-FOUNDATION-ID
    13  export REPO=fabric-ca
    14  
    15  export PROJECT=github.com/hyperledger
    16  export GERRIT=gerrit.hyperledger.org
    17  export GERRIT_ADDR=$GERRIT:29418
    18  
    19  # Clone the repo
    20  function clone {
    21    initvars
    22    if [ -d $LFID ]; then
    23       echo "LFID environment variable must be set to your Linux Foundation ID"
    24       return 1
    25    fi
    26    if [ -d $REPO_DIR ]; then
    27       echo "repo already exists at $REPO_DIR"
    28       return 1
    29    fi
    30    if [ ! -d $PROJECT_DIR ]; then
    31       mkdir -p $PROJECT_DIR
    32    fi
    33    cd $PROJECT_DIR
    34    echo ">>> Cloning directory at $REPO_DIR ..."
    35    git clone ssh://${LFID}@${GERRIT_ADDR}/${REPO}
    36    cdr
    37    git config --global gitreview.username $LFID
    38    git config --global gitreview.remote origin
    39    gitdir=$(git rev-parse --git-dir)
    40    scp -p -P 29418 ${LFID}@${GERRIT}:hooks/commit-msg ${gitdir}/hooks/  > /dev/null
    41    echo ">>> Completed clone of directory at $REPO_DIR"
    42  }
    43  
    44  # Clone the repo to a new directory, typically for verification
    45  function clonedir {
    46    OLD_GOPATH=$GOPATH
    47    if [ $# -ne 1 ]; then
    48       echo "Usage: clonedir <dir>"
    49       return 1
    50    fi
    51    if [ -d $1 ]; then
    52       echo "directory $1 already exists"
    53       return 1
    54    fi
    55    mkdir -p $1
    56    cd $1
    57    export GOPATH=`pwd`
    58    clone
    59    echo "WARNING: Your GOPATH was changed from ${OLD_GOPATH} to ${GOPATH}.  Be sure to change it back when done."
    60  }
    61  
    62  # Create a new branch
    63  function branch {
    64    initvars
    65    if [ $# -ne 1 ]; then
    66       echo "Usage: branch <branch-name>"
    67       return 1
    68    fi
    69    cdr
    70    if [ $? -ne 0 ]; then
    71      return $?
    72    fi
    73    git checkout master
    74    if [ $? -ne 0 ]; then
    75      return $?
    76    fi
    77    git checkout -b $1
    78    return $?
    79  }
    80  
    81  # push changes to repo
    82  function push {
    83   cdr
    84   if [ $? -ne 0 ]; then
    85     return 1
    86   fi
    87   echo "Running make before pushing ..."
    88   make unit-tests docs
    89   if [ $? -ne 0 ]; then
    90     echo "Not pushing because make failed"
    91     return 1
    92   fi
    93   git push origin HEAD:refs/for/master
    94  }
    95  
    96  # Rebase your current branch on the latest from master
    97  function rebase {
    98     cdr
    99     CUR_BRANCH=`git rev-parse --abbrev-ref HEAD`
   100     if [ "${CUR_BRANCH}" = "master" ]; then
   101        echo "Can't rebase from master branch"
   102        return 1
   103     fi
   104     git checkout master
   105     if [ $? -ne 0 ]; then
   106        echo "Failed to checkout out master"
   107        return 1
   108     fi
   109     echo "Updating master ..."
   110     git pull
   111     if [ $? -ne 0 ]; then
   112        echo "Failed to pull from master"
   113        return 1
   114     fi
   115     git checkout $CUR_BRANCH
   116     if [ $? -ne 0 ]; then
   117        echo "Failed to switch back to branch $CUR_BRANCH"
   118        return 1
   119     fi
   120     git rebase master
   121     if [ $? -ne 0 ]; then
   122        echo "Failed to rebase branch $CUR_BRANCH against master"
   123        return 1
   124     fi
   125  }
   126  
   127  # setrepo
   128  function setrepo {
   129    if [ $# -ne 1 ]; then
   130       echo "Usage: setrepo <repo>"
   131       echo "Examples:"
   132       echo "   setrepo fabric-ca"
   133       echo "   setrepo fabric"
   134       return 1
   135    fi
   136    export REPO=$1
   137    initvars
   138    if [ ! -d $REPO_DIR ]; then
   139       clone
   140    else
   141       cdr
   142    fi
   143  }
   144  
   145  function verify {
   146     rm -rf $HOME/verify
   147     clonedir $HOME/verify
   148  }
   149  
   150  # Change to the repo directory
   151  function cdr {
   152    initvars
   153    if [ ! -d $REPO_DIR ]; then
   154       echo "repo does not exist at $REPO_DIR"
   155       return 1
   156    fi
   157    cd $REPO_DIR
   158    return 0
   159  }
   160  
   161  # Initialize variables appropriately
   162  function initvars {
   163     export PROJECT_DIR=$GOPATH/src/$PROJECT
   164     export REPO_DIR=$PROJECT_DIR/$REPO
   165  }
   166  
   167  # Generate the coverage report
   168  function gencov {
   169     cdr
   170     echo "Generating coverage report ..."
   171     go get github.com/axw/gocov/gocov
   172     go get -u gopkg.in/matm/v1/gocov-html
   173     gocov test `go list ./... | grep -Ev '/vendor/|/api|/dbutil|/ldap'` | gocov-html > /tmp/coverage.html
   174     echo "View the coverage report by pasting the following URL in your browser: file:///tmp/coverage.html"
   175  }