Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.
 
 
 
 
 
 

121 řádky
3.7 KiB

  1. import sys
  2. import os
  3. import json
  4. import subprocess
  5. root_path = os.path.dirname(os.path.dirname(os.path.realpath(__file__)))
  6. def usage():
  7. script_name = os.path.basename(__file__)
  8. print(f"Example: python {script_name} lesspass-web-extension --patch")
  9. print(f"Example: python {script_name} lesspass-site --patch")
  10. sys.exit(1)
  11. def print_packages_version(packages):
  12. len_col = len(max(packages, key=packages.get)) + 2
  13. for package in packages:
  14. with open(os.path.join(root_path, "packages", package, "package.json")) as f:
  15. package_json = json.load(f)
  16. printable_package_name = f"{package:{len_col}s}"
  17. version = package_json["version"]
  18. print(f"|{printable_package_name}|{version.rjust(9, ' ')}|")
  19. def get_package_version(package):
  20. with open(os.path.join(root_path, "packages", package, "package.json")) as f:
  21. package_json = json.load(f)
  22. return package_json["version"]
  23. def set_version(file_path, version):
  24. with open(file_path) as f:
  25. package_json = json.load(f)
  26. package_json["version"] = version
  27. with open(file_path, "w", encoding="utf-8") as f:
  28. json.dump(package_json, f, ensure_ascii=False, indent=2)
  29. if __name__ == "__main__":
  30. if len(sys.argv) != 3:
  31. usage()
  32. has_error = False
  33. package = sys.argv[1]
  34. packages = {
  35. "lesspass": "lesspass",
  36. "lesspass-crypto": "crypto",
  37. "lesspass-entropy": "entropy",
  38. "lesspass-fingerprint": "fingerprint",
  39. "lesspass-pure": "pure",
  40. "lesspass-render-password": "render-password",
  41. "lesspass-site": "site",
  42. "lesspass-web-extension": "web-extension",
  43. }
  44. if package not in packages:
  45. print(f"Error: {package} is invalid, should be one of:")
  46. packages_joined = "\n ".join(packages.keys())
  47. print(f" {packages_joined}")
  48. has_error = True
  49. bump = sys.argv[2]
  50. bump = bump.replace("-", "")
  51. valid_bumps = ["major", "minor", "patch"]
  52. if bump not in valid_bumps:
  53. valid_bump_joined = ",".join(valid_bumps)
  54. print(f"Error: {bump} is invalid, should be one of {valid_bump_joined}")
  55. has_error = True
  56. if has_error:
  57. usage()
  58. package_short_name = packages[package]
  59. subprocess.run(
  60. [
  61. "yarn",
  62. "workspace",
  63. f"{package}",
  64. "version",
  65. f"--{bump}",
  66. "--no-git-tag-version",
  67. "--no-commit-hooks",
  68. ]
  69. )
  70. version = get_package_version(package)
  71. if package == "lesspass-web-extension":
  72. subprocess.run(
  73. [
  74. "yarn",
  75. "workspace",
  76. "lesspass-web-extension-legacy",
  77. "version",
  78. f"--{bump}",
  79. "--no-git-tag-version",
  80. "--no-commit-hooks",
  81. ]
  82. )
  83. set_version(
  84. os.path.join(root_path, "packages", package, "extension", "manifest.json"),
  85. version,
  86. )
  87. set_version(
  88. os.path.join(
  89. root_path,
  90. "packages",
  91. "lesspass-web-extension-legacy",
  92. "extension",
  93. "manifest.json",
  94. ),
  95. version,
  96. )
  97. subprocess.run(["yarn", "workspace", "lesspass-crypto", "build"])
  98. subprocess.run(["yarn", "workspace", "lesspass-pure", "build"])
  99. subprocess.run(["yarn", "workspace", "lesspass-web-extension", "build"])
  100. subprocess.run(["yarn", "workspace", "lesspass-web-extension-legacy", "build"])
  101. subprocess.run(["git", "add", "."])
  102. tag = f"{package_short_name}-v{version}"
  103. subprocess.run(["git", "commit", "-a", "-m", tag])
  104. subprocess.run(["git", "tag", tag])