diff --git a/build.cake b/build.cake index 013a5186c6e4c7a0fd3f26ccd318f20cd3db2d9a..56e829ef5c5f0b89fdb5f3ead3474e1e32ec942a 100644 --- a/build.cake +++ b/build.cake @@ -5,6 +5,9 @@ #addin nuget:https://api.nuget.org/v3/index.json?package=Cake.FileHelpers&version=3.2.1 #addin nuget:https://api.nuget.org/v3/index.json?package=Cake.Http&version=0.7.0 +using System.Net; +using System.Net.Http; + // Commandline arguments var target = Argument("target", "Default"); var configuration = Argument("configuration", "Release"); @@ -89,12 +92,12 @@ Task("Test") }); Task("GitVersion") -.WithCriteria(string.IsNullOrWhiteSpace(version)) .Does(() => { - version = GitVersion(new GitVersionSettings { - UpdateAssemblyInfo = false - }).NuGetVersionV2; - + if(string.IsNullOrWhiteSpace(version)) { + version = GitVersion(new GitVersionSettings { + UpdateAssemblyInfo = false + }).NuGetVersionV2; + } var index = version.IndexOf("-"); semanticVersion = index > 0 ? version.Substring(0, index) : version; Information($"Version: {version}, SemanticVersion: {semanticVersion}"); @@ -183,9 +186,9 @@ IEnumerable<string> redirectedStandardOutput; ); var description = ""; if(lastTag == null) { - description = $" # {semanticVersion} ({DateTime.Now.Year}-{DateTime.Now.Month}-{DateTime.Now.Day})\n\n\n"; + description = $"# {semanticVersion} ({DateTime.Now.Year}-{DateTime.Now.Month}-{DateTime.Now.Day})\n\n\n"; } else { - description = $" # [{semanticVersion}]({url}) ({DateTime.Now.Year}-{DateTime.Now.Month}-{DateTime.Now.Day})\n\n\n"; + description = $"# [{semanticVersion}]({url}) ({DateTime.Now.Year}-{DateTime.Now.Month}-{DateTime.Now.Day})\n\n\n"; } var prefixList = new Dictionary<string, List<string>>{ @@ -219,8 +222,8 @@ IEnumerable<string> redirectedStandardOutput; } description += "\n"; } - } - // create tag + } + var settings = new HttpSettings { Headers = new Dictionary<string, string> @@ -230,24 +233,17 @@ IEnumerable<string> redirectedStandardOutput; EnsureSuccessStatusCode = true, }; - settings.SetJsonRequestBody("{}"); - var responseBody = HttpPost($"https://git.rwth-aachen.de/api/v4/projects/{gitlabProjectId}/repository/tags?tag_name=v{semanticVersion}&ref=master&release_description={description}", settings); - Information("Create tag: {0}", responseBody); + // create tag + var client = new HttpClient(); + client.DefaultRequestHeaders.Add("PRIVATE-TOKEN", gitlabToken); + var result = client.PostAsync($"https://git.rwth-aachen.de/api/v4/projects/{gitlabProjectId}/repository/tags?tag_name=v{semanticVersion}&ref=master", null).Result; + Information("Create tag: {0}", result.Content.ReadAsStringAsync().Result); // create release - settings = new HttpSettings - { - Headers = new Dictionary<string, string> - { - {"PRIVATE-TOKEN", gitlabToken}, - }, - EnsureSuccessStatusCode = true, - }; - - var json = $"{{\"name\": \"v{semanticVersion}\", \"tag_name\": \"v{semanticVersion}\" \"description\": \"{description}\"}}"; - settings.SetJsonRequestBody(json); - responseBody = HttpPost($"https://git.rwth-aachen.de/api/v4/projects/{gitlabProjectId}/releases", settings); - Information("Create release: {0}", responseBody); + var json = $"{{\"name\": \"v{semanticVersion}\", \"tag_name\": \"v{semanticVersion}\", \"description\": \"{description}\"}}"; + var content = new StringContent(json, Encoding.ASCII, "application/json"); + result = client.PostAsync($"https://git.rwth-aachen.de/api/v4/projects/{gitlabProjectId}/releases", content).Result; + Information("Create release: {0}", result.Content.ReadAsStringAsync().Result); }); Task("Build")