123 lines
4.0 KiB
Bash
Executable File
123 lines
4.0 KiB
Bash
Executable File
#!/usr/bin/env bash
|
||
|
||
cd src
|
||
|
||
if [ -f debian/changelog ] || [ ! -d .git ]; then
|
||
tamarin_info "Not a Git repository or Debian changelog already exists !"
|
||
exit
|
||
fi
|
||
|
||
# Get pkg tags as tie points in commit history
|
||
pkg_tags="$(git for-each-ref --format '%(refname)' refs/tags | tac)"
|
||
|
||
# Set starting commit
|
||
start_commit='HEAD'
|
||
|
||
# Get commits log as changelog
|
||
|
||
current_release=$(git describe --match "release/*" --abbrev=0)
|
||
|
||
if [[ -z ${current_release} ]]
|
||
then
|
||
tamarin_warn "No release tag found, you repo must have a tag like 'release/*'"
|
||
exit 1
|
||
fi
|
||
|
||
touch debian/changelog
|
||
|
||
project_name=$(tamarin_db get project_name)
|
||
distribution=$(tamarin_db get distribution UNRELEASED)
|
||
urgency=$(tamarin_db get urgency low)
|
||
|
||
function gen_changelog_entry {
|
||
start_commit=$1
|
||
previous_pkg="$(git describe --long --always --match='pkg/*' $start_commit)"
|
||
if [[ "${previous_pkg}" =~ "pkg/" ]]
|
||
then
|
||
tamarin_info "dernier paquet trouvé : ${previous_pkg}"
|
||
extended_version=$(echo $previous_pkg | cut -d "/" -f4)
|
||
exploded_version="$(echo $extended_version | sed "s/\([a-z0-9.]\+\)-\([0-9]\+\)\(-\([0-9]\+\)-\(g[a-z0-9]\+\)\)\?$/\1 \2 \4 \5/")"
|
||
upstream_version=$(echo $exploded_version | cut -d " " -f1)
|
||
package_version=$(echo $exploded_version | cut -d " " -f2)
|
||
distance_to_pkg=$(echo $exploded_version | cut -d " " -f3)
|
||
if [[ "${distance_to_pkg}" > 0 ]]
|
||
then
|
||
tamarin_info "${distance_to_pkg} commit depuis le dernier paquet"
|
||
stop_commit="$(git describe --abbrev=0 --always --match='pkg/*' $start_commit)"
|
||
version=$(expr $package_version + 1)
|
||
else
|
||
stop_commit="$(git describe --abbrev=0 --always --match='pkg/*' ${start_commit}^1)"
|
||
version=$package_version
|
||
tamarin_info "version ${tamarin}"
|
||
fi
|
||
if [[ "${start_commit}" = "${stop_commit}" ]]
|
||
then
|
||
return 1
|
||
fi
|
||
elif [[ "${start_commit}" = "${stop_commit}" ]]
|
||
then
|
||
return 1
|
||
else
|
||
tamarin_info "Pas encore de paquet pour ce dépôt"
|
||
version="1"
|
||
upstream_version="${current_release#release/}"
|
||
stop_commit="${current_release}"
|
||
fi
|
||
|
||
# Set the top commiter as the maintainer of the project if not defined
|
||
# If commit is tagged with pkg/, use tagger name as maintainer
|
||
# Else if commit is not tagged with pkg/, use commiter name as maintainer
|
||
current_release="$(git describe --abbrev=0 --always --match='release/*' $start_commit)"
|
||
tamarin_info "Création de l’entrée de changelog entre ${start_commit} et ${stop_commit}"
|
||
if [[ "$current_release" = "$start_commit" ]] # No package yet, git describe --always returned commit itself
|
||
then
|
||
echo "on passe bien là"
|
||
current_release='UNRELEASED'
|
||
return 1
|
||
fi
|
||
if [ "${start_commit}" == "HEAD" ]
|
||
then
|
||
maintainer="$(git log -n1 --format='%cn <%ce>')"
|
||
maintainer=$(tamarin_db get maintainer "${maintainer}")
|
||
else
|
||
maintainer_commit="$(git describe --abbrev=0 --always --match='pkg/*' $start_commit)"
|
||
maintainer="$(git tag -l --format='%(creator)' ${maintainer_commit})"
|
||
fi
|
||
maintainer=$(tamarin_db get maintainer "${maintainer}")
|
||
|
||
version=${upstream_version}-${version}
|
||
version=${version/_/-}
|
||
tamarin_warn "traitement de la version $version"
|
||
changelog_entry="${project_name} (${version}) ${distribution}; urgency=${urgency}"
|
||
echo "$changelog_entry" >> debian/changelog
|
||
echo >> debian/changelog
|
||
for commit in "$(git log --format='%H' ${stop_commit}..${start_commit})"
|
||
do
|
||
subject="$(git log -n1 --format=%s ${commit})"
|
||
tamarin_info "${subject}"
|
||
echo " * ${subject}" >> debian/changelog
|
||
start_commit="$(git log -n1 --format='%H' ${commit}^1)"
|
||
done
|
||
echo >> debian/changelog
|
||
changelog_sign=" -- ${maintainer} $(date --rfc-2822)"
|
||
echo "$changelog_sign" >> debian/changelog
|
||
echo >> debian/changelog
|
||
start_commit=${stop_commit}
|
||
}
|
||
|
||
function gen_changelog() {
|
||
# while [[ $current_release != 'UNRELEASED' ]]
|
||
# do
|
||
# echo $start_commit
|
||
# echo $current_release
|
||
# gen_changelog_entry $start_commit
|
||
# done
|
||
while gen_changelog_entry $start_commit
|
||
do
|
||
echo $changelog_entry
|
||
done
|
||
}
|
||
|
||
gen_changelog
|
||
cp debian/changelog /dist/changelog
|