Skip to content
Snippets Groups Projects
Commit 5041261f authored by L. Ellenbeck's avatar L. Ellenbeck
Browse files

Build: better tag query

Build: better Information calls
parent fbe76c7b
Branches
Tags
1 merge request!21Topic/570 git version
...@@ -2,6 +2,8 @@ ...@@ -2,6 +2,8 @@
#tool nuget:?package=vswhere&version=2.8.4 #tool nuget:?package=vswhere&version=2.8.4
#tool nuget:?package=GitVersion.CommandLine&version=5.1.3 #tool nuget:?package=GitVersion.CommandLine&version=5.1.3
#addin nuget:https://api.nuget.org/v3/index.json?package=Cake.Json&version=4.0.0
#addin nuget:https://api.nuget.org/v3/index.json?package=Newtonsoft.Json&version=11.0.2
#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.FileHelpers&version=3.2.1
using System.Net; using System.Net;
...@@ -32,11 +34,11 @@ var msBuildPathX64 = (vsLatest == null) ? null : vsLatest.CombineWithFilePath(". ...@@ -32,11 +34,11 @@ var msBuildPathX64 = (vsLatest == null) ? null : vsLatest.CombineWithFilePath(".
Setup(context =>{ Setup(context =>{
nupkgDir = $"{artifactsDir.ToString()}/nupkg"; nupkgDir = $"{artifactsDir.ToString()}/nupkg";
Information($"Started at {DateTime.Now}"); Information("Started at {0}", DateTime.Now);
}); });
Teardown(context =>{ Teardown(context =>{
Information($"Finished at {DateTime.Now}"); Information("Finished at {0}", DateTime.Now);
}); });
Task("Clean") Task("Clean")
...@@ -57,7 +59,7 @@ Task("Clean") ...@@ -57,7 +59,7 @@ Task("Clean")
directoriesToClean.Add(artifactsDir); directoriesToClean.Add(artifactsDir);
foreach(var dir in directoriesToClean) { foreach(var dir in directoriesToClean) {
Information($"Cleaning {dir.ToString()}"); Information("Cleaning {0}", dir.ToString());
if (DirectoryExists(dir)) { if (DirectoryExists(dir)) {
DeleteDirectory(dir, settings); DeleteDirectory(dir, settings);
CreateDirectory(dir); CreateDirectory(dir);
...@@ -99,7 +101,7 @@ Task("GitVersion") ...@@ -99,7 +101,7 @@ Task("GitVersion")
} }
var index = version.IndexOf("-"); var index = version.IndexOf("-");
semanticVersion = index > 0 ? version.Substring(0, index) : version; semanticVersion = index > 0 ? version.Substring(0, index) : version;
Information($"Version: {version}, SemanticVersion: {semanticVersion}"); Information("Version: {0}, SemanticVersion: {1}", version, semanticVersion);
}); });
Task("UpdateAssemblyInfo") Task("UpdateAssemblyInfo")
...@@ -124,57 +126,46 @@ Task("UpdateAssemblyInfo") ...@@ -124,57 +126,46 @@ Task("UpdateAssemblyInfo")
Task("GitlabRelease") Task("GitlabRelease")
.IsDependentOn("GitVersion") .IsDependentOn("GitVersion")
.Does(() => { .Does(() => {
IEnumerable<string> redirectedStandardOutput; var client = new HttpClient();
var exitCodeWithArgument = client.DefaultRequestHeaders.Add("PRIVATE-TOKEN", gitlabToken);
StartProcess(
"git",
new ProcessSettings {
Arguments = "describe --tags --abbrev=0",
RedirectStandardOutput = true
},
out redirectedStandardOutput
);
var lastTag = redirectedStandardOutput.LastOrDefault(); // get the latest tag
var logParam = ""; var result = client.GetAsync($"https://git.rwth-aachen.de/api/v4/projects/{gitlabProjectId}/repository/tags").Result;
if(exitCodeWithArgument == 0) { if(!result.IsSuccessStatusCode) {
logParam = $"{lastTag}..Head"; throw new Exception("Tag query failed.");
} else {
lastTag = null;
} }
string url = null; var tagList = result.Content.ReadAsStringAsync().Result;
if(lastTag != null) { var jArray = JArray.Parse(tagList);
if(String.IsNullOrWhiteSpace(gitlabProjectPath)) { // null if not tags exists yet
exitCodeWithArgument = var lastTag = jArray.FirstOrDefault();
StartProcess(
"git",
new ProcessSettings {
Arguments = $"config --get remote.origin.url",
RedirectStandardOutput = true
},
out redirectedStandardOutput
);
url = redirectedStandardOutput.LastOrDefault(); var url = $"https://git.rwth-aachen.de/{gitlabProjectPath}";
if(url.StartsWith("git@git.rwth-aachen.de:")){
url = url.Replace("git@git.rwth-aachen.de:", "https://git.rwth-aachen.de/");
}
} else {
url = $"https://git.rwth-aachen.de/{gitlabProjectPath}";
}
if(url.EndsWith(".git")) { if(url.EndsWith(".git")) {
url = url.Substring(0, url.Length - ".git".Length); url = url.Substring(0, url.Length - ".git".Length);
} }
if(url.EndsWith("/")) { if(url.EndsWith("/")) {
url = url.Substring(0, url.Length - 1); url = url.Substring(0, url.Length - 1);
} }
url = $"{url}/compare/{lastTag}...v{semanticVersion}"; var description = "";
// First line of description
// Gitlab compare url, if something can be compared
if(lastTag == null) {
description = $"# {semanticVersion} ({DateTime.Now.Year}-{DateTime.Now.Month}-{DateTime.Now.Day})\n\n\n";
} else {
description = $"# [{semanticVersion}]({url}/compare/{lastTag}...v{semanticVersion}) ({DateTime.Now.Year}-{DateTime.Now.Month}-{DateTime.Now.Day})\n\n\n";
}
// From when will messages be parsed, null results in all messages
var logParam = "";
if(lastTag != null) {
logParam = $"{lastTag}..Head";
} }
exitCodeWithArgument = var exitCodeWithArgument =
StartProcess( StartProcess(
"git", "git",
new ProcessSettings { new ProcessSettings {
...@@ -183,12 +174,6 @@ IEnumerable<string> redirectedStandardOutput; ...@@ -183,12 +174,6 @@ IEnumerable<string> redirectedStandardOutput;
}, },
out redirectedStandardOutput out redirectedStandardOutput
); );
var description = "";
if(lastTag == null) {
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";
}
var prefixList = new Dictionary<string, List<string>>{ var prefixList = new Dictionary<string, List<string>>{
{"Fix", new List<string>()}, {"Fix", new List<string>()},
...@@ -222,19 +207,25 @@ IEnumerable<string> redirectedStandardOutput; ...@@ -222,19 +207,25 @@ IEnumerable<string> redirectedStandardOutput;
description += "\n"; description += "\n";
} }
} }
// correctly escape the json newlines
description = description.Replace("\n", "\\n");
// create tag // create tag
var client = new HttpClient();
client.DefaultRequestHeaders.Add("PRIVATE-TOKEN", gitlabToken); 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; 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); Information("Create tag: {0}", result.Content.ReadAsStringAsync().Result);
if(!result.IsSuccessStatusCode) {
throw new Exception("Tag creation failed.");
}
description = description.Replace("\n", "\\n");
// create release // create release
var json = $"{{\"name\": \"v{semanticVersion}\", \"tag_name\": \"v{semanticVersion}\", \"description\": \"{description}\"}}"; var json = $"{{\"name\": \"v{semanticVersion}\", \"tag_name\": \"v{semanticVersion}\", \"description\": \"{description}\"}}";
var content = new StringContent(json, Encoding.UTF8, "application/json"); var content = new StringContent(json, Encoding.UTF8, "application/json");
result = client.PostAsync($"https://git.rwth-aachen.de/api/v4/projects/{gitlabProjectId}/releases", content).Result; result = client.PostAsync($"https://git.rwth-aachen.de/api/v4/projects/{gitlabProjectId}/releases", content).Result;
Information("Create release: {0}", result.Content.ReadAsStringAsync().Result); Information("Create release: {0}", result.Content.ReadAsStringAsync().Result);
if(!result.IsSuccessStatusCode) {
throw new Exception("Release creation failed.");
}
}); });
Task("Build") Task("Build")
...@@ -256,7 +247,7 @@ Task("Build") ...@@ -256,7 +247,7 @@ Task("Build")
} }
// Use MSBuild // Use MSBuild
Information($"Building {solutionFile}"); Information("Building {0}", solutionFile);
MSBuild(solutionFile, frameworkSettingsWindows); MSBuild(solutionFile, frameworkSettingsWindows);
}); });
...@@ -307,7 +298,7 @@ Task("CopyToArtifacts") ...@@ -307,7 +298,7 @@ Task("CopyToArtifacts")
&& !FileExists($"{project.GetDirectory()}/{project.GetFilenameWithoutExtension()}.nuspec") && !FileExists($"{project.GetDirectory()}/{project.GetFilenameWithoutExtension()}.nuspec")
&& DirectoryExists(project.GetDirectory())) && DirectoryExists(project.GetDirectory()))
{ {
Information($"Copying {project.GetDirectory()}/bin/{configuration}/* to {artifactsDir}"); Information("Copying {0}/* to {1}", $"{project.GetDirectory()}/bin/{configuration}", artifactsDir);
CopyDirectory($"{project.GetDirectory()}/bin/{configuration}/", artifactsDir); CopyDirectory($"{project.GetDirectory()}/bin/{configuration}/", artifactsDir);
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment