forked from keptn-sandbox/alexa-notification-service
-
Notifications
You must be signed in to change notification settings - Fork 0
/
.travis.yml
81 lines (76 loc) · 3.39 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
81
sudo: true
dist: xenial
language: bash
services:
- docker
before_install:
- export TZ=Europe/Vienna
- IMAGE=alipatton10/alexa-service
- REPO_URL="$(git remote get-url --all origin)"
# get the last tag
- GIT_LAST_TAG=$(git describe --tags $(git rev-list --tags) || echo "0.0.0")
- GIT_NUM_COMMITS_SINCE_LAST_TAG=$(git rev-list ${GIT_LAST_TAG}..HEAD --count || echo "trunk")
# get current branch name
- GIT_BRANCH_NAME=$(git branch | grep \* | cut -d ' ' -f2)
- BRANCH=$(if [ "$TRAVIS_PULL_REQUEST" == "false" ]; then echo $TRAVIS_BRANCH; else echo $TRAVIS_PULL_REQUEST_BRANCH; fi)
- echo "TRAVIS_BRANCH=$TRAVIS_BRANCH, PR=$PR, BRANCH=$BRANCH"
- GIT_SHA=$(git rev-parse --short HEAD)
- GIT_BRANCH_AND_COMMIT=$(git describe --exact-match 2> /dev/null || echo "`git symbolic-ref HEAD 2> /dev/null | cut -b 12-`-`git log --pretty=format:\"%h\" -1`")
# find out if we are on a tag (= exact match)
# if not: use tag + number of commit + commit hash
- |
VERSION=$(git describe --exact-match)
if [ $? -ne 0 ]; then
VERSION="${GIT_LAST_TAG}-${GIT_BRANCH_NAME}-${GIT_NUM_COMMITS_SINCE_LAST_TAG}-${GIT_SHA}"
fi
- DATE="$(date +'%Y%m%d.%H%M')"
- ./writeManifest.sh
- cat MANIFEST
# uncomment certain lines from Dockerfile that are for travis builds only
- sed -i '/#travis-uncomment/s/^#travis-uncomment //g' Dockerfile
jobs:
include:
- stage: tests
script:
- echo "Running tests (todo)"
- stage: feature/bug/hotfix/patch
# build docker images for feature/bug/hotfix/patch branches
if: branch =~ ^feature.*$ OR branch =~ ^bug.*$ OR branch =~ ^hotfix.*$ OR branch =~ ^patch.*$
script:
- echo $TRAVIS_BUILD_STAGE_NAME
- TYPE="$(echo $TRAVIS_BRANCH | cut -d'/' -f1)"
- NUMBER="$(echo $TRAVIS_BRANCH | cut -d'/' -f2)"
- docker build . -t "${IMAGE}:${GIT_SHA}" || travis_terminate -1
- docker tag "${IMAGE}:${GIT_SHA}" "${IMAGE}:${TYPE}.${NUMBER}.${DATE}"
after_success:
- echo "$REGISTRY_PASSWORD" | docker login --username $REGISTRY_USER --password-stdin
- docker push "${IMAGE}:${GIT_SHA}"
- docker push "${IMAGE}:${TYPE}.${NUMBER}.${DATE}"
- stage: master/develop
# build docker images for master/develop branch
if: (branch = develop or branch = master) AND NOT type = pull_request
script:
- echo $TRAVIS_BUILD_STAGE_NAME
- docker build . -t "${IMAGE}:${GIT_SHA}" || travis_terminate -1
- docker tag "${IMAGE}:${GIT_SHA}" "${IMAGE}:${DATE}"
- docker tag "${IMAGE}:${GIT_SHA}" "${IMAGE}:latest"
after_success:
- echo "$REGISTRY_PASSWORD" | docker login --username $REGISTRY_USER --password-stdin
- docker push "${IMAGE}:${GIT_SHA}"
- docker push "${IMAGE}:${DATE}"
- docker push "${IMAGE}:latest"
- stage: release-branch
# build docker images for release branches
if: branch =~ ^release.*$ AND NOT type = pull_request
script:
# remove release- form branch name and overwrite the VERSION based on the branch name
- echo $BRANCH
- export VERSION=${BRANCH#"release-"}
- echo $TRAVIS_BUILD_STAGE_NAME - $VERSION
- docker build . -t "${IMAGE}:${GIT_SHA}" || travis_terminate -1
- docker tag "${IMAGE}:${GIT_SHA}" "${IMAGE}:${VERSION}.${DATE}"
- docker tag "${IMAGE}:${GIT_SHA}" "${IMAGE}:${VERSION}"
after_success:
- echo "$REGISTRY_PASSWORD" | docker login --username $REGISTRY_USER --password-stdin
- docker images
- docker push "${IMAGE}"