blob: ec63c68ad98970d98ae5082dde9c6f0ab03afa69 [file] [log] [blame]
Sergio Slobodrianc2d86fb2017-07-18 20:35:46 -04001#!/bin/bash
2
3tagName=$1
4
5if ( find /src -maxdepth 0 -empty | read v );
6then
7 echo "Error: Must mount Go source code into /src directory"
8 exit 990
9fi
10
11# Grab Go package name
12pkgName="$(go list -e -f '{{.ImportComment}}' 2>/dev/null || true)"
13
14if [ -z "$pkgName" ];
15then
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
32fi
33
34if [ -z "$pkgName" ];
35then
36 echo "Error: Must add canonical import path to root package"
37 exit 992
38fi
39
40# Grab just first path listed in GOPATH
41goPath="${GOPATH%%:*}"
42
43# Construct Go package path
44pkgPath="$goPath/src/$pkgName"
45
46# Set-up src directory tree in GOPATH
47mkdir -p "$(dirname "$pkgPath")"
48
49# Link source dir into GOPATH
50ln -sf /src "$pkgPath"
51
52# change work dir to
53cd $pkgPath
54
55echo "--------------------------------------"
56echo "* Resolve dependencies"
57if [ -e "$pkgPath/vendor" ];
58then
59 echo "unsing vendor folder"
60elif [ -d "$pkgPath/Godeps" ];
61then
62 gpm install
63elif [ -d "$pkgPath/Godeps/_workspace" ];
64then
65 # Add local godeps dir to GOPATH
66 GOPATH=$pkgPath/Godeps/_workspace:$GOPATH
67elif [ -f "$pkgPath/glide.yaml" ];
68then
69 glide install
70else
71 # Get all package dependencies
72 go get -t -d -v ./...
73fi