github.com/deemoprobe/k8s-first-commit@v0.0.0-20230430165612-a541f1982be3/third_party/update.sh (about) 1 #!/bin/bash 2 3 set -e 4 5 if (( $(git status --porcelain 2>/dev/null | grep "^M" | wc -l) > 0 )); then 6 echo "You can't have any staged files in git when updating packages." 7 echo "Either commit them or unstage them to continue." 8 exit 1 9 fi 10 11 THIRD_PARTY_DIR=$(dirname $0) 12 cd $THIRD_PARTY_DIR 13 14 . ./deps.sh 15 16 # Create a temp GOPATH root. It must be an absolute path 17 mkdir -p ../target/go_dep_update 18 cd ../target/go_dep_update 19 TMP_GO_ROOT=$PWD 20 cd - 21 export GOPATH=${TMP_GO_ROOT} 22 23 for p in $PACKAGES; do 24 echo "Fetching $p" 25 26 # this is the target directory 27 mkdir -p src/$p 28 29 # This will checkout the project into src 30 go get -u -d $p 31 32 # The go get path 33 gp=$TMP_GO_ROOT/src/$p 34 35 # Attempt to find the commit hash of the repo 36 cd $gp 37 38 HEAD= 39 REL_PATH=$(git rev-parse --show-prefix 2>/dev/null) 40 if [[ -z "$HEAD" && $REL_PATH != *target/go_dep_update* ]]; then 41 # Grab the head if it is git 42 HEAD=$(git rev-parse HEAD) 43 fi 44 45 # Grab the head if it is mercurial 46 if [[ -z "$HEAD" ]] && hg root >/dev/null 2>&1; then 47 HEAD=$(hg id -i) 48 fi 49 50 cd - 51 52 # Copy the code into the final directory 53 rsync -a -z -r --exclude '.git/' --exclude '.hg/' $TMP_GO_ROOT/src/$p/ $p 54 55 # Make a nice commit about what everything bumped to 56 git add $p 57 if ! git diff --cached --exit-code > /dev/null 2>&1; then 58 git commit -m "bump($p): $HEAD" 59 fi 60 done