Skip to content

Commit

Permalink
[Build] PackageUpdateVersionTask: always update VersionSuffix (even i…
Browse files Browse the repository at this point in the history
…f empty)
  • Loading branch information
xen2 committed Aug 2, 2018
1 parent 7746b75 commit 951335d
Showing 1 changed file with 25 additions and 18 deletions.
43 changes: 25 additions & 18 deletions sources/core/Xenko.Core.Tasks/PackageUpdateVersionTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,26 +85,27 @@ public override bool Execute()
var headCommitSha = repo.Head.Commits.FirstOrDefault()?.Sha;

// Patch NuGetVersion
if (!string.IsNullOrEmpty(SpecialVersion) || SpecialVersionGitHeight || SpecialVersionGitCommit)
var versionSuffix = SpecialVersion ?? string.Empty;
if (SpecialVersionGitHeight)
{
var versionSuffix = SpecialVersion ?? string.Empty;
if (SpecialVersionGitHeight)
{
// Compute version based on Git info
var xenkoPackageFileName = Path.GetFileName(PackageFile.ItemSpec);
var height = Nerdbank.GitVersioning.GitExtensions.GetVersionHeight(repo, xenkoPackageFileName);
versionSuffix += height.ToString("D5");
}
if (SpecialVersionGitCommit && headCommitSha != null)
{
if (versionSuffix.Length > 0)
versionSuffix += "-";
versionSuffix += "g" + headCommitSha.Substring(0, 8);
}

// Replace NuGetVersionSuffix
versionFileData = Regex.Replace(versionFileData, "NuGetVersionSuffix = (.*);", $"NuGetVersionSuffix = \"-{versionSuffix}\";");
// Compute version based on Git info
var xenkoPackageFileName = Path.GetFileName(PackageFile.ItemSpec);
var height = Nerdbank.GitVersioning.GitExtensions.GetVersionHeight(repo, xenkoPackageFileName);
versionSuffix += height.ToString("D5");
}
if (SpecialVersionGitCommit && headCommitSha != null)
{
if (versionSuffix.Length > 0)
versionSuffix += "-";
versionSuffix += "g" + headCommitSha.Substring(0, 8);
}

// Prefix with dash (if non empty)
if (versionSuffix.Length > 0)
versionSuffix = "-" + versionSuffix;

// Replace NuGetVersionSuffix
versionFileData = Regex.Replace(versionFileData, "NuGetVersionSuffix = (.*);", $"NuGetVersionSuffix = \"{versionSuffix}\";");

var assemblyInformationalSuffix = "NuGetVersionSuffix";

Expand All @@ -120,6 +121,12 @@ public override bool Execute()
// Write back new file
File.WriteAllText(GeneratedVersionFile.ItemSpec, versionFileData);

// Also patch .xkpkg (necessary when compiling editor shaders)
// TODO: Find a better way to override this without overwriting file during builds
var packageFileContent = File.ReadAllText(PackageFile.ItemSpec);
packageFileContent = Regex.Replace(packageFileContent, "^ Version: (.*)$", $" Version: {XenkoVersion.NuGetVersionSimple + versionSuffix}", RegexOptions.Multiline);
File.WriteAllText(PackageFile.ItemSpec, packageFileContent);

return true;
}
catch (Exception e)
Expand Down

0 comments on commit 951335d

Please sign in to comment.