-
Notifications
You must be signed in to change notification settings - Fork 10
/
.travis.yml
83 lines (77 loc) · 4.49 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
82
83
# Travis-CI for Golang projects
# Runs the tests, builds the distribution artifacts, uploads them to S3, and produces a
# code coverage report. The upload is segregated by branch name, so each branch gets its own
# uploaded version. (Note: nothing is automatically garbage collected.)
language: go
go:
- 1.16.x
env:
global:
# RSBIN_KEY= to upload to rightscale-binaries bucket in q&b acct:
- secure: "ijNb1OR2HyNxKXMPemlYit+QEyJDahpm0L5nTI4sevJ2+99+L/p/rBGOUfrCxnnAD3Swn9jzkqLjfwZiUqL5MRMzNHtTnCKgmVRZpH6xMeFpZlQqTGVpOeLr1jVbbXlopjro1dtPEFE1ytu0k0AQS2G/kljOwN4FB3pnDsPPKZ0="
# GITHUB_TOKEN= to push code coverage comment to github
- secure: "UarvquG9ge5jXZn4gzfM4IhdYNsQYt3iM+EAlkiYiUMvor1d8nkpw5vSPhpdR7YE5fyCdZTzrqwdnEnACdDdZHLa1jR8PwTnWEWeRq+DBH5XFjcKbG3ODKmRzOYiU138K70I7e0y0eOFqEWsdNvyg/SdemmRgFbIAEZT7KYtEjg="
# COV_KEY= code coverage upload keys
- secure: "kcM2KYw0QC4BpAzUq1P7J1hTPVWDeJrmi6N42Ku5n8b1Bz3JtnFg6XxJcBBM6cPtCCCFhJhYDzXEQ/gX2Q7W7WMns/lcY3jev/1RSZg5Sdbf7y2CEQg/C/cWIlK+EQAOYAeY/B3ikIox+WwnC2P+Eoh7wn0ReTFpxTsmsvF5PDg="
# sudo=false makes the build run using a container
sudo: false
# travis checks rsc out into github.com/rightscale/rsc but for release branches we really need it
# in gopkg.in/rightscale/rsc-v1 so we have to manually move it, sigh
before_install:
- re='^v[0-9]'; if [[ ${TRAVIS_BRANCH} =~ $re ]]; then
cd $HOME/gopath/src;
mkdir -p gopkg.in/rightscale;
mv github.com/rightscale/rsc gopkg.in/rightscale/rsc.${BASH_REMATCH[0]};
export TRAVIS_BUILD_DIR=$HOME/gopath/src/gopkg.in/rightscale/rsc.${BASH_REMATCH[0]};
fi
- cd ${TRAVIS_BUILD_DIR}
- pwd
# here all we're doing is making sure that we have a go compliler for every target architecture
install:
- export PATH=$PATH:$HOME/gopath/bin # travis' worker doesn't seem to do this consistently
before_script: make build
# Everything else in here, we don't put the uploads into an after_success section because
# that can cause the build to succeed even if the artifacts are not actually uploaded
script:
- export NAME=`basename $TRAVIS_REPO_SLUG`
- make travis-test
- echo $PATH
- which gof3r
# Deploy build result to s3
- export AWS_ACCESS_KEY_ID=AKIAIX3L4RHHIREAHABQ
- export AWS_SECRET_ACCESS_KEY=${RSBIN_KEY}
- make upload
# Compute code coverage
- go tool cover -func=`basename $TRAVIS_BUILD_DIR`.coverprofile > coverage.txt
- export COVERAGE=$(grep "^total:" coverage.txt | grep -o "[0-9\.]*")
- echo "Code Coverage is ${COVERAGE}%"
- export BUILD=${TRAVIS_BUILD_NUMBER}
- if [[ "${TRAVIS_PULL_REQUEST}" != "false" ]]; then let BUILD=BUILD-1; fi
- export FILENAME="$(date +%Y-%m-%d)_${BUILD}_Coverage-${COVERAGE}.txt"
- mv coverage.txt $FILENAME
# Post code coverage comment to github
- export CODCOV_URL="https://s3.amazonaws.com/rs-code-coverage/${NAME}/${FILENAME}"
- export JSON_COMMENT="{\"body\":\"Code Coverage is ${COVERAGE}%, details at $CODCOV_URL
(sometimes the URL can take a few minutes to be available)\"}"
- |
if [[ "${TRAVIS_PULL_REQUEST}" != "false" ]]; then
curl -XPOST -s -H "Authorization: token ${GITHUB_TOKEN}" \
-H "Content-Type: application/json" -d "${JSON_COMMENT}" \
"https://api.github.com/repos/rightscale/${NAME}/issues/${TRAVIS_PULL_REQUEST}/comments"
fi
# Deploy code coverage result to S3
- export AWS_ACCESS_KEY_ID=AKIAI4RIGBPD3NP2RQ3Q # code coverage bucket access
- export AWS_SECRET_ACCESS_KEY=${COV_KEY}
- gof3r put -b rs-code-coverage -k ${NAME}/${FILENAME} --acl public-read < ${FILENAME}
# Deploy code coverage badge to S3
# If you change this you *must* verify that the badge actually updates and isn't cached by
# github in perpetuity! The image must serve over https, must have a no-cache header, must
# have a proper content-type, and possbly more...
- export COVERAGE_INT=$(echo $COVERAGE | cut -d. -f1)
- export BADGE_FILENAME=cc_badge_${TRAVIS_BRANCH}.svg
- export BADGE_COLOR=$( if [ ${COVERAGE_INT} -gt 80 ] ; then echo brightgreen ; elif [ ${COVERAGE_INT} -gt 40 ] ; then echo yellow ; else echo red ; fi )
- curl "http://img.shields.io/badge/coverage-${COVERAGE}%25-${BADGE_COLOR}.svg" -L -o ${BADGE_FILENAME}
- gof3r put -b rs-code-coverage -k ${NAME}/${BADGE_FILENAME} --acl public-read -m cache-control:no-cache -m content-type:image/svg+xml < ${BADGE_FILENAME}
notifications:
slack:
#secure: XOzXMfYmpv7xsycDWrjKkLVuZOOfPpYi8BQDVjHaSVzq233ClyqTktUAfLbPRu27E96+FyGueN7Yb6yYHqijYgycx7X7wcbYrE990xDcAzMXJxj3l3gSEzFgj8mRVqkQ9yB17JqZ9bnNRuoCMg4fjdIoI5GZlDkKOzdDJuGA/xs=