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.

125 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. library_manifest_filename = os.path.join(MANIFESTS_DIR, f"{slug}.json")
  45. if os.path.isdir(plugin_filename):
  46. # Check if the library manifest is up to date
  47. try:
  48. with open(library_manifest_filename, "r") as f:
  49. library_manifest = json.load(f)
  50. if library_manifest and manifest['version'] == library_manifest['version']:
  51. continue
  52. except IOError:
  53. pass
  54. # Build repo
  55. print()
  56. print(f"Building {slug}")
  57. try:
  58. build.delete_stage()
  59. build.build(plugin_filename)
  60. build.system(f"cp -vi stage/* '{PACKAGES_DIR}'")
  61. build.system(f"cp -vi stage/* '{RACK_USER_PLUGIN_DIR}'")
  62. except Exception as e:
  63. print(e)
  64. print(f"{slug} build failed")
  65. input()
  66. continue
  67. finally:
  68. build.delete_stage()
  69. # Open plugin issue thread
  70. os.system(f"qutebrowser 'https://github.com/VCVRack/library/issues?utf8=%E2%9C%93&q=is%3Aissue+is%3Aopen+in%3Atitle+{slug}' &")
  71. elif plugin_ext == ".zip":
  72. # Review manifest for errors
  73. print(json.dumps(manifest, indent=" "))
  74. print("Press enter to approve manifest")
  75. input()
  76. # Copy package
  77. package_dest = os.path.join(PACKAGES_DIR, os.path.basename(plugin_filename))
  78. build.system(f"cp '{plugin_filename}' '{package_dest}'")
  79. build.system(f"touch '{package_dest}'")
  80. # Copy manifest
  81. with open(library_manifest_filename, "w") as f:
  82. json.dump(manifest, f, indent=" ")
  83. # Delete screenshot cache
  84. screenshots_dir = os.path.join(SCREENSHOTS_DIR, slug)
  85. build.system(f"rm -rf '{screenshots_dir}'")
  86. updated_slugs.add(slug)
  87. if not updated_slugs:
  88. print("Nothing to build")
  89. exit(0)
  90. print("Press enter to upload packages and push library repo")
  91. input()
  92. # Upload packages
  93. build.system("cd ../packages && make upload")
  94. # Commit repository
  95. build.system("git add manifests")
  96. built_slugs_str = ", ".join(updated_slugs)
  97. build.system(f"git commit -m 'Update manifest for {built_slugs_str}'")
  98. build.system("git push")
  99. print()
  100. print(f"Built {built_slugs_str}")
  101. print("Remember to generate and upload screenshots")