Skip to content

Commit

Permalink
Merge pull request #93 from kadel/travis-tests
Browse files Browse the repository at this point in the history
Run tests on travis-ci
  • Loading branch information
kadel authored Aug 11, 2016
2 parents 406ba65 + ef1f92e commit e7dfff5
Show file tree
Hide file tree
Showing 8 changed files with 100 additions and 29 deletions.
19 changes: 11 additions & 8 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
# we need trusty because test-cmd depends on jq version >= 1.5
dist : trusty
sudo: required


language: go

go:
- 1.6

branches:
only:
- master

install:
- go get github.com/mitchellh/gox
- go get github.com/tools/godep
- ./script/godep-restore.sh
- true

script:
- make binary
- make binary
# $GOPATH/bin is in $PATH
- mkdir -p $GOPATH/bin
- cp kompose $GOPATH/bin/

- make test-unit
- make test-cmd
12 changes: 12 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,15 @@ all:

binary:
CGO_ENABLED=0 ./script/make.sh binary

binary-cross:
CGO_ENABLED=0 ./script/make.sh binary-cross

clean:
./script/make.sh clean

test-unit:
./script/make.sh test-unit

test-cmd:
./script/make.sh test-cmd
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ file "redis-deployment.json" created
The default `kompose` transformation will generate Kubernetes [Deployments](http://kubernetes.io/docs/user-guide/deployments/) and [Services](http://kubernetes.io/docs/user-guide/services/), in json format. You have alternative option to generate yaml with `-y`. Also, you can alternatively generate [Replication Controllers](http://kubernetes.io/docs/user-guide/replication-controller/) objects, [Deamon Sets](http://kubernetes.io/docs/admin/daemons/), or [Helm](https://github.com/helm/helm) charts.

```console
$ kompose convert
$ kompose convert
file "redis-svc.json" created
file "web-svc.json" created
file "redis-deployment.json" created
Expand Down Expand Up @@ -180,7 +180,7 @@ You need `-tags experimental` because the current `bundlefile` package of docker
- You need `make`

```console
$ make binary
$ make binary-cross
```

## Contributing and Issues
Expand Down
5 changes: 5 additions & 0 deletions script/.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash

GITCOMMIT=$(git rev-parse --short HEAD)

BUILD_FLAGS=(-tags experimental -ldflags="-w -X github.com/skippbox/kompose/version.GITCOMMIT=${GITCOMMIT}")
33 changes: 14 additions & 19 deletions script/binary
Original file line number Diff line number Diff line change
@@ -1,26 +1,21 @@
#!/bin/bash
set -e

if [ -z "$1" ]; then
OS_PLATFORM_ARG=(-os="darwin linux windows")
else
OS_PLATFORM_ARG=($1)
fi

if [ -z "$2" ]; then
OS_ARCH_ARG=(-arch="386 amd64")
else
OS_ARCH_ARG=($2)
fi
source "$(dirname "$BASH_SOURCE")/.build"

GITCOMMIT=$(git rev-parse --short HEAD)
OUT_FILE="./kompose"

# Get rid of existing binaries
rm -f kompose*
# Get rid of existing binary
rm -f $OUT_FILE

# Build binaries
gox "${OS_PLATFORM_ARG[@]}" "${OS_ARCH_ARG[@]}" \
-output="bundles/kompose_{{.OS}}-{{.Arch}}/kompose" \
-tags experimental \
-ldflags="-w -X github.com/skippbox/kompose/version.GITCOMMIT=${GITCOMMIT}" \
# Build binary
go build \
"${BUILD_FLAGS[@]}" \
-o $OUT_FILE \
./cli/main

if [ $? -eq 0 ]; then
echo "Build successful. Program saved as ${OUT_FILE}"
else
echo "Build failed."
fi
27 changes: 27 additions & 0 deletions script/binary-cross
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/bin/bash
set -e

source "$(dirname "$BASH_SOURCE")/.build"

if [ -z "$1" ]; then
OS_PLATFORM_ARG=(-os="darwin linux windows")
else
OS_PLATFORM_ARG=($1)
fi

if [ -z "$2" ]; then
OS_ARCH_ARG=(-arch="386 amd64")
else
OS_ARCH_ARG=($2)
fi

GITCOMMIT=$(git rev-parse --short HEAD)

# Get rid of existing binaries
rm -f kompose*

# Build binaries
gox "${OS_PLATFORM_ARG[@]}" "${OS_ARCH_ARG[@]}" \
-output="bundles/kompose_{{.OS}}-{{.Arch}}/kompose" \
"${BUILD_FLAGS[@]}" \
./cli/main
3 changes: 3 additions & 0 deletions script/test-cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash

./script/test/cmd/tests.sh
26 changes: 26 additions & 0 deletions script/test-unit
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/bin/bash
set -e

source "$(dirname "$BASH_SOURCE")/.build"

find_dirs() {
(
find . -not \( \
\( \
-path './vendor/*' \
\) -prune \
\) -name '*_test.go' -print0 | xargs -0n1 dirname | sed 's|^\./||' | sort -u
)
}

TEST_FLAGS=("${BUILD_FLAGS[@]}" -cover -coverprofile=cover.out)

if [ -z "$TEST_DIRS" ]; then
TEST_DIRS=$(find_dirs '*_test.go')
fi

TESTS_FAILED=()

for dir in $TEST_DIRS; do
go test "${TEST_FLAGS[@]}" "./${dir}"
done

0 comments on commit e7dfff5

Please sign in to comment.