-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpublish-release.sh
executable file
·160 lines (142 loc) · 4.84 KB
/
publish-release.sh
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
#!/usr/bin/env bash
set -e
# set -o pipefail # exit if pipe command fails
[ -z "$DEBUG" ] || set -x
##
RELEASE="confinit"
VERSION=${VERSION:-}
DESCRIPTION="Managing configuration at boot time"
GITHUB_REPO="jriguera/confinit"
###
BUILDEB="dpkg-buildpackage -rfakeroot -us -uc"
MAKE="make"
JQ="jq"
CURL="curl -s"
SHA1="sha1sum -b"
# Create a personal github token to use this script
if [ -z "$GITHUB_TOKEN" ]
then
echo "Github TOKEN not defined!"
echo "See https://help.github.com/articles/creating-an-access-token-for-command-line-use/"
exit 1
fi
# You need make installed
if ! [ -x "$(command -v $MAKE)" ]
then
echo "ERROR: $MAKE command not found! Please install it and make it available in the PATH"
exit 1
fi
# You need bosh installed and with you credentials
if ! [ -x "$(command -v $(echo $BUILDEB | cut -d' ' -f 1))" ]
then
echo "ERROR: $MAKE command not found! Please install it and make it available in the PATH"
exit 1
fi
# You need jq installed
if ! [ -x "$(command -v $JQ)" ]
then
echo "ERROR: $JQ command not found! Please install it and make it available in the PATH"
exit 1
fi
### Parse args
case $# in
0)
echo "*** Creating a new release. Automatically calculating version number"
;;
1)
if [ $1 == "-h" ] || [ $1 == "--help" ]
then
echo "Usage: $0 [version-number]"
echo " Creates a release, commits the changes to this repository using tags and uploads "
echo " the release to Github Releases and the final Docker image to Docker Hub. "
echo " It also adds comments based on previous git commits."
exit 0
else
VERSION=$1
if ! [[ $VERSION =~ $RE_VERSION_NUMBER ]]
then
echo "ERROR: Incorrect version number!"
exit 1
fi
echo "*** Creating a new release. Using release version number $VERSION."
fi
;;
*)
echo "ERROR: incorrect argument. See '$0 --help'"
exit 1
;;
esac
echo "* Removing old binaries ..."
$MAKE clean-build
# Creating the release
if [ -z "$VERSION" ]
then
VERSION=$(head -n1 VERSION)
echo "* Creating final release version $VERSION (from VERSION) ..."
else
echo "* Creating final release version $VERSION (from env/input)..."
fi
# Get the last git commit made by this script
LASTCOMMIT=$(git show-ref --tags -d | tail -n 1 | cut -d' ' -f 1)
DEBIAN_CHANGELOG="${RELEASE} (${VERSION}) unstable; urgency=low\n"
if [ -z "$LASTCOMMIT" ]
then
echo "* Changes since the beginning: "
CHANGELOG=$(git log --pretty="- %h %aI %s (%an)")
DEBIAN_CHANGELOG+="$(git log --pretty=' * %s')\n\n"
DEBIAN_CHANGELOG+="$(git log --pretty=' -- %aN <%aE> %aD%n%n' HEAD^..HEAD)"
else
echo "* Changes since last version with commit $LASTCOMMIT: "
CHANGELOG=$(git log --pretty="- %h %aI %s (%an)" "${LASTCOMMIT}..@")
DEBIAN_CHANGELOG+="$(git log --pretty=' * %s' ${LASTCOMMIT}..@)\n\n"
DEBIAN_CHANGELOG+="$(git log --pretty=' -- %aN <%aE> %aD%n%n' ${LASTCOMMIT}^..${LASTCOMMIT})"
fi
if [ -z "$CHANGELOG" ]
then
echo "ERROR: no commits since last release with commit $LASTCOMMIT!. Please "
echo "commit your changes to create and publish a new release!"
exit 1
fi
echo "$CHANGELOG"
# Make
echo "* Generating binaries ..."
$MAKE build
echo "* Generating debian package ..."
# Add changelog to debian/changelog
cp debian/changelog debian/changelog.tmp
echo -e "$DEBIAN_CHANGELOG" > debian/changelog
echo >> debian/changelog
cat debian/changelog.tmp >> debian/changelog
rm -f debian/changelog.tmp
$MAKE deb
git add debian/changelog
git commit -m "updated debian changelog for version $VERSION"
git push
# Create annotated tag
echo "* Creating a git tag ... "
git tag -a "v$VERSION" -m "$RELEASE v$VERSION"
git push --tags
# Create a release in Github
echo "* Creating a new release in Github ... "
DESC=$(cat <<-EOF
# $RELEASE version $VERSION
$DESCRIPTION
## Changes since last version
$CHANGELOG
EOF
)
printf -v data '{"tag_name": "v%s","target_commitish": "master","name": "v%s","body": %s,"draft": false, "prerelease": false}' "$VERSION" "$VERSION" "$(echo "$DESC" | $JQ -R -s '@text')"
releaseid=$($CURL -H "Authorization: token $GITHUB_TOKEN" -H "Content-Type: application/json" -XPOST --data "$data" "https://api.github.com/repos/$GITHUB_REPO/releases" | $JQ '.id')
# Upload the release
echo "* Uploading binaries to Github releases section ... "
for release in build/* deb/*.deb
do
echo -n " URL: "
$CURL -H "Authorization: token $GITHUB_TOKEN" -H "Content-Type: application/octet-stream" --data-binary @"${release}" "https://uploads.github.com/repos/$GITHUB_REPO/releases/$releaseid/assets?name=$(basename ${release})" | $JQ -r '.browser_download_url'
done
# Finish
echo
echo "*** Description https://github.com/$GITHUB_REPO/releases/tag/v$VERSION: "
echo
echo "$DESC"
exit 0