From d81e74b84894ac5c45eadca61bfbb48b1da55f01 Mon Sep 17 00:00:00 2001 From: MakesYT <2696703792@qq.com> Date: Sun, 4 Aug 2024 11:16:18 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=20=E6=9E=84=E5=BB=BA?= =?UTF-8?q?=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build/Build.cs | 60 ++++++++++++++++++-------------------------------- 1 file changed, 22 insertions(+), 38 deletions(-) diff --git a/build/Build.cs b/build/Build.cs index dc2219f..26a848e 100644 --- a/build/Build.cs +++ b/build/Build.cs @@ -65,6 +65,7 @@ class Build : NukeBuild }); GitHubClient _gitHubClient; + Release release; Target CreateRelease => _ => _.OnlyWhenDynamic(() => { @@ -153,34 +154,34 @@ class Build : NukeBuild Draft = false, Body = body.ToString() }; - var release = _gitHubClient.Repository.Release.Create( + release = _gitHubClient.Repository.Release.Create( gitRepository.GetGitHubOwner(), gitRepository.GetGitHubName(), newRelease) .Result; }); - Target PackDebug => _ => _.Executes(() => - { - var rootDirectory = RootDirectory / "buildTest"; - var archiveFile = RootDirectory / "Kitopia" + AvaloniaProject.GetProperty("Version") + - "_Debug_WithoutContained.zip"; - archiveFile.DeleteFile(); - rootDirectory.ZipTo(archiveFile); - Log.Debug("Uploading artifact {0}", archiveFile); - using var artifactStream = File.OpenRead(archiveFile); - var assetUpload = new ReleaseAssetUpload + Target PackDebug => _ => _ + .OnlyWhenDynamic(() => FinishedTargets.Contains(CreateRelease)) + .DependsOn(CreateRelease) + .Executes(() => { - FileName = archiveFile.Name, - ContentType = "application/octet-stream", - RawData = artifactStream, - }; - var gitRepository = GitRepository.FromUrl("https://github.com/MakesYT/Kitopia"); - var release = _gitHubClient.Repository.Release.Get(gitRepository.GetGitHubOwner(), "Kitopia", - AvaloniaProject.GetProperty("Version")).Result; - _gitHubClient.Repository.Release.UploadAsset(release, assetUpload) - .Wait(); - }); + var rootDirectory = RootDirectory / "buildTest"; + var archiveFile = RootDirectory / "Kitopia" + AvaloniaProject.GetProperty("Version") + + "_Debug_WithoutContained.zip"; + archiveFile.DeleteFile(); + rootDirectory.ZipTo(archiveFile); + Log.Debug("Uploading artifact {0}", archiveFile); + using var artifactStream = File.OpenRead(archiveFile); + var assetUpload = new ReleaseAssetUpload + { + FileName = archiveFile.Name, + ContentType = "application/octet-stream", + RawData = artifactStream, + }; + _gitHubClient.Repository.Release.UploadAsset(release, assetUpload) + .Wait(); + }); Target Pack => _ => _ .OnlyWhenDynamic(() => FinishedTargets.Contains(CreateRelease)) @@ -206,11 +207,6 @@ class Build : NukeBuild .SetConfiguration("Release") .SetSelfContained(false) ); - var gitRepository = GitRepository.FromUrl("https://github.com/MakesYT/Kitopia"); - var result = GitHubTasks.GetLatestRelease(gitRepository, true) - .Result; - Log.Debug("Packing project {0}", AvaloniaProject); - Log.Debug("GitHubName {0}", gitRepository.GetGitHubName()); foreach (var absolutePath in rootDirectory.GetFiles()) { if (absolutePath.Extension is ".pdb" or ".xml") @@ -231,11 +227,8 @@ class Build : NukeBuild ContentType = "application/octet-stream", RawData = artifactStream, }; - var release = _gitHubClient.Repository.Release.Get(gitRepository.GetGitHubOwner(), "Kitopia", - AvaloniaProject.GetProperty("Version")).Result; _gitHubClient.Repository.Release.UploadAsset(release, assetUpload) .Wait(); - Log.Debug(result); } ); @@ -265,12 +258,6 @@ class Build : NukeBuild .SetConfiguration("Release") .SetSelfContained(true) ); - var gitRepository = GitRepository.FromUrl("https://github.com/MakesYT/Kitopia"); - var result = GitHubTasks.GetLatestRelease(gitRepository, true) - .Result; - Log.Debug("Packing project {0}", AvaloniaProject); - Log.Debug("GitHubName {0}", gitRepository.GetGitHubName()); - var archiveFile_self = RootDirectory / "Kitopia" + AvaloniaProject.GetProperty("Version") + "_SelfContained.zip"; archiveFile_self.DeleteFile(); @@ -289,11 +276,8 @@ class Build : NukeBuild ContentType = "application/octet-stream", RawData = File.OpenRead(archiveFile_self), }; - var release = _gitHubClient.Repository.Release.Get(gitRepository.GetGitHubOwner(), "Kitopia", - AvaloniaProject.GetProperty("Version")).Result; _gitHubClient.Repository.Release.UploadAsset(release, assetUpload_self) .Wait(); - Log.Debug(result); } );