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
80 lines (69 loc) · 2.17 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
#!/bin/bash
# build and test a node module
set -o pipefail
declare Pkg=travis-build-node
declare Version=0.2.0
function msg() {
echo "$Pkg: $*"
}
function err() {
msg "$*" 1>&2
}
# usage: main "$@"
function main () {
msg "running tslint"
if ! tslint '**/*.ts' --exclude 'node_modules/**'; then
err "tslint failed"
return 1
fi
msg "compiling typescript"
if ! tsc -p .; then
err "typescript compilation failed"
return 1
fi
msg "running tests"
if ! npm test; then
err "npm test failed"
return 1
fi
[[ $TRAVIS_PULL_REQUEST == false ]] || return 0
if [[ $TRAVIS_BRANCH == master || $TRAVIS_TAG =~ ^[0-9]+\.[0-9]+\.[0-9]+(-(m|rc)\.[0-9]+)?$ ]]; then
local project_version
if [[ $TRAVIS_TAG =~ ^[0-9]+\.[0-9]+\.[0-9]+(-(m|rc)\.[0-9]+)?$ ]]; then
project_version=$TRAVIS_TAG
else
local pkg_version
pkg_version=$(jq --raw-output .version package.json)
if [[ $? -ne 0 || ! $pkg_version ]]; then
err "failed to parse version from package.json"
return 1
fi
local timestamp
timestamp=$(date -u +%Y%m%d%H%M%S)
if [[ $? -ne 0 || ! $timestamp ]]; then
err "failed to generate timestamp"
return 1
fi
project_version=$pkg_version-$timestamp
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