cut_release.py 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. # Copyright Materialize, Inc. and contributors. All rights reserved.
  2. #
  3. # Use of this software is governed by the Business Source License
  4. # included in the LICENSE file at the root of this repository.
  5. #
  6. # As of the Change Date specified in that file, in accordance with
  7. # the Business Source License, use of this software will be governed
  8. # by the Apache License, Version 2.0.
  9. """Cut a new release and push the tag to the upstream Materialize repository."""
  10. import argparse
  11. import re
  12. import sys
  13. from semver.version import Version
  14. from materialize import MZ_ROOT, spawn
  15. from materialize.git import checkout, get_branch_name, tag_annotated
  16. def parse_version(version: str) -> Version:
  17. return Version.parse(re.sub(r"^v", "", version))
  18. def main():
  19. parser = argparse.ArgumentParser(
  20. prog="cut_release",
  21. description="Creates a new release for Materialize.",
  22. )
  23. parser.add_argument(
  24. "--sha",
  25. help="Chosen SHA of the release",
  26. type=str,
  27. required=True,
  28. )
  29. parser.add_argument(
  30. "--version",
  31. help="Version of release",
  32. type=parse_version,
  33. required=True,
  34. )
  35. parser.add_argument(
  36. "--remote",
  37. help="Git remote name of Materialize repo",
  38. type=str,
  39. required=True,
  40. )
  41. args = parser.parse_args()
  42. version = f"v{args.version}"
  43. current_branch = get_branch_name()
  44. try:
  45. print(f"Checking out SHA {args.sha}")
  46. checkout(args.sha)
  47. print(f"Bumping version to {version}")
  48. spawn.runv([MZ_ROOT / "bin" / "bump-version", version])
  49. print("Tagging version")
  50. tag_annotated(version)
  51. print("Pushing tag to Materialize repo")
  52. spawn.runv(["git", "push", args.remote, version])
  53. finally:
  54. # The caller may have started in a detached HEAD state.
  55. if current_branch:
  56. checkout(current_branch)
  57. if __name__ == "__main__":
  58. sys.exit(main())