Exclude deployment for pull requests, move docker and sudo requirements to deploy step

This commit is contained in:
ErickSkrauch 2020-01-05 23:35:10 +03:00
parent a8e4f7ae56
commit bc1427dd1f

View File

@ -1,16 +1,11 @@
sudo: required
language: go language: go
go: go:
- 1.13 - "1.13"
services:
- docker
stages: stages:
- test - test
- name: deploy - name: deploy
if: branch = master OR tag IS present if: env(TRAVIS_PULL_REQUEST) = false AND (branch = master OR tag IS present)
install: install:
- go get -u github.com/golang/dep/cmd/dep - go get -u github.com/golang/dep/cmd/dep
@ -20,23 +15,27 @@ jobs:
include: include:
- stage: test - stage: test
script: script:
- go test -v -race -coverprofile=coverage.txt -covermode=atomic ./... - go test -v -race -coverprofile=coverage.txt -covermode=atomic ./...
- bash <(curl -s https://codecov.io/bash) - bash <(curl -s https://codecov.io/bash)
- stage: deploy - stage: deploy
sudo: required
services:
- docker
script: script:
- docker login -u="$DOCKER_USERNAME" -p="$DOCKER_PASSWORD" - docker login -u="$DOCKER_USERNAME" -p="$DOCKER_PASSWORD"
- export DOCKER_TAG="${TRAVIS_TAG:-dev}" - export DOCKER_TAG="${TRAVIS_TAG:-dev}"
- export APP_VERSION="${TRAVIS_TAG:-dev-${TRAVIS_COMMIT:0:7}}" - export APP_VERSION="${TRAVIS_TAG:-dev-${TRAVIS_COMMIT:0:7}}"
- > - >
env CGO_ENABLED=0 GOOS=linux GOARCH=amd64 env CGO_ENABLED=0 GOOS=linux GOARCH=amd64
go build go build
-o release/chrly -o release/chrly
-ldflags '-extldflags "-static" -X github.com/elyby/chrly/version.version=$APP_VERSION -X github.com/elyby/chrly/version.commit=$TRAVIS_COMMIT' -ldflags '-extldflags "-static" -X github.com/elyby/chrly/version.version=$APP_VERSION -X github.com/elyby/chrly/version.commit=$TRAVIS_COMMIT'
main.go main.go
- docker build -t elyby/chrly:$DOCKER_TAG . - docker build -t elyby/chrly:$DOCKER_TAG .
- docker push elyby/chrly:$DOCKER_TAG - docker push elyby/chrly:$DOCKER_TAG
- | - |
if [ ! -z ${TRAVIS_TAG+x} ] && [[ "$TRAVIS_TAG" != *"-"* ]]; then if [ ! -z ${TRAVIS_TAG+x} ] && [[ "$TRAVIS_TAG" != *"-"* ]]; then
docker tag elyby/chrly:$DOCKER_TAG elyby/chrly:latest docker tag elyby/chrly:$DOCKER_TAG elyby/chrly:latest
docker push elyby/chrly:latest docker push elyby/chrly:latest
fi fi