public void CanDecrement() { SemanticVersion v1 = new SemanticVersion(1, 0, 0, "alpha.1"); SemanticVersion v2 = new SemanticVersion(1, 3, 4, "alpha.2.0"); SemanticVersion v3 = new SemanticVersion(0, 0, 0, "beta"); SemanticVersion v4 = new SemanticVersion(0, 0, 0, "beta.x.0"); PreRelease v11 = --(v1.PreRelease); PreRelease v21 = --(v2.PreRelease); Assert.Equal(v11.Count, 1); Assert.Equal(v11.ToString(), "alpha"); Assert.Equal(v21.ToString(), "alpha.1"); Assert.Equal((--v3).ToString(), "0.0.0"); Assert.Equal((--v4).ToString(), "0.0.0.beta"); }
public SemanticVersion(uint major, uint minor, uint patch, PreRelease prelease, uint build) { Major = major; Minor = minor; Patch = patch; PreRelease = prelease; Build = build; _generalStr = string.Format("{0}.{1}.{2}", Major.ToString(), Minor.ToString(), Patch.ToString()); if (PreRelease != null) _comparableStr = string.Format("{0}-{1}", _generalStr, PreRelease.ToString()); else _comparableStr = _generalStr; if (Build == 0) _fullStr = _comparableStr; else _fullStr = string.Format("{0}+{1}", _comparableStr, Build.ToString()); }
public void CanIncrement() { SemanticVersion v1 = new SemanticVersion(1, 0, 0, "alpha.1"); SemanticVersion v2 = new SemanticVersion(1, 3, 4, "alpha.2.0"); SemanticVersion v3 = new SemanticVersion(0, 0, 0, "beta"); SemanticVersion v4 = new SemanticVersion(0, 0, 0, "beta.x.0"); SemanticVersion bx860new = new SemanticVersion(0, 0, 0, "beta.x86.0.new"); PreRelease v11 = ++(v1.PreRelease); PreRelease v21 = ++(v2.PreRelease); Assert.Equal(v11.ToString(), "alpha.2"); Assert.Equal(v11[1], "2"); Assert.Equal(v21[1], "3"); Assert.Equal(v21.ToString(), "alpha.3"); ++(v3.PreRelease); Assert.Equal(v3.PreRelease.Count, 2); Assert.Equal(v3.PreRelease[1], "1"); ++(v4.PreRelease); Assert.Equal(v4.PreRelease[2], "1"); Assert.Equal((++bx860new).PreRelease.ToString(), "beta.x86.0.new.1"); }
public override string ToString() { return(PreRelease.HasValue? $"{Major}.{Minor}.{Patch}-{PreRelease.ToString()}": $"{Major}.{Minor}.{Patch}"); }
private async System.Threading.Tasks.Task Upload() { using (var httpClient = new HttpClient()) { httpClient.DefaultRequestHeaders.UserAgent.Add(new System.Net.Http.Headers.ProductInfoHeaderValue("msbuild", "4.0")); httpClient.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); httpClient.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Token", GithubOAuthToken); HttpResponseMessage createReleaseResponse; string postUrl = @"https://api.github.com/repos/" + GithubUser + @"/" + GithubRepo + @"/releases"; using (var request = new HttpRequestMessage(new HttpMethod("POST"), postUrl)) { string json = @"{ ""tag_name"": """; json += ReleaseTag; json += @""", ""target_commitish"": ""master"", ""name"": """; json += ReleaseName; json += @""", ""body"": """; json += HttpUtility.JavaScriptStringEncode(ReleaseDescription, false); json += @""", ""draft"": "; json += Draft.ToString().ToLower(); json += @", ""prerelease"": "; json += PreRelease.ToString().ToLower(); json += @"}"; //string json = @"{ ""tag_name"": ""v11.0.0"", ""target_commitish"": ""master"", ""name"": ""release name v11.0.0"", ""body"": ""Description of the release"", ""draft"": true, ""prerelease"": false}"; request.Content = new StringContent(json, Encoding.UTF8, "application/json"); createReleaseResponse = await httpClient.SendAsync(request); } string createReleaseOutput = await createReleaseResponse.Content.ReadAsStringAsync(); if (!createReleaseResponse.IsSuccessStatusCode) { Log.LogMessage(MessageImportance.High, createReleaseResponse.ToString()); Log.LogMessage(MessageImportance.High, createReleaseOutput.ToString()); Log.LogError("[UploadGitHubRelease] Failed to create release with the GitHub API V3"); return; } var jsonReader = JsonReaderWriterFactory.CreateJsonReader(Encoding.UTF8.GetBytes(createReleaseOutput), new System.Xml.XmlDictionaryReaderQuotas()); var root = XElement.Load(jsonReader); string uploadURL = root.XPathSelectElement("//upload_url").Value; uploadURL = uploadURL.Replace("{?name,label}", "?name="); Log.LogMessage(MessageImportance.High, "[UploadGitHubRelease] Release '" + ReleaseName + "' created with tag '" + ReleaseTag + "'"); if (ZipFilesToUpload == null) { return; } foreach (ITaskItem zipItem in ZipFilesToUpload) { HttpResponseMessage uploadZipResponse; string zipname = Path.GetFileName(zipItem.ItemSpec); Log.LogMessage(MessageImportance.High, "[UploadGitHubRelease] Uploading '" + zipname + "'..."); using (var request = new HttpRequestMessage(new HttpMethod("POST"), uploadURL + zipname)) { request.Content = new ByteArrayContent(File.ReadAllBytes(zipItem.ItemSpec)); request.Content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/zip"); uploadZipResponse = await httpClient.SendAsync(request); } if (!uploadZipResponse.IsSuccessStatusCode) { Log.LogMessage(MessageImportance.High, uploadZipResponse.ToString()); Log.LogMessage(MessageImportance.High, await uploadZipResponse.Content.ReadAsStringAsync()); Log.LogError("[UploadGitHubRelease] Failed to upload zip file with the GitHub API V3 : " + zipItem.ItemSpec); break; } Log.LogMessage(MessageImportance.High, "[UploadGitHubRelease] " + zipname + " uploaded successfully"); } } }