269 lines
No EOL
10 KiB
C#
269 lines
No EOL
10 KiB
C#
using System;
|
|
using System.Linq;
|
|
using BetaVersionLauncher;
|
|
using TeaBox.Code;
|
|
using TeaBox.Macros;
|
|
using TeaBox.Signiant;
|
|
using TeaBox.Jira;
|
|
using Path = System.IO.Path;
|
|
|
|
namespace TeaBox.BuildVersion
|
|
{
|
|
public class PublishVersionCommand : ITask
|
|
{
|
|
protected internal IExecutionContext Context { get; set; }
|
|
protected internal Platform Platform { get; set; }
|
|
protected internal string Branch { get; set; }
|
|
protected internal Region Region { get; set; }
|
|
protected internal DevEnvBuildVariant Variant { get; set; }
|
|
protected internal string DataChangelist { get; set; }
|
|
protected internal string CodeChangelist { get; set; }
|
|
protected internal GameOnlineEnvironment GameOnlineEnvironment { get; set; }
|
|
protected internal string VersionName { get; set; }
|
|
protected internal bool Restricted { get; set; }
|
|
protected string SourcePath => GameConstants.GetLocalWorkingPath(Platform, DataChangelist);
|
|
protected internal string PlatformName => new EngineExecutable(Platform, Variant).DeliveredPlatformName;
|
|
protected internal Studio StudiosToShareVersionWith { get; set; }
|
|
protected internal string PackagePublishedPath => Path.Combine(Version.GetPackagePublishingPath(GameOnlineEnvironment, VersionName, Region, Variant, PlatformName, Restricted), "Package");
|
|
|
|
public void Execute(IExecutionContext context)
|
|
{
|
|
if (ThisVersionAlreadyExists())
|
|
return;
|
|
|
|
PublishPackage();
|
|
SharePackage();
|
|
PublishLoosesFiles();
|
|
AddVersionToJira();
|
|
}
|
|
|
|
protected virtual void PublishPackage()
|
|
{
|
|
Context.AddStep("Publishing package ...", stepcontext =>
|
|
{
|
|
PublishPackageImpl();
|
|
});
|
|
}
|
|
|
|
protected virtual void PublishPackageImpl()
|
|
{
|
|
var sourcePath = Path.Combine(SourcePath, "Output");
|
|
var destinationPath = PackagePublishedPath;
|
|
|
|
if (CanAccessFolder(sourcePath))
|
|
{
|
|
Context.LogWarning($"Can't access {SourcePath}");
|
|
}
|
|
|
|
try
|
|
{
|
|
Context.LogMessage($"Publish package from {sourcePath} to {destinationPath}");
|
|
RoboCopy.ReplicateDirectory(sourcePath, destinationPath, Context);
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
Console.WriteLine(e);
|
|
var localBackupPath = Path.Combine($@"d:\backup", Region.ToString(), Variant.ToString(), VersionName, "Package");
|
|
Context.LogWarning($"Backup package to {localBackupPath}");
|
|
RoboCopy.ReplicateDirectory(sourcePath, localBackupPath, Context);
|
|
}
|
|
}
|
|
|
|
protected virtual void PublishLoosesFiles()
|
|
{
|
|
Context.AddStep("Publishing looses ...", stepcontext =>
|
|
{
|
|
PublishLoosesFilesImpl();
|
|
});
|
|
}
|
|
|
|
protected virtual void PublishLoosesFilesImpl()
|
|
{
|
|
// Only publish looses for Final versions
|
|
if (Variant == DevEnvBuildVariant.Release || Variant == DevEnvBuildVariant.Debug)
|
|
{
|
|
return;
|
|
}
|
|
|
|
var destinationPath = Path.Combine(Version.GetLoosesPublishingPath(Region, VersionName, GameOnlineEnvironment, PlatformName, Restricted), "Looses");
|
|
|
|
// Looases are not published for scoring tools
|
|
if (destinationPath.ToLower().Contains("datascoring"))
|
|
{
|
|
return;
|
|
}
|
|
|
|
// Excluding Output folder content from the Looses publishing
|
|
Func<string, bool> excludeFolders = file =>
|
|
{
|
|
var patterns = new[] { "Output/", "subOutput/" };
|
|
return !patterns.Any(file.Replace('\\', '/').Contains);
|
|
};
|
|
|
|
if (CanAccessFolder(SourcePath))
|
|
{
|
|
Context.LogWarning($"Can't access {SourcePath}");
|
|
}
|
|
|
|
try
|
|
{
|
|
Context.LogMessage($"Publish package from {SourcePath} to {destinationPath}");
|
|
RoboCopy.ReplicateDirectory(SourcePath, destinationPath, Context, @where: excludeFolders);
|
|
}
|
|
// try to catch any copy error
|
|
catch (Exception e)
|
|
{
|
|
Console.WriteLine(e);
|
|
var localBackupPath = Path.Combine($@"d:\backup", Region.ToString(), Variant.ToString(), VersionName, "Looses");
|
|
Context.LogWarning($"Backup package to {localBackupPath}");
|
|
RoboCopy.ReplicateDirectory(SourcePath, localBackupPath, Context);
|
|
}
|
|
}
|
|
|
|
protected virtual void SharePackage()
|
|
{
|
|
Context.AddStep("Sharing package with other sites ...", stepcontext =>
|
|
{
|
|
SharePackageImpl();
|
|
});
|
|
}
|
|
|
|
protected virtual void AddVersionToJira()
|
|
{
|
|
Context.AddStep("Adding version to Jira releases", stepcontext =>
|
|
{
|
|
AddJiraVersionMacros.AddVersionIntoJira(Context, Platform, $"{UAFConstants.GameName} Version", $"{VersionName}", $"JD{UAFConstants.JdNumericVersion}", "11751"); //11751 = projectId on jira for JD2021
|
|
});
|
|
}
|
|
|
|
protected virtual void SharePackageImpl()
|
|
{
|
|
// Only sharing with other studios, not with the one where the machine executing the macro is located
|
|
foreach (var studio in StudiosToShareVersionWith.FlagsDefined().Where(x => x != CurrentStudio.Value))
|
|
{
|
|
// Check if current studio is a valid studio value
|
|
if (!Enum.IsDefined(typeof(Studio), studio) || studio == Studio.Unknown)
|
|
{
|
|
Context.LogWarning($"Studio <{studio}> is not a valid value for a studio!");
|
|
break;
|
|
}
|
|
|
|
var initiateTransfer = true;
|
|
var platformsExcludedFromSharing = "";
|
|
var variantsExcludedFromSharing = "";
|
|
var targetStudio = studio.SigniantName();
|
|
|
|
Context.LogMessage($"Current studio to share the version with, is : {studio}");
|
|
Context.LogMessage($"Current game platform is {Platform}");
|
|
|
|
switch (studio)
|
|
{
|
|
case Studio.Montreal:
|
|
platformsExcludedFromSharing = "Durango, Orbis, GGP, NX";
|
|
break;
|
|
|
|
case Studio.Pune:
|
|
targetStudio = Variant == DevEnvBuildVariant.Release ? "Pune" : "Pune_JD";
|
|
break;
|
|
|
|
case Studio.Bucharest:
|
|
platformsExcludedFromSharing = "";
|
|
break;
|
|
|
|
case Studio.Shanghai:
|
|
platformsExcludedFromSharing = "GGP";
|
|
break;
|
|
|
|
default:
|
|
platformsExcludedFromSharing = string.Empty;
|
|
break;
|
|
}
|
|
|
|
foreach (var variant in variantsExcludedFromSharing.Split(','))
|
|
{
|
|
if (!string.Equals(Variant.ToString(), variant, StringComparison.CurrentCultureIgnoreCase))
|
|
{
|
|
continue;
|
|
}
|
|
|
|
Context.LogMessage($"Variant {variant} is ignored");
|
|
initiateTransfer = false;
|
|
}
|
|
|
|
foreach (var platform in platformsExcludedFromSharing.Split(','))
|
|
{
|
|
if (!string.Equals(Platform.ToString().Trim(), platform.Trim(), StringComparison.CurrentCultureIgnoreCase))
|
|
{
|
|
continue;
|
|
}
|
|
|
|
Context.LogMessage($"Platform {platform} is ignored");
|
|
initiateTransfer = false;
|
|
}
|
|
|
|
if (!initiateTransfer)
|
|
{
|
|
Context.LogWarning($"Transfer is cancelled for this studio ({studio})");
|
|
continue;
|
|
}
|
|
|
|
Context.LogMessage($"Sharing package with {studio} using agent {targetStudio}");
|
|
|
|
if (!Directory.Exists(PackagePublishedPath))
|
|
{
|
|
throw new MacroException($"Cannot find folder {PackagePublishedPath}");
|
|
}
|
|
|
|
var fromPath = PackagePublishedPath;
|
|
|
|
var toPath = Path.Combine(studio.PackagePublishedRoot(Restricted), PlatformName, Branch == "main" ? "Full_version" : Branch, VersionName,
|
|
Region.ToString(), Variant.ToString());
|
|
|
|
if (fromPath.ToLower().Contains("datascoring"))
|
|
{
|
|
const string dataScoringPath = @"\\ubisoft.org\projects\JD2018_PUN\Score_Design\JD2020Project\JD2020 Builds";
|
|
toPath = Path.Combine(dataScoringPath, VersionName,
|
|
Region.ToString(), Variant.ToString());
|
|
}
|
|
|
|
Context.LogMessage($"From studio {CurrentStudio.Value.SigniantName()} to studio {studio.SigniantName()}");
|
|
Context.LogMessage($"From path {fromPath} to path {toPath}");
|
|
SigniantMacros.ReplicateNasDirectory(Context, @from: fromPath, to: toPath, sourceStudio: CurrentStudio.Value.SigniantName(),
|
|
targetStudio: targetStudio, transferTitle: $"{UAFConstants.GameName} Transfer", block: false);
|
|
}
|
|
}
|
|
|
|
private bool ThisVersionAlreadyExists()
|
|
{
|
|
// Publish only if the same version is not already published on network
|
|
if (!System.IO.Directory.Exists(PackagePublishedPath))
|
|
{
|
|
return false;
|
|
}
|
|
|
|
Context.LogError($"Folder {PackagePublishedPath} already exists, publish aborted!");
|
|
return true;
|
|
}
|
|
|
|
public virtual bool CanAccessFolder(string path)
|
|
{
|
|
bool exist;
|
|
try
|
|
{
|
|
System.IO.Directory.GetAccessControl(path);
|
|
exist = true;
|
|
}
|
|
catch (UnauthorizedAccessException)
|
|
{
|
|
exist = true;
|
|
}
|
|
catch
|
|
{
|
|
exist = false;
|
|
}
|
|
|
|
return exist;
|
|
}
|
|
|
|
}
|
|
} |