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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
|
#!/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
# - create draft of GitHub releases by using https://github.com/github/hub
#
# 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:
# - GITHUB_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
echo "---- INITIALIZING CONFIGURATION -----"
# 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}')
HUB_VERSION=${HUB_VERSION:-"2.5.1"}
# Git config
git config user.email "${GIT_MAIL}"
git config user.name "${GIT_USER}"
GIT_URL=$(git config --get remote.origin.url)
GIT_URL=${GIT_URL#*//}
echo "---- FIGURING OUT TAGS-----"
# Check if current commit is tagged or not
GIT_TAG=$(git tag --points-at)
if [ -z "${GIT_TAG}" ]; then
# Figure out next tag based on commit message
GIT_TAG=HEAD
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" != "HEAD" ]; then
echo "Assigning a new tag: $GIT_TAG"
git tag "$GIT_TAG" -a -m "Automatic tag generation for travis build no. $TRAVIS_BUILD_NUMBER"
git push "https://${GITHUB_TOKEN}:@${GIT_URL}" --tags || exit 0 # exits if tag exists
fi
fi
# If GIT_TAG is still having value "HEAD" then script entered a state where there was no keyword in commit msg and commit wasn't tagged.
# This condition can be triggered by a cron job and it shouldn't create a release but might be still useful for changelog generation.
echo "---- CREATING CHANGELOG -----"
#PREV_TAG=$(git describe --abbrev=0 "${GIT_TAG}"^)
git checkout master
git pull
#docker run -it --rm -v "$(pwd)":/usr/local/src/your-app ferrarimarco/github-changelog-generator:1.14.3 \
docker run -it -v "$(pwd)":/project markmandel/github-changelog-generator:latest \
--user "${ORGANIZATION}" \
--project "${PROJECT}" \
--token "${GITHUB_TOKEN}" \
--since-tag "v1.10.0" \
--unreleased-label "**Next release**" \
--no-compare-link \
--exclude-labels duplicate,question,invalid,wontfix,discussion,documentation
echo "---- UPLOADING CHANGELOG -----"
git add CHANGELOG.md
git commit -m '[ci skip] Automatic changelog update'
git push "https://${GITHUB_TOKEN}:@${GIT_URL}" || exit 0 # Exit if changlog was already uploaded
if [ "${GIT_TAG}" == "HEAD" ]; then
echo "Not creating a release since neither of two conditions was met:"
echo " - keyword in commit message"
echo " - commit is tagged"
exit 0
fi
echo "---- CREATING RELEASE ARTIFACTS -----"
python -c 'import os,sys,fcntl; flags = fcntl.fcntl(sys.stdout, fcntl.F_GETFL); fcntl.fcntl(sys.stdout, fcntl.F_SETFL, flags&~os.O_NONBLOCK);'
./makeself/build-x86_64-static.sh
make dist
ln -s netdata-latest.gz.run "netdata-${GIT_TAG}.gz.run"
ln -s netdata-*.tar.gz "netdata-${GIT_TAG}.tar.gz"
sha256sum -b "netdata-${GIT_TAG}.gz.run" "netdata-${GIT_TAG}.tar.gz" > "sha256sums.txt"
echo "---- CREATING RELEASE DRAFT WITH ASSETS -----"
# Download hub
wget "https://github.com/github/hub/releases/download/v${HUB_VERSION}/hub-linux-amd64-${HUB_VERSION}.tgz" -O "/tmp/hub-linux-amd64-${HUB_VERSION}.tgz"
tar -C /tmp -xvf "/tmp/hub-linux-amd64-${HUB_VERSION}.tgz"
export PATH=$PATH:"/tmp/hub-linux-amd64-${HUB_VERSION}/bin"
# Create a release draft
hub release create --draft -a "netdata-${GIT_TAG}.tar.gz" -a "netdata-${GIT_TAG}.gz.run" -a "sha256sums.txt" -m "${GIT_TAG}" "${GIT_TAG}"
|