parameters.cake 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. using System.Xml.Linq;
  2. using System.Linq;
  3. public class Parameters
  4. {
  5. public string Configuration { get; private set; }
  6. public bool SkipTests { get; private set; }
  7. public string MainRepo { get; private set; }
  8. public string MasterBranch { get; private set; }
  9. public string ReleasePlatform { get; private set; }
  10. public string ReleaseConfiguration { get; private set; }
  11. public string MSBuildSolution { get; private set; }
  12. public bool IsLocalBuild { get; private set; }
  13. public bool IsRunningOnUnix { get; private set; }
  14. public bool IsRunningOnWindows { get; private set; }
  15. public bool IsRunningOnAppVeyor { get; private set; }
  16. public bool IsPullRequest { get; private set; }
  17. public bool IsMainRepo { get; private set; }
  18. public bool IsMasterBranch { get; private set; }
  19. public bool IsTagged { get; private set; }
  20. public bool IsReleasable { get; private set; }
  21. public bool IsMyGetRelease { get; private set; }
  22. public bool IsNuGetRelease { get; private set; }
  23. public string Version { get; private set; }
  24. public DirectoryPath ArtifactsDir { get; private set; }
  25. public DirectoryPath NugetRoot { get; private set; }
  26. public DirectoryPath ZipRoot { get; private set; }
  27. public DirectoryPath BinRoot { get; private set; }
  28. public string DirSuffix { get; private set; }
  29. public DirectoryPathCollection BuildDirs { get; private set; }
  30. public string FileZipSuffix { get; private set; }
  31. public FilePath ZipCoreArtifacts { get; private set; }
  32. public FilePath ZipNuGetArtifacts { get; private set; }
  33. public DirectoryPath ZipSourceControlCatalogDesktopDirs { get; private set; }
  34. public FilePath ZipTargetControlCatalogDesktopDirs { get; private set; }
  35. public Parameters(ICakeContext context)
  36. {
  37. var buildSystem = context.BuildSystem();
  38. // ARGUMENTS
  39. Configuration = context.Argument("configuration", "Release");
  40. SkipTests = context.HasArgument("skip-tests");
  41. // CONFIGURATION
  42. MainRepo = "AvaloniaUI/Avalonia";
  43. MasterBranch = "master";
  44. ReleaseConfiguration = "Release";
  45. MSBuildSolution = "./dirs.proj";
  46. // PARAMETERS
  47. IsLocalBuild = buildSystem.IsLocalBuild;
  48. IsRunningOnUnix = context.IsRunningOnUnix();
  49. IsRunningOnWindows = context.IsRunningOnWindows();
  50. IsRunningOnAppVeyor = buildSystem.AppVeyor.IsRunningOnAppVeyor;
  51. IsPullRequest = buildSystem.AppVeyor.Environment.PullRequest.IsPullRequest;
  52. IsMainRepo = StringComparer.OrdinalIgnoreCase.Equals(MainRepo, buildSystem.AppVeyor.Environment.Repository.Name);
  53. IsMasterBranch = StringComparer.OrdinalIgnoreCase.Equals(MasterBranch, buildSystem.AppVeyor.Environment.Repository.Branch);
  54. IsTagged = buildSystem.AppVeyor.Environment.Repository.Tag.IsTag
  55. && !string.IsNullOrWhiteSpace(buildSystem.AppVeyor.Environment.Repository.Tag.Name);
  56. IsReleasable = StringComparer.OrdinalIgnoreCase.Equals(ReleaseConfiguration, Configuration);
  57. IsMyGetRelease = !IsTagged && IsReleasable;
  58. // VERSION
  59. Version = context.Argument("force-nuget-version", GetVersion());
  60. if (IsRunningOnAppVeyor)
  61. {
  62. string tagVersion = null;
  63. if (IsTagged)
  64. {
  65. var tag = buildSystem.AppVeyor.Environment.Repository.Tag.Name;
  66. var nugetReleasePrefix = "nuget-release-";
  67. IsNuGetRelease = IsTagged && IsReleasable && tag.StartsWith(nugetReleasePrefix);
  68. if(IsNuGetRelease)
  69. tagVersion = tag.Substring(nugetReleasePrefix.Length);
  70. }
  71. if(tagVersion != null)
  72. {
  73. Version = tagVersion;
  74. }
  75. else
  76. {
  77. // Use AssemblyVersion with Build as version
  78. Version += "-build" + context.EnvironmentVariable("APPVEYOR_BUILD_NUMBER") + "-beta";
  79. }
  80. }
  81. // DIRECTORIES
  82. ArtifactsDir = (DirectoryPath)context.Directory("./artifacts");
  83. NugetRoot = ArtifactsDir.Combine("nuget");
  84. ZipRoot = ArtifactsDir.Combine("zip");
  85. BinRoot = ArtifactsDir.Combine("bin");
  86. BuildDirs = context.GetDirectories("**/bin") + context.GetDirectories("**/obj");
  87. DirSuffix = Configuration;
  88. FileZipSuffix = Version + ".zip";
  89. ZipCoreArtifacts = ZipRoot.CombineWithFilePath("Avalonia-" + FileZipSuffix);
  90. ZipNuGetArtifacts = ZipRoot.CombineWithFilePath("Avalonia-NuGet-" + FileZipSuffix);
  91. ZipSourceControlCatalogDesktopDirs = (DirectoryPath)context.Directory("./samples/ControlCatalog.Desktop/bin/" + DirSuffix + "/net461");
  92. ZipTargetControlCatalogDesktopDirs = ZipRoot.CombineWithFilePath("ControlCatalog.Desktop-" + FileZipSuffix);
  93. }
  94. private static string GetVersion()
  95. {
  96. var xdoc = XDocument.Load("./build/SharedVersion.props");
  97. return xdoc.Descendants().First(x => x.Name.LocalName == "Version").Value;
  98. }
  99. }