Sergio Slobodrian | c2d86fb | 2017-07-18 20:35:46 -0400 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | |
| 3 | tagName=$1 |
| 4 | |
| 5 | if ( find /src -maxdepth 0 -empty | read v ); |
| 6 | then |
| 7 | echo "Error: Must mount Go source code into /src directory" |
| 8 | exit 990 |
| 9 | fi |
| 10 | |
| 11 | # Grab Go package name |
| 12 | pkgName="$(go list -e -f '{{.ImportComment}}' 2>/dev/null || true)" |
| 13 | |
| 14 | if [ -z "$pkgName" ]; |
| 15 | then |
| 16 | if [ -f "/src/glide.yaml" ] |
| 17 | then |
| 18 | pkgName="$(glide name)" |
| 19 | elif [ -f "/src/Godeps/Godeps.json" ] |
| 20 | then |
| 21 | pkgName="$(cat /src/Godeps/Godeps.json | jq --raw-output '.ImportPath')" |
| 22 | else |
| 23 | url=$(git config --get remote.origin.url) |
| 24 | if [[ "$url" == http* ]] |
| 25 | then |
| 26 | pkgName=$(echo ${url} | sed -E 's|https?://(.+)|\1|') |
| 27 | elif [[ "$url" == git@* ]] |
| 28 | then |
| 29 | pkgName=$(echo ${url} | sed -E 's|git@(.+):(.+).git|\1/\2|') |
| 30 | fi |
| 31 | fi |
| 32 | fi |
| 33 | |
| 34 | if [ -z "$pkgName" ]; |
| 35 | then |
| 36 | echo "Error: Must add canonical import path to root package" |
| 37 | exit 992 |
| 38 | fi |
| 39 | |
| 40 | # Grab just first path listed in GOPATH |
| 41 | goPath="${GOPATH%%:*}" |
| 42 | |
| 43 | # Construct Go package path |
| 44 | pkgPath="$goPath/src/$pkgName" |
| 45 | |
| 46 | # Set-up src directory tree in GOPATH |
| 47 | mkdir -p "$(dirname "$pkgPath")" |
| 48 | |
| 49 | # Link source dir into GOPATH |
| 50 | ln -sf /src "$pkgPath" |
| 51 | |
| 52 | # change work dir to |
| 53 | cd $pkgPath |
| 54 | |
| 55 | echo "--------------------------------------" |
| 56 | echo "* Resolve dependencies" |
| 57 | if [ -e "$pkgPath/vendor" ]; |
| 58 | then |
| 59 | echo "unsing vendor folder" |
| 60 | elif [ -d "$pkgPath/Godeps" ]; |
| 61 | then |
| 62 | gpm install |
| 63 | elif [ -d "$pkgPath/Godeps/_workspace" ]; |
| 64 | then |
| 65 | # Add local godeps dir to GOPATH |
| 66 | GOPATH=$pkgPath/Godeps/_workspace:$GOPATH |
| 67 | elif [ -f "$pkgPath/glide.yaml" ]; |
| 68 | then |
| 69 | glide install |
| 70 | else |
| 71 | # Get all package dependencies |
| 72 | go get -t -d -v ./... |
| 73 | fi |