From 7c424f1995a9888a986a4f64da89c2353a9c0a76 Mon Sep 17 00:00:00 2001 From: paulfantom Date: Sat, 21 Apr 2018 15:11:51 +0200 Subject: [PATCH] change way releases work; update license year --- .travis.yml | 2 +- .travis/generatetag.sh | 16 ---------- .travis/releaser.sh | 71 ++++++++++++++++++++++++++++++++++++++++++ LICENSE | 2 +- 4 files changed, 73 insertions(+), 18 deletions(-) delete mode 100755 .travis/generatetag.sh create mode 100755 .travis/releaser.sh diff --git a/.travis.yml b/.travis.yml index 81335ea..bbf038b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -14,7 +14,7 @@ script: deploy: provider: script skip_cleanup: true - script: ./.travis/generatetag.sh + script: .travis/releaser.sh on: branch: master branches: diff --git a/.travis/generatetag.sh b/.travis/generatetag.sh deleted file mode 100755 index fc79a6f..0000000 --- a/.travis/generatetag.sh +++ /dev/null @@ -1,16 +0,0 @@ -#!/bin/bash - -# Test if current commit is already tagged -git tag --points-at -[[ $(git tag --points-at) ]] && exit 0 - -git config --global user.email "paulfantom@gmail.com" -git config --global user.name "paulfantom" -GIT_TAG=$([[ "$TRAVIS_COMMIT_MESSAGE" =~ ("Merge pull request".*\[feature\].*) ]] && git semver --next-minor || git semver --next-patch ) -echo "$TRAVIS_COMMIT_MESSAGE" -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 || exit 0 diff --git a/.travis/releaser.sh b/.travis/releaser.sh new file mode 100755 index 0000000..0c04ce8 --- /dev/null +++ b/.travis/releaser.sh @@ -0,0 +1,71 @@ +#!/bin/bash +# +# Copyright (C) 2018 Pawel Krupa (@paulfantom) - All Rights Reserved +# Permission to copy and modify is granted under the MIT license +# +# Script to automatically do a couple of things: +# - generate a new tag according to semver (https://semver.org/) +# - generate CHANGELOG.md by using https://github.com/skywinder/github-changelog-generator +# - sync CHANGELOG with GitHub releases by using https://github.com/mattbrictson/chandler +# +# Tags are generated by searching for a keyword in last commit message. Keywords are: +# - [patch] or [fix] to bump patch number +# - [minor], [feature] or [feat] to bump minor number +# - [major] or [breaking change] to bump major number +# All keywords MUST be surrounded with square braces. +# +# Script uses git mechanisms for locking, so it can be used in parallel builds +# +# Requirements: +# - GH_TOKEN variable set with GitHub token. Access level: repo.public_repo +# - docker +# - git-semver python package (pip install git-semver) + +# Exit when latest commit is tagged +[[ $(git tag --points-at) ]] && exit 0 + +# Some basic variables +GIT_MAIL="cloudalchemybot@gmail.com" +GIT_USER="cloudalchemybot" +ORGANIZATION=$(echo "$TRAVIS_REPO_SLUG" | awk -F '/' '{print $1}') +PROJECT=$(echo "$TRAVIS_REPO_SLUG" | awk -F '/' '{print $2}') +GALAXY_URL="https://galaxy.ansible.com/${ORGANIZATION}/${PROJECT#ansible-}" + +# Git config +git config --global user.email "${GIT_MAIL}" +git config --global user.name "${GIT_USER}" +GIT_URL=$(git config --get remote.origin.url) +GIT_URL=${GIT_URL#*//} + +# Generate TAG +GIT_TAG=none +echo "Last commit message: $TRAVIS_COMMIT_MESSAGE" +case "${TRAVIS_COMMIT_MESSAGE}" in + *"[patch]"*|*"[fix]"* ) GIT_TAG=$(git semver --next-patch) ;; + *"[minor]"*|*"[feat]"*|*"[feature]"* ) GIT_TAG=$(git semver --next-minor) ;; + *"[major]"*|*"[breaking change]"* ) GIT_TAG=$(git semver --next-major) ;; + *) echo "Keyword not detected. Doing nothing" ;; +esac +if [ "$GIT_TAG" != "none" ]; then + echo "Assigning new tag: $GIT_TAG" + git tag "$GIT_TAG" -a -m "Automatic tag generation for travis build no. $TRAVIS_BUILD_NUMBER" + git push "https://${GH_TOKEN}:@${GIT_URL}" --tags || exit 0 +fi + +# Generate CHANGELOG.md +git checkout master +git pull +docker run -it --rm -v "$(pwd)":/usr/local/src/your-app ferrarimarco/github-changelog-generator \ + -u "${ORGANIZATION}" -p "${PROJECT}" --token "${GH_TOKEN}" \ + --release-url "${GALAXY_URL}" \ + --unreleased-label "**Next release**" --no-compare-link + +git add CHANGELOG.md +git commit -m '[ci skip] Automatic changelog update' + +git push "https://${GH_TOKEN}:@${GIT_URL}" || exit 0 + +# Sync changelog to github releases +if [ "$GIT_TAG" != "none" ]; then + docker run -e CHANDLER_GITHUB_API_TOKEN="${GH_TOKEN}" -v "$(pwd)":/chandler -ti whizark/chandler push "${GIT_TAG}" +fi diff --git a/LICENSE b/LICENSE index 2c376b4..2b1b2c0 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ The MIT License (MIT) -Copyright (c) 2017 Pawel Krupa and Roman Demachkovych +Copyright (c) 2017-2018 Pawel Krupa and Roman Demachkovych Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal