-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuild-helpers.sh
72 lines (66 loc) · 2.06 KB
/
build-helpers.sh
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
#!/bin/bash
# functions to commits on a branch in a Travis CI build
# be sure to avoid creating a Travis CI fork bomb
# see https://github.com/travis-ci/travis-ci/issues/1701
# based on https://gist.github.com/ddgenome/f3a60fe4c2af0cbe758556d982fbeea9
function travis_checkout_branch() {
local head_ref branch_ref
head_ref=$(git rev-parse HEAD)
if [[ $? -ne 0 || ! $head_ref ]]; then
err "failed to get HEAD reference"
return 1
fi
branch_ref=$(git rev-parse "$TRAVIS_BRANCH")
if [[ $? -ne 0 || ! $branch_ref ]]; then
err "failed to get $TRAVIS_BRANCH reference"
return 1
fi
if [[ $head_ref != $branch_ref ]]; then
msg "HEAD ref ($head_ref) does not match $TRAVIS_BRANCH ref ($branch_ref)"
msg "someone may have pushed new commits before this build cloned the repo"
return 0
fi
if ! git checkout "$TRAVIS_BRANCH"; then
err "failed to checkout $TRAVIS_BRANCH"
return 1
fi
}
function travis_add_and_commit() {
if [[ $# -ne 2 ]]; then
err "incorrect number of arguments"
return 1
fi
local add_path="$1"
local commit_message="$2"
git config --global user.name "Travis CI"
if ! git add --all $add_path; then
err "failed to add modified files to git index"
return 1
fi
# make Travis CI skip this build
if ! ( git diff --staged --quiet $add_path || git commit -m "$commit_message [ci skip]" ); then
err "failed to commit updates"
return 1
fi
}
function travis_push() {
if [[ $# -ne 1 ]]; then
err "incorrect number of arguments"
return 1
fi
local push_what="$1"
local remote=origin
if [[ $GITHUB_TOKEN ]]; then
remote=https://[email protected]/$TRAVIS_REPO_SLUG
fi
if ! git push --quiet --follow-tags "$remote" "$push_what" > /dev/null 2>&1; then
err "failed to push git changes, did you forget to configure a GitHub token?"
return 1
fi
}
function msg() {
echo "travis-commit: $*"
}
function err() {
msg "$*" 1>&2
}