Tamarin/hooks/05-create-changelog-prebuild

69 lines
1.7 KiB
Bash
Executable File

#!/usr/bin/env bash
source "${TAMARIN_UTIL}"
if [ -f debian/changelog ] || [ ! -d .git ]; then
info "Not a Git repository or Debian changelog already exists !"
exit
fi
# Get commits log as changelog
BUILD_TAG=$(get_opt build_tag "last")
echo "BUILD TAG IS ${BUILD_TAG}"
if [[ ${BUILD_TAG} == "last" ]]
then
tags=$(git tag master -l "release/*"|sort -r)
else
tagbranch="build-tag-${BUILD_TAG}"
git checkout -b ${tagbranch}
set_opt "tag_branch" "${tag_branch}"
local tags="${BUILD_TAG}"
fi
if [[ -z ${tags} ]]
then
warn "No release tag found, you repo must have a tag like 'release/X.X'"
exit
fi
touch debian/changelog
for tag in ${tags}
do
logs=$(git log --pretty=format:"%an - %h : %s" ${tag} | sed 's/"/\\"/g')
# Set the top commiter as the maintainer of the project if not defined
top_contributor=$(git log --pretty=short | git shortlog -s -n -e | sed 's/^\s*[0-9]*\s*//g' | head -n 1)
maintainer=$(get_opt maintainer "${top_contributor}")
project_name=$(get_opt project_name)
version=${tag#*/} #$(get_opt version 0.0.0)
version=${version/_/-} #$(get_opt version 0.0.0)
distribution=$(get_opt distribution UNRELEASED)
urgency=$(get_opt urgency low)
package_version=${version}
# Define project_version opt if not defined
if [ -z "$(get_opt project_version)" ]; then
# Share computed project version
set_opt project_version "${version}"
fi
echo "${project_name} (${version}) ${distribution}; urgency=${urgency}" >> debian/changelog
echo >> debian/changelog
while read -r entry; do
echo " * ${entry}" >> debian/changelog
done <<< "$(echo -e "${logs}" | sed 's/^"//')"
echo >> debian/changelog
echo " -- ${maintainer} $(date -R)" >> debian/changelog
echo >> debian/changelog
done