-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[muzi] adding script to commit to github from travis-ci ✊
- Loading branch information
Showing
2 changed files
with
66 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
#!/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 | ||
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 "Travis CI update [ci skip]"; then | ||
err "failed to commit updates" | ||
return 1 | ||
fi | ||
# add to your .travis.yml: `branches\n except:\n - "/\\+travis\\d+$/"\n` | ||
local git_tag=SOME_TAG_TRAVIS_WILL_NOT_BUILD+travis$TRAVIS_BUILD_NUMBER | ||
if ! git tag "$git_tag" -m "Generated tag from Travis CI build $TRAVIS_BUILD_NUMBER"; then | ||
err "failed to create git tag: $git_tag" | ||
return 1 | ||
fi | ||
local remote=origin | ||
if [[ $GITHUB_API_KEY ]]; then | ||
remote=https://$GITHUB_API_KEY@github.com/$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" > /dev/null 2>&1; then | ||
err "failed to push git changes" | ||
return 1 | ||
fi | ||
} | ||
|
||
function msg() { | ||
echo "travis-commit: $*" | ||
} | ||
|
||
function err() { | ||
msg "$*" 1>&2 | ||
} |