Solution:
// Create a new Version manager instance
var manager = VersionManager.GetInstance(tree);
// Check out the document
if (!node.IsCheckedOut)
{
manager.CheckOut(node);
}
// Save the changes
DocumentHelper.UpdateDocument(node, tree);
// Check in the document
if (node.IsCheckedOut)
{
manager.CheckIn(node, null, null);
}
var workflowManager = WorkflowManager.GetInstance(tree);
var workflow = workflowManager.GetNodeWorkflow(node);
// apply latest version
manager.ApplyLatestVersion(node);
// Check if the document uses workflow
if (workflow != null)
{
// Publish the document
workflowManager.PublishDocument(node, string.Format("Automatically published {0} page.", node.DocumentName));
}