diff --git a/build.cake b/build.cake index 5da84e614..f37ee080f 100644 --- a/build.cake +++ b/build.cake @@ -44,18 +44,10 @@ var artifactsFile = packagesDir + File("artifacts.txt"); var releaseNotesFile = packagesDir + File("ReleaseNotes.md"); var releaseNotes = new List(); -// stable releases -var tagsUrl = "https://api.github.com/repos/ThreeMammals/ocelot/releases/tags/"; -var nugetFeedStableKey = EnvironmentVariable("OCELOT_NUGET_API_KEY_3Mammals"); -var nugetFeedStableUploadUrl = "https://www.nuget.org/api/v2/package"; -var nugetFeedStableSymbolsUploadUrl = "https://www.nuget.org/api/v2/package"; - // internal build variables - don't change these. string committedVersion = "0.0.0-dev"; GitVersion versioning = null; -bool IsTechnicalRelease = true; -//string gitHubUsername = "raman-m"; -//string gitHubToken = Environment.GetEnvironmentVariable("OCELOT_GITHUB_API_KEY_2"); +bool IsTechnicalRelease = false; var target = Argument("target", "Default"); var slnFile = (target == Release) ? $"./Ocelot.{Release}.sln" : "./Ocelot.sln"; @@ -490,7 +482,7 @@ Task("PublishGitHubRelease") .IsDependentOn("CreateArtifacts") .Does(() => { - //if (!IsRunningOnCircleCI()) return; + if (!IsRunningOnCircleCI()) return; dynamic release = CreateGitHubRelease(); var path = packagesDir.ToString() + @"/**/*"; @@ -524,7 +516,7 @@ Task("DownloadGitHubReleaseArtifacts") System.Threading.Thread.Sleep(5000); EnsureDirectoryExists(packagesDir); - var releaseUrl = tagsUrl + versioning.NuGetVersion; + var releaseUrl = "https://api.github.com/repos/ThreeMammals/ocelot/releases/tags/" + versioning.NuGetVersion; var releaseInfo = await GetResourceAsync(releaseUrl); var assets_url = Newtonsoft.Json.Linq.JObject.Parse(releaseInfo) .Value("assets_url"); @@ -555,6 +547,10 @@ Task("PublishToNuget") if (IsRunningOnCircleCI()) { + // stable releases + var nugetFeedStableKey = EnvironmentVariable("OCELOT_NUGET_API_KEY_3Mammals"); + var nugetFeedStableUploadUrl = "https://www.nuget.org/api/v2/package"; + var nugetFeedStableSymbolsUploadUrl = "https://www.nuget.org/api/v2/package"; PublishPackages(packagesDir, artifactsFile, nugetFeedStableKey, nugetFeedStableUploadUrl, nugetFeedStableSymbolsUploadUrl); } }); @@ -593,13 +589,10 @@ private GitVersion GetNuGetVersionForCommit() private void PersistVersion(string committedVersion, string newVersion) { Information(string.Format("We'll search all csproj files for {0} and replace with {1}...", committedVersion, newVersion)); - var projectFiles = GetFiles("./**/*.csproj"); - foreach(var projectFile in projectFiles) { var file = projectFile.ToString(); - Information(string.Format("Updating {0}...", file)); var updatedProjectFile = System.IO.File.ReadAllText(file) @@ -612,7 +605,7 @@ private void PersistVersion(string committedVersion, string newVersion) /// Publishes code and symbols packages to nuget feed, based on contents of artifacts file private void PublishPackages(ConvertableDirectoryPath packagesDir, ConvertableFilePath artifactsFile, string feedApiKey, string codeFeedUrl, string symbolFeedUrl) { - Information("Publishing to NuGet..."); + Information("PublishPackages: Publishing to NuGet..."); var artifacts = System.IO.File .ReadAllLines(artifactsFile) .Distinct(); @@ -620,14 +613,10 @@ private void PublishPackages(ConvertableDirectoryPath packagesDir, ConvertableFi foreach(var artifact in artifacts) { if (artifact == "ReleaseNotes.md") - { continue; - } var codePackage = packagesDir + File(artifact); - Information("Pushing package " + codePackage + "..."); - - Information("Calling DotNetNuGetPush"); + Information("PublishPackages: Pushing package " + codePackage + "..."); DotNetNuGetPush( codePackage, new DotNetNuGetPushSettings { ApiKey = feedApiKey, Source = codeFeedUrl } @@ -638,10 +627,7 @@ private void PublishPackages(ConvertableDirectoryPath packagesDir, ConvertableFi private void SetupGitHubClient(System.Net.Http.HttpClient client) { string token = Environment.GetEnvironmentVariable("OCELOT_GITHUB_API_KEY_2"); - client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue( - "Bearer", - token // Convert.ToBase64String(System.Text.ASCIIEncoding.ASCII.GetBytes(gitHubPassword)) // token actually - ); + client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", token); client.DefaultRequestHeaders.Add("User-Agent", "Ocelot Release"); client.DefaultRequestHeaders.Add("Accept", "application/vnd.github+json"); client.DefaultRequestHeaders.Add("X-GitHub-Api-Version", "2022-11-28"); @@ -649,35 +635,23 @@ private void SetupGitHubClient(System.Net.Http.HttpClient client) private dynamic CreateGitHubRelease() { - //var json = $"{{ \"tag_name\": \"{versioning.NuGetVersion}\", \"target_commitish\": \"main\", \"name\": \"{versioning.NuGetVersion}\", \"body\": \"{ReleaseNotesAsJson()}\", \"draft\": true, \"prerelease\": true }}"; var json = $"{{ \"tag_name\": \"{versioning.NuGetVersion}\", \"target_commitish\": \"main\", \"name\": \"{versioning.NuGetVersion}\", \"body\": \"{ReleaseNotesAsJson()}\", \"draft\": true, \"prerelease\": true, \"generate_release_notes\": false }}"; var content = new System.Net.Http.StringContent(json, System.Text.Encoding.UTF8, "application/json"); using (var client = new System.Net.Http.HttpClient()) { - // client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue( - // "Basic", - // Convert.ToBase64String(System.Text.ASCIIEncoding.ASCII.GetBytes($"{gitHubUsername}:{gitHubPassword}")) - // ); - // client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue( - // "Bearer", - // Convert.ToBase64String(System.Text.ASCIIEncoding.ASCII.GetBytes(gitHubPassword)) // token actually - // ); - // client.DefaultRequestHeaders.Add("User-Agent", "Ocelot Release"); - // client.DefaultRequestHeaders.Add("Accept", "application/vnd.github+json"); - // client.DefaultRequestHeaders.Add("X-GitHub-Api-Version", "2022-11-28"); SetupGitHubClient(client); - var result = client.PostAsync("https://api.github.com/repos/ThreeMammals/Ocelot/releases", content) - .Result; - if(result.StatusCode != System.Net.HttpStatusCode.Created) + var result = client.PostAsync("https://api.github.com/repos/ThreeMammals/Ocelot/releases", content).Result; + if (result.StatusCode != System.Net.HttpStatusCode.Created) { - throw new Exception("CreateGitHubRelease result.StatusCode = " + result.StatusCode); + var msg = "CreateGitHubRelease: StatusCode = " + result.StatusCode; + Information(msg); + throw new Exception(msg); } var releaseData = result.Content.ReadAsStringAsync().Result; dynamic releaseJSON = Newtonsoft.Json.JsonConvert.DeserializeObject(releaseData); Information("CreateGitHubRelease: Release ID is " + releaseJSON.id); - //releaseId = test.id; - return releaseJSON; //.id; + return releaseJSON; } } @@ -694,18 +668,13 @@ private void UploadFileToGitHubRelease(dynamic release, FilePath file) using (var client = new System.Net.Http.HttpClient()) { - // client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue( - // "Basic", - // Convert.ToBase64String(System.Text.ASCIIEncoding.ASCII.GetBytes($"{gitHubUsername}:{gitHubPassword}")) - // ); - // client.DefaultRequestHeaders.Add("User-Agent", "Ocelot Release"); SetupGitHubClient(client); int releaseId = release.id; var fileName = file.GetFilename(); string uploadUrl = release.upload_url.ToString(); Information($"UploadFileToGitHubRelease: uploadUrl is {uploadUrl}"); - string[] parts = uploadUrl.Split('{'); - uploadUrl = parts[0] + $"?name={fileName}"; // $"https://uploads.github.com/repos/ThreeMammals/Ocelot/releases/{releaseId}/assets?name={fileName}" + string[] parts = uploadUrl.Replace("{", "").Split(','); + uploadUrl = parts[0] + "=" + fileName; // $"https://uploads.github.com/repos/ThreeMammals/Ocelot/releases/{releaseId}/assets?name={fileName}" Information($"UploadFileToGitHubRelease: uploadUrl is {uploadUrl}"); var result = client.PostAsync(uploadUrl, content).Result; if (result.StatusCode != System.Net.HttpStatusCode.Created) @@ -719,20 +688,14 @@ private void UploadFileToGitHubRelease(dynamic release, FilePath file) private void CompleteGitHubRelease(dynamic release) { int releaseId = release.id; - string url = release.url; + string url = release.url.ToString(); var json = $"{{ \"tag_name\": \"{versioning.NuGetVersion}\", \"target_commitish\": \"main\", \"name\": \"{versioning.NuGetVersion}\", \"body\": \"{ReleaseNotesAsJson()}\", \"draft\": false, \"prerelease\": false }}"; var request = new System.Net.Http.HttpRequestMessage(new System.Net.Http.HttpMethod("Patch"), url); // $"https://api.github.com/repos/ThreeMammals/Ocelot/releases/{releaseId}"); request.Content = new System.Net.Http.StringContent(json, System.Text.Encoding.UTF8, "application/json"); using (var client = new System.Net.Http.HttpClient()) { - // client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue( - // "Basic", - // Convert.ToBase64String(System.Text.ASCIIEncoding.ASCII.GetBytes($"{gitHubUsername}:{gitHubPassword}")) - // ); - // client.DefaultRequestHeaders.Add("User-Agent", "Ocelot Release"); SetupGitHubClient(client); - var result = client.SendAsync(request).Result; if (result.StatusCode != System.Net.HttpStatusCode.OK) {