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.

158 lines
4.3KB

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