From 27a37cef47050d53551ef78e832a6daf6ac6b813 Mon Sep 17 00:00:00 2001 From: soi-bot Date: Mon, 16 Oct 2017 13:53:12 +0200 Subject: [PATCH] travis --- .travis.yml | 27 +++++++++++++++++++++++++++ .travis/generatetag.sh | 11 +++++++++++ .travis/notification.sh | 41 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 79 insertions(+) create mode 100644 .travis.yml create mode 100644 .travis/generatetag.sh create mode 100644 .travis/notification.sh diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..a0c99a4 --- /dev/null +++ b/.travis.yml @@ -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 \ No newline at end of file diff --git a/.travis/generatetag.sh b/.travis/generatetag.sh new file mode 100644 index 0000000..681b571 --- /dev/null +++ b/.travis/generatetag.sh @@ -0,0 +1,11 @@ +#!/bin/bash + +git config --global user.email "soibot@sointeractive.pl" +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 \ No newline at end of file diff --git a/.travis/notification.sh b/.travis/notification.sh new file mode 100644 index 0000000..c6d17d7 --- /dev/null +++ b/.travis/notification.sh @@ -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}"