This repository has been archived by the owner on Mar 19, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
travis-build.bash
83 lines (72 loc) · 2.67 KB
/
travis-build.bash
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
#!/bin/bash
# build, test, and publish maven projects on Travis CI
set -o pipefail
declare Pkg=travis-build-mvn
declare Version=0.1.0
function msg() {
echo "$Pkg: $*"
}
function err() {
msg "$*" 1>&2
}
function main() {
msg "branch is ${TRAVIS_BRANCH}"
local mvn="mvn --settings .settings.xml -B -V -U"
local project_version
if [[ $TRAVIS_TAG =~ ^[0-9]+\.[0-9]+\.[0-9]+(-(m|rc)\.[0-9]+)?$ ]]; then
if ! $mvn build-helper:parse-version versions:set -DnewVersion="$TRAVIS_TAG" versions:commit; then
err "failed to set project version"
return 1
fi
project_version="$TRAVIS_TAG"
else
if ! $mvn build-helper:parse-version versions:set -DnewVersion=\${parsedVersion.majorVersion}.\${parsedVersion.minorVersion}.\${parsedVersion.incrementalVersion}-\${timestamp} versions:commit
then
err "failed to set timestamped project version"
return 1
fi
project_version=$(mvn help:evaluate -Dexpression=project.version | grep -v "^\[")
if [[ $? != 0 || ! $project_version ]]; then
err "failed to parse project version"
return 1
fi
fi
if ! $mvn install -U -Dmaven.javadoc.skip=true; then
err "maven install failed"
return 1
fi
if [[ $TRAVIS_PULL_REQUEST != false ]]; then
msg "not publishing or tagging pull request"
return 0
fi
if [[ $TRAVIS_BRANCH == rug-* || $TRAVIS_BRANCH == master || $TRAVIS_TAG =~ ^[0-9]+\.[0-9]+\.[0-9]+(-(m|rc)\.[0-9]+)?$ ]]; then
msg "version is $project_version"
local mvn_deploy_args
if [[ $TRAVIS_BRANCH == master ]]; then
mvn_deploy_args=-DaltDeploymentRepository=public-atomist-dev::default::https://atomist.jfrog.io/atomist/libs-dev-local
fi
if ! $mvn deploy -DskipTests $mvn_deploy_args; then
err "maven deploy failed"
return 1
fi
if ! git config --global user.email "travis-ci@atomist.com"; then
err "failed to set git user email"
return 1
fi
if ! git config --global user.name "Travis CI"; then
err "failed to set git user name"
return 1
fi
local git_tag=$project_version+travis$TRAVIS_BUILD_NUMBER
if ! git tag "$git_tag" -m "Generated tag from TravisCI build $TRAVIS_BUILD_NUMBER"; then
err "failed to create git tag: $git_tag"
return 1
fi
if ! git push --quiet --tags "https://$GITHUB_TOKEN@github.com/$TRAVIS_REPO_SLUG" > /dev/null 2>&1; then
err "failed to push git tags"
return 1
fi
fi
}
main "$@" || exit 1
exit 0