#!/bin/bash

set -ex

release=buster
relnum=10

# assume that upstream/master has already been updated, since the package
# goes into unstable first.
date=${1:-$(date -u -d $(git log -1 --date=short --pretty=format:%cI upstream) +%Y%m%d.%H%M)}
git merge -m "merge upstream changes to ${date}" "publicsuffix/${date}"
git log -n30 "publicsuffix/${date}" > debian/upstream-changes.txt
git add debian/upstream-changes.txt
newver="${date}-0+deb${relnum}u1"
dch --distribution "$release" -v "$newver" 'new upstream publicsuffix data'
git add debian/changelog
git commit -m "new upstream version ${date}"
gbp buildpackage --git-tag --changes-option=-S
debian/rules clean
git push salsa --follow-tags "debian/$release"
prevver="$(dpkg-parsechangelog -o 1 -c 1 -S Version)"
debdiff="publicsuffix_${prevver}_${newver}.debdiff"
debdiff  "../publicsuffix_${prevver}.dsc" "../publicsuffix_${newver}.dsc" | gzip -n -9 > ../"$debdiff".gz
cat > "../publicsuffix_${newver}_${release}.eml" <<EOF
Please consider an update to publicsuffix in debian $release.

This package reflects the state of the network, and keeping it current
is useful for all the packages that depend on it.

The debdiff from the previous version in $release is attached.

This proposed release is also available at the
"publicsuffix_debian/$newver" tag on the "debian/$release" branch at
the git repo for publicsuffix packaging:

    https://salsa.debian.org/debian/publicsuffix

Please followup on this ticket to confirm whether I should upload this
revision to $release.

EOF

reportbug --attach=../"$debdiff".gz --subject="$release-pu: package publicsuffix/$newver" \
          --body-file="../publicsuffix_${newver}_${release}.eml" --no-query-bts --severity=normal \
          --pseudo-header="Tags: $release" \
          --pseudo-header="User: release.debian.org@packages.debian.org" \
          --pseudo-header="Usertags: pu" \
          --pseudo-header="Control: affects -1 src:publicsuffix" \
          release.debian.org
