helm_chart_version_bump.py 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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. #
  10. # helm_chart_version_bump — Bump environmentd (appVersion), orchestratord and helm-chart versions in helm chart
  11. import argparse
  12. from ruamel.yaml import YAML
  13. from materialize import MZ_ROOT
  14. from materialize.version_list import get_all_mz_versions
  15. def main() -> int:
  16. parser = argparse.ArgumentParser(
  17. prog="helm-chart-version-bump",
  18. description="Bump environmentd (appVersion), orchestratord and helm-chart versions in helm chart.",
  19. )
  20. parser.add_argument(
  21. "--helm-chart-version",
  22. type=str,
  23. help="Helm-chart version to bump to, no change if not set.",
  24. )
  25. parser.add_argument(
  26. "--bump-orchestratord-version",
  27. action="store_true",
  28. help="Bump the orchestratord version to the last released version",
  29. )
  30. parser.add_argument(
  31. "environmentd_version", type=str, help="environmentd version to bump to."
  32. )
  33. args = parser.parse_args()
  34. yaml = YAML()
  35. yaml.preserve_quotes = True
  36. yaml.width = 4096 # Don't introduce line breaks
  37. mods = [
  38. (
  39. MZ_ROOT / "misc" / "helm-charts" / "operator" / "Chart.yaml",
  40. lambda docs: docs[0].update({"appVersion": args.environmentd_version}),
  41. ),
  42. (
  43. MZ_ROOT / "misc" / "helm-charts" / "testing" / "materialize.yaml",
  44. lambda docs: docs[2]["spec"].update(
  45. {
  46. "environmentdImageRef": f"materialize/environmentd:{args.environmentd_version}"
  47. }
  48. ),
  49. ),
  50. ]
  51. if args.bump_orchestratord_version:
  52. # There are two cases that bump the version:
  53. # 1. Bump to new unreleased dev version: Use the latest released orchestratord version
  54. # 2. Bump when releasing a new version: Use the version we are currently releasing
  55. orchestratord_version = (
  56. str(get_all_mz_versions()[0])
  57. if "dev" in args.environmentd_version
  58. else args.environmentd_version
  59. )
  60. mods += [
  61. (
  62. MZ_ROOT / "misc" / "helm-charts" / "operator" / "values.yaml",
  63. lambda docs: docs[0]["operator"]["image"].update(
  64. {"tag": orchestratord_version}
  65. ),
  66. ),
  67. (
  68. MZ_ROOT
  69. / "misc"
  70. / "helm-charts"
  71. / "operator"
  72. / "tests"
  73. / "deployment_test.yaml",
  74. lambda docs: docs[0]["tests"][0]["asserts"][1]["equal"].update(
  75. {"value": f"materialize/orchestratord:{orchestratord_version}"}
  76. ),
  77. ),
  78. ]
  79. if args.helm_chart_version:
  80. mods.append(
  81. (
  82. MZ_ROOT / "misc" / "helm-charts" / "operator" / "Chart.yaml",
  83. lambda docs: docs[0].update({"version": args.helm_chart_version}),
  84. )
  85. )
  86. for file, mod in mods:
  87. with open(file) as f:
  88. docs = list(yaml.load_all(f))
  89. mod(docs)
  90. with open(file, "w") as f:
  91. yaml.dump_all(docs, f)
  92. return 0
  93. if __name__ == "__main__":
  94. main()