Skip to content

Commit

Permalink
travis
Browse files Browse the repository at this point in the history
  • Loading branch information
soi-bot committed Oct 16, 2017
1 parent 2648563 commit 27a37ce
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 0 deletions.
27 changes: 27 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
sudo: required
language: python
services:
- docker
install:
- pip install ansible==2.3.2 molecule==1.25.0 docker git-semver
script:
- if [ -f requirements.yml ]; then ansible-galaxy install -r requirements.yml -p .molecule/roles/. ; fi
- molecule test
deploy:
provider: script
skip_cleanup: true
script:
- ./.travis/generatetag.sh
on:
branch: master
#do not start when tag is added
branches:
only:
- master
tags:
except:
- /^\d+\.\d+\.\d+$/
notifications:
webhooks: https://galaxy.ansible.com/api/v1/notifications/
after_script:
- ./.travis/notification.sh
11 changes: 11 additions & 0 deletions .travis/generatetag.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/bash

git config --global user.email "[email protected]"
git config --global user.name "soi-bot"
GIT_TAG=$([[ "$TRAVIS_COMMIT_MESSAGE" =~ ("Merge pull request".*/feature.*) ]] && git semver --next-minor || git semver --next-patch )
echo $GIT_TAG
git tag $GIT_TAG -a -m "Generated tag from TravisCI for build $TRAVIS_BUILD_NUMBER"
GIT_URL=$(git config --get remote.origin.url)
GIT_URL=${GIT_URL#*//}

git push https://${GH_TOKEN}:@${GIT_URL} --tags
41 changes: 41 additions & 0 deletions .travis/notification.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!/bin/bash

function success {
GIT_TAG=$(git semver)
echo $GIT_TAG
if [ "$TRAVIS_PULL_REQUEST" != "false" ]
then
MESSAGE="Travis [build no. ${TRAVIS_BUILD_NUMBER}](travis-ci.org/${TRAVIS_REPO_SLUG}/builds/${TRAVIS_BUILD_ID}) has finished successfully. Pull request no. ${TRAVIS_PULL_REQUEST} opened by ${GIT_COMMITER} can be found [here](https://github.com/${TRAVIS_REPO_SLUG}/pull/${TRAVIS_PULL_REQUEST})."
else
MESSAGE="Travis [build no. ${TRAVIS_BUILD_NUMBER}](travis-ci.org/${TRAVIS_REPO_SLUG}/builds/${TRAVIS_BUILD_ID}) has finished successfully. Tag [${GIT_TAG}](https://github.com/${TRAVIS_REPO_SLUG}/releases/tag/${GIT_TAG}) was pushed to master by ${GIT_COMMITER}."
fi
echo $MESSAGE
}

function failure {
if [ "$TRAVIS_PULL_REQUEST" != "false" ]
then
MESSAGE="Travis [build no. ${TRAVIS_BUILD_NUMBER}](travis-ci.org/${TRAVIS_REPO_SLUG}/builds/${TRAVIS_BUILD_ID}) has failed. Pull request no. ${TRAVIS_PULL_REQUEST} opened by ${GIT_COMMITER} can be found [here](https://github.com/${TRAVIS_REPO_SLUG}/pull/${TRAVIS_PULL_REQUEST})."
else
MESSAGE="Travis [build no. ${TRAVIS_BUILD_NUMBER}](travis-ci.org/${TRAVIS_REPO_SLUG}/builds/${TRAVIS_BUILD_ID}) has failed. Please check for problems on branch [master](https://github.com/${TRAVIS_REPO_SLUG}/tree/master) which was pushed by ${GIT_COMMITER} on repo [${TRAVIS_REPO_SLUG}](https://github.com/${TRAVIS_REPO_SLUG})."
fi
}

if [ -z "$MM_WEBHOOK" ]
then
echo "MM_WEBHOOK variable is not set!"
exit 0
fi

GIT_COMMITER=$(git show -s --pretty=%an)
echo $GIT_COMMITER
if [ "$TRAVIS_TEST_RESULT" == "0" ]
then
success
COLOR="#00FF00"
else
failure
COLOR="#FF0000"
fi

curl -X POST --data-urlencode "payload={\"username\": \"soi\", \"attachments\": [{ \"color\": \"$COLOR\", \"text\": \"$MESSAGE\" }], \"icon_url\": \"https://maxcdn.icons8.com/office/PNG/512/Programming/bot_80-512.png\"}" "${MM_WEBHOOK}"

0 comments on commit 27a37ce

Please sign in to comment.