-
Notifications
You must be signed in to change notification settings - Fork 0
/
.travis.yml
80 lines (68 loc) · 2.82 KB
/
.travis.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# use the latest ubuntu environment (16.04) available on travis
dist: xenial
language: go
go:
- "1.12.x"
env:
global:
# Force-enable Go modules. Also force go to use the code in vendor/
# These will both be unnecessary when Go 1.13 lands.
- GO111MODULE=on
# - GOFLAGS="-mod vendor"
- CUSTOM_GOFLAGS="-mod vendor"
- TWEETWATCH_TEST_POSTGRES_DSN="postgres://postgres@127.0.0.1:5432/tweetwatch"
- TWEETWATCH_TEST_TEST_PORT=1308
# These environment variables must be available during tests running:
# TWEETWATCH_TEST_TWITTER_CONSUMER_KEY
# TWEETWATCH_TEST_TWITTER_CONSUMER_SECRET
# TWEETWATCH_TEST_TWITTER_ACCESS_TOKEN
# TWEETWATCH_TEST_TWITTER_ACCESS_SECRET
- TRAVIS_COMMIT_SHORT="$(git rev-parse --short ${TRAVIS_COMMIT})"
# Only clone the most recent commit.
git:
depth: 1
# Skip the install step. Don't `go get` dependencies. Only build with the code
# in vendor/
install: true
# Don't email me the results of the test runs.
notifications:
email: false
services:
- postgresql
- docker
# Anything in before_script that returns a nonzero exit code will flunk the
# build and immediately stop. It's sorta like having set -e enabled in bash.
# Make sure golangci-lint is vendored.
before_script:
- psql -c 'create database tweetwatch;' -U postgres
- ./tools/migrate.linux-amd64 -source file:schema/postgres -database "$TWEETWATCH_TEST_POSTGRES_DSN" up
# Main pipe line
jobs:
include:
- stage: test
script: go test $CUSTOM_GOFLAGS -race -coverprofile=coverage.txt -covermode=atomic ./...
- stage: e2e
script:
- cp tweetwatch.yml.example tweetwatch.yml
- POSTGRES_DSN="$TWEETWATCH_TEST_POSTGRES_DSN" TWITTER_PROVIDER=void REST_PORT="$TWEETWATCH_TEST_TEST_PORT" go run -mod=vendor cmd/server/server.go > server.log &2>1 &
- |
echo "Waiting Tweetwatch to launch on $TWEETWATCH_TEST_TEST_PORT..."
while ! nc -z localhost "$TWEETWATCH_TEST_TEST_PORT"; do
sleep 0.1
done
echo "Tweetwatch launched"
- cd tests/e2e
- yarn
- yarn test
- kill -9 $(ps aux | grep "server.go" | grep -v "grep" | awk '{ print $2 }')
after_success:
- bash <(curl -s https://codecov.io/bash)
# Publish the docker image.
# Each successful build in the master branch also will be published with tag "latest".
# Each successful build (any branch exclude master) will be published with tag "edge".
- echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin
- export TAG=`if [ "$TRAVIS_BRANCH" == "master" ]; then echo "latest"; else echo "edge" ; fi`
- docker build --no-cache -t ${TRAVIS_REPO_SLUG}:${TRAVIS_COMMIT_SHORT} -f Dockerfile .
- docker tag ${TRAVIS_REPO_SLUG}:${TRAVIS_COMMIT_SHORT} ${TRAVIS_REPO_SLUG}:$TAG
- docker image ls
- docker push ${TRAVIS_REPO_SLUG}