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.

137 lines
3.7KB

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