Skip to content
Snippets Groups Projects
Commit c89b1958 authored by Markus Frosch's avatar Markus Frosch
Browse files

Add icinga-build-release script

parent 2124611f
No related branches found
No related tags found
No related merge requests found
#!/bin/bash
set -e
: "${GIT_REMOTE:=origin}"
: "${DCH_DIST:=icinga}"
error() {
if [ -t 2 ]; then
{
echo -ne '\e[31m'
echo -n "$*"
echo -e '\e[39m'
} >&2
else
echo "$*" >&2
fi
}
fail() {
error "$@"
exit 1
}
help() {
echo "Usage: $0 <version> [message]"
echo
}
if [ $# -ge 1 ]; then
version="$1"
else
help
fail "Missing version"
fi
if [ $# -ge 2 ]; then
message="$2"
elif [[ "${version}" = *-* ]]; then
message="Release version ${version}"
else
message="Update to ${version}"
fi
# Detect git repository
if ! git_repo="$(git rev-parse --show-toplevel)"; then
fail "Could not detect git repository!"
fi
# Are we in the top directory of the git repository
if [ "$(pwd)" != "${git_repo}" ]; then
echo "Switching to directory ${git_repo}"
cd "${git_repo}"
fi
# Detect packaging variant
if [ -e "debian/changelog" ]; then
variant=deb
elif [ -n "$(ls ./*.spec 2>/dev/null)" ]; then
variant=rpm
else
fail "Could not detect packaging variant! Looking for debian/changelog or *.spec"
fi
# Ensure git is up to date
echo "Fetching latest git version from ${GIT_REMOTE}"
(set -x; git fetch -p "${GIT_REMOTE}")
git_branch="$(git rev-parse --abbrev-ref HEAD)"
git_commit="$(git rev-parse HEAD)"
git_commit_upstream="$(git rev-parse "${GIT_REMOTE}/${git_branch}")"
if [ "${git_commit}" != "${git_commit_upstream}" ]; then
git status
fail "Local and remote branch ${git_branch} are not in sync!"
fi
# Check uncommited files
if [ -n "$(git status -s)" ]; then
git status
fail "Git repository is not clean, please commit or remove files!"
fi
# Check if tag already exists
if [ -n "$(git show-ref "tags/${version}")" ]; then
git show "tags/${version}"
fail "There is already a tag named '${version}'!"
fi
# Doing the actual work now
if [ "$variant" = deb ]; then
echo "Updating version with dch"
DEBFULLNAME="$(git config user.name)"
DEBEMAIL="$(git config user.email)"
export DEBFULLNAME DEBEMAIL
dchopt=()
if [[ "${version}" != *-* ]]; then
full_version="${version}-1"
else
full_version="${version}"
dchopt+=(--force-distribution -D "${DCH_DIST}")
fi
(set -x; dch -v "${full_version}" "${dchopt[@]}" -- "${message}")
# Staging the change
git add debian/changelog
else # rpm
fail "RPM not yet implemented!" >&2
fi
# Show the user what changed
git diff --color=auto --cached
if [[ "${version}" != *-* ]]; then
echo "Version ${version} does not contain a revision, assuming version bump!"
exit 0
fi
do_commit=
read -r -p "Do you want me to commit the changes? [Y/n] " do_commit
[ -n "$do_commit" ] || do_commit=yes
case "$do_commit" in
y*|Y*)
echo "Committing changes with message: ${message}"
git commit -m "${message}"
;;
*)
echo "Aborting."
exit 1
;;
esac
do_tag=
read -r -p "Do you want me to tag the release? [Y/n] " do_tag
[ -n "$do_tag" ] || do_tag=yes
case "$do_tag" in
y*|Y*)
echo "Creating tag ${version}"
git tag -m "${message}" "${version}"
;;
*)
echo "Aborting."
exit 1
;;
esac
do_push=
read -r -p "Do you want me to push branch '${git_branch}' and tag '${version}'? [Y/n] " do_push
[ -n "$do_push" ] || do_push=yes
case "$do_push" in
y*|Y*)
echo "Pushing branch ${git_branch}"
git push "${GIT_REMOTE}" "${git_branch}"
echo "Pushing tag ${version}"
git push "${GIT_REMOTE}" "${version}"
;;
*)
echo "Aborting."
exit 1
;;
esac
# vi: ts=2 sw=2 expandtab :
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment