summaryrefslogtreecommitdiffstats
path: root/.travis/releaser.sh
blob: db43468de38c02149905c7d18009dfd852f65687 (plain)
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
73
74
75
76
77
78
79
80
81
82
83
84
#!/bin/bash
# SPDX-License-Identifier: MIT
# Copyright (C) 2018 Pawel Krupa (@paulfantom) - All Rights Reserved
# Permission to copy and modify is granted under the MIT license
#
# Original script is available at https://github.com/paulfantom/travis-helper/blob/master/releasing/releaser.sh
#
# 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)
# 

if [ ! -f .gitignore ]
then
  echo "Run as ./travis/$(basename "$0") from top level directory of git repository"
  exit 1
fi

# Exit when latest commit is tagged
[[ $(git tag --points-at) ]] && exit 0

# Some basic variables
GIT_MAIL="pawel+bot@netdata.cloud"
GIT_USER="netdatabot"
# ORGANIZATION=$(echo "$TRAVIS_REPO_SLUG" | awk -F '/' '{print $1}')
# PROJECT=$(echo "$TRAVIS_REPO_SLUG" | awk -F '/' '{print $2}')

# 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#*//}

# Figure out next tag based on commit message
# OLD_TAG="$(git semver)"
GIT_TAG=none
echo "Last commit message: $TRAVIS_COMMIT_MESSAGE"
case "${TRAVIS_COMMIT_MESSAGE}" in
  *"[patch]"*|*"[fix]"* )                GIT_TAG="v$(git semver --next-patch)" ;;
  *"[minor]"*|*"[feat]"*|*"[feature]"* ) GIT_TAG="v$(git semver --next-minor)" ;;
  *"[major]"*|*"[breaking change]"* )    GIT_TAG="v$(git semver --next-major)" ;;
  *) echo "Keyword not detected. Doing nothing" ;;
esac

# Tag it!
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:1.14.3 \
#                                                        --user "${ORGANIZATION}" \
#                                                        --token "${GH_TOKEN}" \
#                                                        --project "${PROJECT}" \
#                                                        --since-tag "${OLD_TAG}" \
#                                                        --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