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.
 
 
 

58 regels
2.4 KiB

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