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.

152 lines
4.1KB

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