build: extract the version number from git
Update the tests as well.
This commit is contained in:
parent
ec8742c9ba
commit
56a80d84cf
7
build
7
build
@ -1,7 +1,10 @@
|
|||||||
#!/bin/bash -e
|
#!/bin/bash -e
|
||||||
|
|
||||||
|
NAME="coreos-cloudinit"
|
||||||
ORG_PATH="github.com/coreos"
|
ORG_PATH="github.com/coreos"
|
||||||
REPO_PATH="${ORG_PATH}/coreos-cloudinit"
|
REPO_PATH="${ORG_PATH}/${NAME}"
|
||||||
|
VERSION=$(git describe --dirty --tags)
|
||||||
|
GLDFLAGS="-X main.version \"${VERSION}\""
|
||||||
|
|
||||||
if [ ! -h gopath/src/${REPO_PATH} ]; then
|
if [ ! -h gopath/src/${REPO_PATH} ]; then
|
||||||
mkdir -p gopath/src/${ORG_PATH}
|
mkdir -p gopath/src/${ORG_PATH}
|
||||||
@ -11,4 +14,4 @@ fi
|
|||||||
export GOBIN=${PWD}/bin
|
export GOBIN=${PWD}/bin
|
||||||
export GOPATH=${PWD}/gopath
|
export GOPATH=${PWD}/gopath
|
||||||
|
|
||||||
go build -o bin/coreos-cloudinit ${REPO_PATH}
|
go build -ldflags "${GLDFLAGS}" -o ${GOBIN}/${NAME} ${REPO_PATH}
|
||||||
|
@ -40,7 +40,6 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
version = "1.5.0+git"
|
|
||||||
datasourceInterval = 100 * time.Millisecond
|
datasourceInterval = 100 * time.Millisecond
|
||||||
datasourceMaxInterval = 30 * time.Second
|
datasourceMaxInterval = 30 * time.Second
|
||||||
datasourceTimeout = 5 * time.Minute
|
datasourceTimeout = 5 * time.Minute
|
||||||
@ -68,6 +67,7 @@ var (
|
|||||||
oem string
|
oem string
|
||||||
validate bool
|
validate bool
|
||||||
}{}
|
}{}
|
||||||
|
version = "was not built properly"
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
@ -138,7 +138,7 @@ func main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if flags.printVersion == true {
|
if flags.printVersion == true {
|
||||||
fmt.Printf("coreos-cloudinit version %s\n", version)
|
fmt.Printf("coreos-cloudinit %s\n", version)
|
||||||
os.Exit(0)
|
os.Exit(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
51
test
51
test
@ -1,19 +1,8 @@
|
|||||||
#!/bin/bash -e
|
#!/bin/bash -e
|
||||||
#
|
|
||||||
# Run all coreos-cloudinit tests
|
|
||||||
# ./test
|
|
||||||
# ./test -v
|
|
||||||
#
|
|
||||||
# Run tests for one package
|
|
||||||
# PKG=initialize ./test
|
|
||||||
#
|
|
||||||
|
|
||||||
# Invoke ./cover for HTML output
|
|
||||||
COVER=${COVER:-"-cover"}
|
|
||||||
|
|
||||||
source ./build
|
source ./build
|
||||||
|
|
||||||
declare -a TESTPKGS=(
|
SRC="
|
||||||
config
|
config
|
||||||
config/validate
|
config/validate
|
||||||
datasource
|
datasource
|
||||||
@ -31,36 +20,22 @@ declare -a TESTPKGS=(
|
|||||||
network
|
network
|
||||||
pkg
|
pkg
|
||||||
system
|
system
|
||||||
)
|
"
|
||||||
|
|
||||||
if [ -z "$PKG" ]; then
|
echo "Checking gofix..."
|
||||||
GOFMTPATH="${TESTPKGS[*]} *.go"
|
go tool fix -diff $SRC
|
||||||
# prepend repo path to each package
|
|
||||||
TESTPKGS="${TESTPKGS[*]/#/${REPO_PATH}/} ./"
|
|
||||||
else
|
|
||||||
GOFMTPATH="$TESTPKGS"
|
|
||||||
# strip out slashes and dots from PKG=./foo/
|
|
||||||
TESTPKGS=${PKG//\//}
|
|
||||||
TESTPKGS=${TESTPKGS//./}
|
|
||||||
TESTPKGS=${TESTPKGS/#/${REPO_PATH}/}
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo "Running tests..."
|
|
||||||
go test -i ${TESTPKGS}
|
|
||||||
go test ${COVER} $@ ${TESTPKGS}
|
|
||||||
|
|
||||||
echo "Checking gofmt..."
|
echo "Checking gofmt..."
|
||||||
fmtRes=$(gofmt -l $GOFMTPATH)
|
gofmt -d -e $SRC
|
||||||
if [ -n "$fmtRes" ]; then
|
|
||||||
echo "$fmtRes"
|
# split SRC into an array and prepend REPO_PATH to each local package for go vet
|
||||||
exit 1
|
split_vet=(${SRC// / })
|
||||||
fi
|
VET_TEST=${split_vet[@]/#/${REPO_PATH}/}
|
||||||
|
|
||||||
echo "Checking govet..."
|
echo "Checking govet..."
|
||||||
vetRes=$(go vet $TESTPKGS)
|
go vet $VET_TEST
|
||||||
if [ -n "${vetRes}" ]; then
|
|
||||||
echo -e "govet checking failed:\n${vetRes}"
|
echo "Running tests..."
|
||||||
exit 255
|
go test -timeout 60s -cover $@ ${VET_TEST} --race
|
||||||
fi
|
|
||||||
|
|
||||||
echo "Success"
|
echo "Success"
|
||||||
|
Loading…
Reference in New Issue
Block a user