diff --git a/package-source-builder/overlay/usr/bin/apertis-pkg-merge-updates b/package-source-builder/overlay/usr/bin/apertis-pkg-merge-updates index a57c933acc86bb16ee5d1e4abe4cdb882a6a80e2..612c7dafd5176928fbd73f335828390b58034ee7 100755 --- a/package-source-builder/overlay/usr/bin/apertis-pkg-merge-updates +++ b/package-source-builder/overlay/usr/bin/apertis-pkg-merge-updates @@ -16,13 +16,12 @@ import sys import tempfile import urllib.request -from sh import dch from sh.contrib import git from pathlib import Path from debian.debian_support import Version -from debian.changelog import Changelog +from debian.changelog import Changelog, VersionError, format_date APERTIS_CI_NAME = 'Apertis CI' APERTIS_CI_EMAIL = 'devel@lists.apertis.org' @@ -72,6 +71,24 @@ def get_current_branch_name(): branch = git('rev-parse', '-q', '--verify', '--symbolic-full-name', 'HEAD', _ok_code=[0, 1]).strip('\n') return branch.replace('refs/heads/', '', 1) +def bump_version(version: Version, changes: list, release: bool = False): + with Path("debian/changelog") as f: + ch = Changelog(f.read_text()) + if version <= ch.version: + raise VersionError("The new version must be greater than the last one.") + ch.new_block(package=ch.package, + version=version, + distributions='apertis' if release else 'UNRELEASED', + urgency='medium', + author=('%s <%s>' % (APERTIS_CI_NAME, APERTIS_CI_EMAIL)), + date=format_date()) + ch.add_change('') + for change in changes: + ch.add_change(f' * {change}') + ch.add_change('') + f.write_text(str(ch)) + git.add('-f', f) + def main(): parser = argparse.ArgumentParser(description='Merge updates from the upstream repositories to the derivative branch') parser.add_argument('--package', dest='package', type=str, help='the package name (e.g. glib2.0)') # TODO: figure this out from the repo @@ -99,14 +116,26 @@ def main(): print(e) sys.exit(1) - o = git('diff', '--exit-code', args.upstream, 'debian/changelog', _ok_code=[0,1]) + o = git('diff', '--exit-code', args.upstream, ':!debian/changelog', ':!debian/apertis/*', _ok_code=[0,1]) if o.exit_code == 1: - # debian/changelog isn't as is from debian, so someone should + # we carry some changes in addition to changelog entries + # and metadata under debian/apertis, so someone should # re-summarize the remaining changes version = upstream_version.full_version + 'co1' - dch('--no-auto-nmu', f"--newversion={version}", - 'PLEASE SUMMARIZE remaining Apertis changes') - git('commit', '--amend', '--no-edit', 'debian/changelog') + bump_version( + version, + ['PLEASE SUMMARIZE remaining Apertis changes'], + release=False + ) + else: + # no changes, but we add a suffix anyway + version = upstream_version.full_version + 'co0' + bump_version( + version, + [f'Sync from Debian {args.upstream}.'], + release=True + ) + git('commit', '--amend', '--no-edit', 'debian/changelog') if __name__ == '__main__': main()