You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

56 lines
2.3 KiB

  1. using System;
  2. using System.Xml;
  3. using FlubuCore.Context;
  4. using FlubuCore.Scripting.Attributes;
  5. namespace BuildScript
  6. {
  7. [Reference("System.Xml.XmlDocument, System.Xml, Version=4.0.0.0, Culture=neutral, publicKeyToken=b77a5c561934e089")]
  8. public partial class BuildScript
  9. {
  10. public BuildVersion FetchBuildVersion(ITaskContext context)
  11. {
  12. var content = System.IO.File.ReadAllText("./build/version.props");
  13. XmlDocument doc = new XmlDocument();
  14. doc.LoadXml(content);
  15. var versionMajor = doc.DocumentElement.SelectSingleNode("/Project/PropertyGroup/VersionMajor").InnerText;
  16. var versionMinor = doc.DocumentElement.SelectSingleNode("/Project/PropertyGroup/VersionMinor").InnerText;
  17. var versionPatch = doc.DocumentElement.SelectSingleNode("/Project/PropertyGroup/VersionPatch").InnerText;
  18. var versionQuality = doc.DocumentElement.SelectSingleNode("/Project/PropertyGroup/VersionQuality").InnerText;
  19. versionQuality = string.IsNullOrWhiteSpace(versionQuality) ? null : versionQuality;
  20. var suffix = versionQuality;
  21. bool isCi = false;
  22. bool isTagged = false;
  23. if (!context.BuildSystems().IsLocalBuild)
  24. {
  25. isCi = true;
  26. //// todo use flubu build system when available.
  27. var appveyortag = context.GetEnvironmentVariable("APPVEYOR_REPO_TAG");
  28. bool isTagAppveyor = !string.IsNullOrEmpty(appveyortag) && appveyortag.Equals("true", StringComparison.OrdinalIgnoreCase);
  29. if ((context.BuildSystems().RunningOn == BuildSystemType.AppVeyor && isTagAppveyor) ||
  30. (context.BuildSystems().RunningOn == BuildSystemType.TravisCI && string.IsNullOrWhiteSpace(context.BuildSystems().Travis().TagName)))
  31. {
  32. isTagged = true;
  33. }
  34. }
  35. if (!isTagged)
  36. {
  37. suffix += (isCi ? "preview-" : "dv-") + CreateStamp();
  38. }
  39. suffix = string.IsNullOrWhiteSpace(suffix) ? null : suffix;
  40. var version = new BuildVersion(int.Parse(versionMajor), int.Parse(versionMinor), int.Parse(versionPatch), versionQuality);
  41. version.Suffix = suffix;
  42. return version;
  43. }
  44. }
  45. }