update_changelog.py 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. #!/usr/bin/env python
  2. # This Source Code Form is subject to the terms of the Mozilla Public
  3. # License, v. 2.0. If a copy of the MPL was not distributed with this
  4. # file, You can obtain one at http://mozilla.org/MPL/2.0/.
  5. import subprocess
  6. import os
  7. import re
  8. from email.utils import formatdate
  9. git_describe_version = subprocess.check_output(["git", "describe", "--tags", "--dirty", "--match", "v*"]).decode('utf-8').strip()
  10. # v1.2
  11. # v1.2.3
  12. # v1.2.3-rc1
  13. # v1.2.3-rc1-dirty
  14. # v1.2.3-5-g4538abcd
  15. # v1.2.3-5-g4538abcd-dirty
  16. # git_describe_version = "v1.2.3"
  17. m = re.match(r"^v([0-9]+)(\.[0-9]+)?(\.[0-9]+)?(-(.*)+)?$", git_describe_version)
  18. version_major = m.group(1) if m.group(1) is not None else "0"
  19. version_minor = m.group(2).replace(".", "") if m.group(2) is not None else "0"
  20. version_patch = m.group(3).replace(".", "") if m.group(3) is not None else "0"
  21. version_label = m.group(4) if m.group(4) is not None else ""
  22. #print("major {} minor {} patch {} label {}".format(version_major, version_minor, version_patch, version_label))
  23. debian_distribution = "unstable"
  24. if version_label is not "":
  25. debian_distribution = "UNRELEASED"
  26. dirpath = os.path.dirname(os.path.realpath(__file__))
  27. changelog_file = os.path.join(dirpath, "changelog")
  28. # remove leading 'v'
  29. changelog_version = git_describe_version[1:] if git_describe_version[0] == 'v' else git_describe_version
  30. with open(changelog_file, 'r') as original: data = original.read()
  31. with open(changelog_file, 'w') as modified:
  32. new_entry = """open62541 ({version}) {distribution}; urgency=medium
  33. * Full changelog is available here: https://github.com/open62541/open62541/blob/master/CHANGELOG
  34. -- open62541 Team <open62541-core@googlegroups.com> {time}
  35. """.format(version=changelog_version, time=formatdate(), distribution = debian_distribution)
  36. modified.write(new_entry + "\n" + data)