Não pode escolher mais do que 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 
 
 
 
 

99 linhas
3.1 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. set_version(
  73. os.path.join(root_path, "packages", package, "extension", "manifest.json"),
  74. version,
  75. )
  76. subprocess.run(["yarn", "workspace", "lesspass-crypto", "build"])
  77. subprocess.run(["yarn", "workspace", "lesspass-pure", "build"])
  78. subprocess.run(["yarn", "workspace", "lesspass-web-extension", "build"])
  79. subprocess.run(["git", "add", "."])
  80. tag = f"{package_short_name}-v{version}"
  81. subprocess.run(["git", "commit", "-a", "-m", tag])
  82. subprocess.run(["git", "tag", tag])