utilities.cake 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. #tool "nuget:?package=GitVersion.CommandLine"
  2. #addin "nuget:?package=YamlDotNet"
  3. public class ContextInfo
  4. {
  5. public string NugetVersion { get; set; }
  6. public string AssemblyVersion { get; set; }
  7. public GitVersion Git { get; set; }
  8. public string BuildVersion
  9. {
  10. get { return NugetVersion + "-" + Git.Sha; }
  11. }
  12. }
  13. ContextInfo _versionContext = null;
  14. public ContextInfo VersionContext
  15. {
  16. get
  17. {
  18. if(_versionContext == null)
  19. throw new Exception("The current context has not been read yet. Call ReadContext(FilePath) before accessing the property.");
  20. return _versionContext;
  21. }
  22. }
  23. public ContextInfo ReadContext(FilePath filepath)
  24. {
  25. var deserializer = new YamlDotNet.Serialization.Deserializer();
  26. _versionContext = deserializer.Deserialize<ContextInfo>(System.IO.File.ReadAllText(filepath.ToString()));
  27. try
  28. {
  29. _versionContext.Git = GitVersion();
  30. }
  31. catch
  32. {
  33. _versionContext.Git = new Cake.Common.Tools.GitVersion.GitVersion();
  34. }
  35. return _versionContext;
  36. }
  37. public void UpdateAppVeyorBuildVersionNumber()
  38. {
  39. var increment = 0;
  40. while(increment < 10)
  41. {
  42. try
  43. {
  44. var version = VersionContext.BuildVersion;
  45. if(increment > 0)
  46. version += "-" + increment;
  47. AppVeyor.UpdateBuildVersion(version);
  48. break;
  49. }
  50. catch
  51. {
  52. increment++;
  53. }
  54. }
  55. }