-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtravis-ci-git-commit.bash
72 lines (67 loc) · 2.06 KB
/
travis-ci-git-commit.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
#!/bin/bash
# function to make a commit 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
#
# set -o errexit -o nounset
# setup_git() {
# git config --global user.email "[email protected]"
# git config --global user.name "Travis CI"
# }
function travis-branch-commit() {
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
if ! git add --all .; then
err "failed to add modified files to git index"
return 1
fi
# make Travis CI skip this build
if ! git commit -m "Update precompiled version [ci skip]"; then
err "failed to commit updates"
return 0
fi
# Force-replacing travis tag, only keep one
export git_tag="ci-ignore"
if ! git tag "$git_tag" -f -m "Generated tag from TravisCI for build $TRAVIS_BUILD_NUMBER"; then
err "failed to create git tag: $git_tag"
return 1
fi
local remote=origin
if [[ $GH_TOKEN ]]; then
remote=https://[email protected]/$TRAVIS_REPO_SLUG
fi
if [[ $TRAVIS_BRANCH != master ]]; then
msg "not pushing updates to branch $TRAVIS_BRANCH"
return 0
fi
if ! git push --quiet --follow-tags "$remote" "$TRAVIS_BRANCH"; then
err "failed to push git changes"
return 1
fi
}
function msg() {
echo "travis-commit: $*"
}
function err() {
msg "$*" 1>&2
}
# setup_git
travis-branch-commit