|
1 |
| -using System.IO; |
2 |
| -using System.Reflection; |
3 |
| -using Cake.Core; |
4 |
| -using Cake.Core.Annotations; |
5 |
| -using Nerdbank.GitVersioning; |
6 |
| - |
7 |
| -namespace Cake.GitVersioning |
| 1 | +namespace Cake.GitVersioning |
8 | 2 | {
|
9 | 3 | using System;
|
10 |
| - using System.Linq; |
11 |
| - |
12 |
| - using Validation; |
| 4 | + using System.IO; |
| 5 | + using System.Reflection; |
| 6 | + using Cake.Core; |
| 7 | + using Cake.Core.Annotations; |
| 8 | + using Nerdbank.GitVersioning; |
| 9 | + using Nerdbank.GitVersioning.Commands; |
13 | 10 |
|
14 | 11 | /// <summary>
|
15 | 12 | /// Contains functionality for using Nerdbank.GitVersioning.
|
@@ -45,5 +42,46 @@ public static VersionOracle GitVersioningGetVersion(this ICakeContext cakeContex
|
45 | 42 | var gitContext = GitContext.Create(fullProjectDirectory);
|
46 | 43 | return new VersionOracle(gitContext, cloudBuild: CloudBuild.Active);
|
47 | 44 | }
|
| 45 | + |
| 46 | + /// <summary> |
| 47 | + /// Adds versioning information to the current build environment's variables. |
| 48 | + /// </summary> |
| 49 | + /// <example> |
| 50 | + /// Task("SetBuildVersion") |
| 51 | + /// .Does(() => |
| 52 | + /// { |
| 53 | + /// GitVersioningCloud() |
| 54 | + /// }); |
| 55 | + /// </example> |
| 56 | + /// <param name="cakeContext">The context.</param> |
| 57 | + /// <param name="projectDirectory">Directory to start the search for version.json.</param> |
| 58 | + /// <param name="settings">The settings to use for updating variables.</param> |
| 59 | + [CakeMethodAlias] |
| 60 | + public static void GitVersioningCloud(this ICakeContext cakeContext, string projectDirectory = ".", GitVersioningCloudSettings settings = null) |
| 61 | + { |
| 62 | + var fullProjectDirectory = (new DirectoryInfo(projectDirectory)).FullName; |
| 63 | + |
| 64 | + string directoryName = Path.GetDirectoryName(Assembly.GetAssembly(typeof(GitVersioningAliases)).Location); |
| 65 | + |
| 66 | + if (string.IsNullOrWhiteSpace(directoryName)) |
| 67 | + { |
| 68 | + throw new InvalidOperationException("Could not locate the Cake.GitVersioning library"); |
| 69 | + } |
| 70 | + |
| 71 | + settings ??= new GitVersioningCloudSettings(); |
| 72 | + |
| 73 | + var cloudCommand = new CloudCommand(Console.Out, Console.Error); |
| 74 | + cloudCommand.SetBuildVariables( |
| 75 | + fullProjectDirectory, |
| 76 | + settings.Metadata, |
| 77 | + settings.Version, |
| 78 | + settings.CISystem?.ToString(), |
| 79 | + settings.AllVariables, |
| 80 | + settings.CommonVariables, |
| 81 | + settings.AdditionalVariables, |
| 82 | + false |
| 83 | + ); |
| 84 | + } |
| 85 | + |
48 | 86 | }
|
49 | 87 | }
|
0 commit comments