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.

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