docs: def _build_global_workflow(json_spec, args):
      """
      Creates a workflow in a temporary project for each enabled region
      and builds a global workflow on the platform based on these workflows.
      """
      # First determine in which regions the global workflow needs to be available
      enabled_regions = _get_validated_enabled_regions(json_spec, args.region)
  
      # Verify all the stages are also enabled in these regions
      # TODO: Add support for dx building multi-region global workflows with applets
      _assert_executable_regions_match(enabled_regions, json_spec)
  
      workflows_by_region, projects_by_region = {}, {}  # IDs by region
      try:
          # prepare "regionalOptions" field for the globalworkflow/new input
          workflows_by_region, projects_by_region = \
              _build_underlying_workflows(enabled_regions, json_spec, args)
          regional_options = {}
          for region, workflow_id in workflows_by_region.items():
              regional_options[region] = {'workflow': workflow_id}
          json_spec.update({'regionalOptions': regional_options})
  
          # leave only fields that are actually used to build the workflow
          gwf_provided_keys = GLOBALWF_SUPPORTED_KEYS.intersection(set(json_spec.keys()))
          gwf_final_json = dict((k, v) for k, v in json_spec.items() if k in gwf_provided_keys)
  
          # we don't want to print the whole documentation to the screen so we'll remove these fields
          print_spec = copy.deepcopy(gwf_final_json)
          if "description" in gwf_final_json:
              del print_spec["description"]
          if "developerNotes" in gwf_final_json:
              del print_spec["developerNotes"]
          logger.info("Will create global workflow with spec: {}".format(json.dumps(print_spec)))
  
          # Create a new global workflow version on the platform
          global_workflow_id = dxpy.api.global_workflow_new(gwf_final_json)["id"]
  
          logger.info("Uploaded global workflow {n}/{v} successfully".format(n=gwf_final_json["name"],
                                                                             v=gwf_final_json["version"]))
          logger.info("You can publish this workflow with:")
          logger.info("  dx publish {n}/{v}".format(n=gwf_final_json["name"],
                                                    v=gwf_final_json["version"]))
      finally:
          # Clean up
          if projects_by_region:
              dxpy.executable_builder.delete_temporary_projects(projects_by_region.values())
  
      # Set any additional fields on the created workflow
      try:
          _set_categories_on_workflow(global_workflow_id, gwf_final_json.get("categories", []))
      except:
          logger.warn(
              "The workflow {n}/{v} was created but setting categories failed".format(n=gwf_final_json['name'],
                                                                                      v=gwf_final_json['version']))
          raise
  
      return global_workflow_id