parameters.cake 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. public class Parameters
  2. {
  3. public string Platform { get; private set; }
  4. public string Configuration { get; private set; }
  5. public bool SkipTests { get; private set; }
  6. public string MainRepo { get; private set; }
  7. public string MasterBranch { get; private set; }
  8. public string AssemblyInfoPath { 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 string XBuildSolution { get; private set; }
  13. public bool IsPlatformAnyCPU { get; private set; }
  14. public bool IsPlatformX86 { get; private set; }
  15. public bool IsPlatformX64 { get; private set; }
  16. public bool IsLocalBuild { get; private set; }
  17. public bool IsRunningOnUnix { get; private set; }
  18. public bool IsRunningOnWindows { get; private set; }
  19. public bool IsRunningOnAppVeyor { get; private set; }
  20. public bool IsPullRequest { get; private set; }
  21. public bool IsMainRepo { get; private set; }
  22. public bool IsMasterBranch { get; private set; }
  23. public bool IsTagged { get; private set; }
  24. public bool IsReleasable { get; private set; }
  25. public bool IsMyGetRelease { get; private set; }
  26. public bool IsNuGetRelease { get; private set; }
  27. public string Version { get; private set; }
  28. public DirectoryPath ArtifactsDir { get; private set; }
  29. public DirectoryPath NugetRoot { get; private set; }
  30. public DirectoryPath ZipRoot { get; private set; }
  31. public DirectoryPath BinRoot { get; private set; }
  32. public string DirSuffix { get; private set; }
  33. public string DirSuffixIOS { get; private set; }
  34. public DirectoryPathCollection BuildDirs { get; private set; }
  35. public string FileZipSuffix { get; private set; }
  36. public FilePath ZipCoreArtifacts { get; private set; }
  37. public DirectoryPath ZipSourceControlCatalogDesktopDirs { get; private set; }
  38. public FilePath ZipTargetControlCatalogDesktopDirs { get; private set; }
  39. public Parameters(ICakeContext context)
  40. {
  41. var buildSystem = context.BuildSystem();
  42. // ARGUMENTS
  43. Platform = context.Argument("platform", "Any CPU");
  44. Configuration = context.Argument("configuration", "Release");
  45. SkipTests = context.HasArgument("skip-tests");
  46. // CONFIGURATION
  47. MainRepo = "AvaloniaUI/Avalonia";
  48. MasterBranch = "master";
  49. AssemblyInfoPath = context.File("./src/Shared/SharedAssemblyInfo.cs");
  50. ReleasePlatform = "Any CPU";
  51. ReleaseConfiguration = "Release";
  52. MSBuildSolution = "./Avalonia.sln";
  53. XBuildSolution = "./Avalonia.XBuild.sln";
  54. // PARAMETERS
  55. IsPlatformAnyCPU = StringComparer.OrdinalIgnoreCase.Equals(Platform, "Any CPU");
  56. IsPlatformX86 = StringComparer.OrdinalIgnoreCase.Equals(Platform, "x86");
  57. IsPlatformX64 = StringComparer.OrdinalIgnoreCase.Equals(Platform, "x64");
  58. IsLocalBuild = buildSystem.IsLocalBuild;
  59. IsRunningOnUnix = context.IsRunningOnUnix();
  60. IsRunningOnWindows = context.IsRunningOnWindows();
  61. IsRunningOnAppVeyor = buildSystem.AppVeyor.IsRunningOnAppVeyor;
  62. IsPullRequest = buildSystem.AppVeyor.Environment.PullRequest.IsPullRequest;
  63. IsMainRepo = StringComparer.OrdinalIgnoreCase.Equals(MainRepo, buildSystem.AppVeyor.Environment.Repository.Name);
  64. IsMasterBranch = StringComparer.OrdinalIgnoreCase.Equals(MasterBranch, buildSystem.AppVeyor.Environment.Repository.Branch);
  65. IsTagged = buildSystem.AppVeyor.Environment.Repository.Tag.IsTag
  66. && !string.IsNullOrWhiteSpace(buildSystem.AppVeyor.Environment.Repository.Tag.Name);
  67. IsReleasable = StringComparer.OrdinalIgnoreCase.Equals(ReleasePlatform, Platform)
  68. && StringComparer.OrdinalIgnoreCase.Equals(ReleaseConfiguration, Configuration);
  69. IsMyGetRelease = !IsTagged && IsReleasable;
  70. // VERSION
  71. Version = context.Argument("force-nuget-version", context.ParseAssemblyInfo(AssemblyInfoPath).AssemblyVersion);
  72. if (IsRunningOnAppVeyor)
  73. {
  74. string tagVersion = null;
  75. if (IsTagged)
  76. {
  77. var tag = buildSystem.AppVeyor.Environment.Repository.Tag.Name;
  78. var nugetReleasePrefix = "nuget-release-";
  79. IsNuGetRelease = IsTagged && IsReleasable && tag.StartsWith(nugetReleasePrefix);
  80. if(IsNuGetRelease)
  81. tagVersion = tag.Substring(nugetReleasePrefix.Length);
  82. }
  83. if(tagVersion != null)
  84. {
  85. Version = tagVersion;
  86. }
  87. else
  88. {
  89. // Use AssemblyVersion with Build as version
  90. Version += "-build" + context.EnvironmentVariable("APPVEYOR_BUILD_NUMBER") + "-beta";
  91. }
  92. }
  93. // DIRECTORIES
  94. ArtifactsDir = (DirectoryPath)context.Directory("./artifacts");
  95. NugetRoot = ArtifactsDir.Combine("nuget");
  96. ZipRoot = ArtifactsDir.Combine("zip");
  97. BinRoot = ArtifactsDir.Combine("bin");
  98. BuildDirs = context.GetDirectories("**/bin") + context.GetDirectories("**/obj");
  99. DirSuffix = Configuration;
  100. DirSuffixIOS = "iPhone" + "/" + Configuration;
  101. FileZipSuffix = Version + ".zip";
  102. ZipCoreArtifacts = ZipRoot.CombineWithFilePath("Avalonia-" + FileZipSuffix);
  103. ZipSourceControlCatalogDesktopDirs = (DirectoryPath)context.Directory("./samples/ControlCatalog.Desktop/bin/" + DirSuffix + "/net461");
  104. ZipTargetControlCatalogDesktopDirs = ZipRoot.CombineWithFilePath("ControlCatalog.Desktop-" + FileZipSuffix);
  105. }
  106. }