You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

126 lines
3.3KB

  1. import sys
  2. import os
  3. import glob
  4. import json
  5. import time
  6. import build
  7. import zipfile
  8. PACKAGES_DIR = "../packages"
  9. SCREENSHOTS_DIR = "../screenshots"
  10. MANIFESTS_DIR = "manifests"
  11. RACK_USER_DIR = "~/.Rack"
  12. RACK_USER_PLUGIN_DIR = os.path.join(RACK_USER_DIR, "plugins-v1")
  13. # Update git before continuing
  14. build.system("git pull")
  15. build.system("git submodule update --init --recursive")
  16. plugin_filenames = sys.argv[1:]
  17. # Default to all repos, so all out-of-date repos are built
  18. if not plugin_filenames:
  19. plugin_filenames = glob.glob("repos/*")
  20. updated_slugs = set()
  21. for plugin_filename in plugin_filenames:
  22. (plugin_basename, plugin_ext) = os.path.splitext(plugin_filename)
  23. # Extract manifest from plugin dir or package
  24. if os.path.isdir(plugin_filename):
  25. manifest_filename = os.path.join(plugin_filename, "plugin.json")
  26. try:
  27. # Read manifest
  28. with open(manifest_filename, "r") as f:
  29. manifest = json.load(f)
  30. except IOError:
  31. # Skip plugins without plugin.json
  32. continue
  33. elif plugin_ext == ".zip":
  34. # Open ZIP
  35. z = zipfile.ZipFile(plugin_filename)
  36. manifest_filename = [f for f in z.namelist() if f.endswith("/plugin.json")][0]
  37. # Unzip manifest
  38. with z.open(manifest_filename) as f:
  39. manifest = json.load(f)
  40. else:
  41. raise Exception(f"Plugin {plugin_filename} must be a source dir or zip package")
  42. # Get library manifest
  43. slug = manifest['slug']
  44. version = manifest['version']
  45. library_manifest_filename = os.path.join(MANIFESTS_DIR, f"{slug}.json")
  46. if os.path.isdir(plugin_filename):
  47. # Check if the library manifest is up to date
  48. try:
  49. with open(library_manifest_filename, "r") as f:
  50. library_manifest = json.load(f)
  51. if library_manifest and version == library_manifest['version']:
  52. continue
  53. except IOError:
  54. pass
  55. # Build repo
  56. print()
  57. print(f"Building {slug}")
  58. try:
  59. build.delete_stage()
  60. build.build(plugin_filename)
  61. build.system(f"cp -vi stage/* '{PACKAGES_DIR}'")
  62. build.system(f"cp -vi stage/* '{RACK_USER_PLUGIN_DIR}'")
  63. except Exception as e:
  64. print(e)
  65. print(f"{slug} build failed")
  66. input()
  67. continue
  68. finally:
  69. build.delete_stage()
  70. # Open plugin issue thread
  71. os.system(f"qutebrowser 'https://github.com/VCVRack/library/issues?utf8=%E2%9C%93&q=is%3Aissue+is%3Aopen+in%3Atitle+{slug}' &")
  72. elif plugin_ext == ".zip":
  73. # Review manifest for errors
  74. print(json.dumps(manifest, indent=" "))
  75. print("Press enter to approve manifest")
  76. input()
  77. # Copy package
  78. package_dest = os.path.join(PACKAGES_DIR, os.path.basename(plugin_filename))
  79. build.system(f"cp '{plugin_filename}' '{package_dest}'")
  80. build.system(f"touch '{package_dest}'")
  81. # Copy manifest
  82. with open(library_manifest_filename, "w") as f:
  83. json.dump(manifest, f, indent=" ")
  84. # Delete screenshot cache
  85. screenshots_dir = os.path.join(SCREENSHOTS_DIR, slug)
  86. build.system(f"rm -rf '{screenshots_dir}'")
  87. updated_slugs.add(slug)
  88. if not updated_slugs:
  89. print("Nothing to build")
  90. exit(0)
  91. print("Press enter to upload packages and push library repo")
  92. input()
  93. # Upload packages
  94. build.system("cd ../packages && make upload")
  95. # Commit repository
  96. build.system("git add manifests")
  97. built_slugs_str = ", ".join(updated_slugs)
  98. build.system(f"git commit -m 'Update manifest for {built_slugs_str}'")
  99. build.system("git push")
  100. print()
  101. print(f"Built {built_slugs_str}")
  102. print("Remember to generate and upload screenshots")