docs: def publish_application(template, sar_client=None):
      """
      Create a new application or new application version in SAR.
  
      :param template: Content of a packaged YAML or JSON SAM template
      :type template: str_or_dict
      :param sar_client: The boto3 client used to access SAR
      :type sar_client: boto3.client
      :return: Dictionary containing application id, actions taken, and updated details
      :rtype: dict
      :raises ValueError
      """
      if not template:
          raise ValueError('Require SAM template to publish the application')
  
      if not sar_client:
          sar_client = boto3.client('serverlessrepo')
  
      template_dict = _get_template_dict(template)
      app_metadata = get_app_metadata(template_dict)
      stripped_template_dict = strip_app_metadata(template_dict)
      stripped_template = yaml_dump(stripped_template_dict)
      try:
          request = _create_application_request(app_metadata, stripped_template)
          response = sar_client.create_application(**request)
          application_id = response['ApplicationId']
          actions = [CREATE_APPLICATION]
      except ClientError as e:
          if not _is_conflict_exception(e):
              raise _wrap_client_error(e)
  
          # Update the application if it already exists
          error_message = e.response['Error']['Message']
          application_id = parse_application_id(error_message)
          try:
              request = _update_application_request(app_metadata, application_id)
              sar_client.update_application(**request)
              actions = [UPDATE_APPLICATION]
          except ClientError as e:
              raise _wrap_client_error(e)
  
          # Create application version if semantic version is specified
          if app_metadata.semantic_version:
              try:
                  request = _create_application_version_request(app_metadata, application_id, stripped_template)
                  sar_client.create_application_version(**request)
                  actions.append(CREATE_APPLICATION_VERSION)
              except ClientError as e:
                  if not _is_conflict_exception(e):
                      raise _wrap_client_error(e)
  
      return {
          'application_id': application_id,
          'actions': actions,
          'details': _get_publish_details(actions, app_metadata.template_dict)
      }