From c74ec5c6ed4058351556d7d095380eb05961514c Mon Sep 17 00:00:00 2001 From: MakesYT <42534870+MakesYT@users.noreply.github.com> Date: Wed, 10 Apr 2024 00:57:39 +0800 Subject: [PATCH] test --- KitopiaAvalonia/KitopiaAvalonia.csproj | 4 +- NuGet.Config | 17 ++++ build/Build.cs | 122 +++++++++++++++++++++++-- 3 files changed, 133 insertions(+), 10 deletions(-) create mode 100644 NuGet.Config diff --git a/KitopiaAvalonia/KitopiaAvalonia.csproj b/KitopiaAvalonia/KitopiaAvalonia.csproj index 71ca72b..906955c 100644 --- a/KitopiaAvalonia/KitopiaAvalonia.csproj +++ b/KitopiaAvalonia/KitopiaAvalonia.csproj @@ -26,7 +26,9 @@ true none Assets\icon.ico - + true + none + 0.0.2.037 diff --git a/NuGet.Config b/NuGet.Config new file mode 100644 index 0000000..09b7850 --- /dev/null +++ b/NuGet.Config @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/build/Build.cs b/build/Build.cs index 9fe4931..dfe46d3 100644 --- a/build/Build.cs +++ b/build/Build.cs @@ -1,25 +1,32 @@ using System; +using System.IO; +using System.IO.Compression; using System.Linq; using Microsoft.Build.Construction; using Nuke.Common; using Nuke.Common.CI; using Nuke.Common.CI.GitHubActions; using Nuke.Common.Execution; +using Nuke.Common.Git; using Nuke.Common.IO; using Nuke.Common.ProjectModel; using Nuke.Common.Tooling; using Nuke.Common.Tools.DotNet; +using Nuke.Common.Tools.GitHub; using Nuke.Common.Utilities.Collections; +using Octokit; using Serilog; using static Nuke.Common.EnvironmentInfo; using static Nuke.Common.IO.FileSystemTasks; using static Nuke.Common.IO.PathConstruction; using static Nuke.Common.Tools.DotNet.DotNetTasks; +using Project = Nuke.Common.ProjectModel.Project; + [GitHubActions( "continuous", GitHubActionsImage.WindowsLatest, On = new[] { GitHubActionsTrigger.Push }, - + ImportSecrets = new[] { nameof(GitHubToken) }, InvokedTargets = new[] { nameof(Compile) })] class Build : NukeBuild { @@ -35,21 +42,21 @@ class Build : NukeBuild [Parameter("Configuration to build - Default is 'Debug' (local) or 'Release' (server)")] readonly Configuration Configuration = IsLocalBuild ? Configuration.Debug : Configuration.Release; + + [Parameter][Secret]readonly string GitHubToken; Project AvaloniaProject => Solution.GetProject("KitopiaAvalonia"); - Target Clean => _ => _ - .Before(Restore) - .Executes(() => - { - }); + Target Restore => _ => _ .Executes(() => { Log.Debug( "Restoring solution {0}", Solution); Log.Debug("Restoring project {0}", AvaloniaProject); + DotNetRestore(c => new DotNetRestoreSettings() .SetProjectFile(AvaloniaProject.Path)); - + DotNetRestore(c => new DotNetRestoreSettings() + .SetProjectFile("KitopiaEx")); }); @@ -57,8 +64,105 @@ class Build : NukeBuild .DependsOn(Restore) .Executes(() => { - DotNetBuild(c => new DotNetBuildSettings() - .SetProjectFile(AvaloniaProject.Path)); + // DotNetBuild(c => + // { + // return new DotNetBuildSettings() + // .SetProjectFile(AvaloniaProject.Path) + // .SetOutputDirectory(RootDirectory / "output"); + // }); }); + + + + + Target Pack => _ => _ + .OnlyWhenDynamic(() => + { + 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 _gitHubClient = new GitHubClient(new ProductHeaderValue("Kitopia")) + { + Credentials = new Credentials(GitHubToken) + }; + var readOnlyList = _gitHubClient.Repository.GetAllTags(gitRepository.GetGitHubOwner(), gitRepository.GetGitHubName()).Result; + if (readOnlyList.Any(e=>e.Name==AvaloniaProject.GetProperty("Version"))) + { + return false; + } + return true; + }) + .DependsOn(Compile) + .Executes(() => + { + var rootDirectory = RootDirectory / "Publish"; + rootDirectory.DeleteDirectory(); + DotNetPublish(c => new DotNetPublishSettings() + .SetProject("KitopiaEx") + .SetOutput(RootDirectory / "Publish" / "plugins" / "KitopiaEx") + .SetRuntime( "win-x64") + .SetFramework("net8.0") + .SetConfiguration("Release") + .SetSelfContained(false) + ); + DotNetPublish(c => new DotNetPublishSettings() + .SetProject(AvaloniaProject.Name) + .SetOutput(RootDirectory / "Publish") + .SetPublishSingleFile(true) + + .SetRuntime( "win-x64") + .SetFramework("net8.0-windows10.0.17763.0") + .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()); + var _gitHubClient = new GitHubClient(new ProductHeaderValue("Kitopia")) + { + Credentials = new Credentials(GitHubToken) + }; + foreach (var absolutePath in rootDirectory.GetFiles()) + { + if (absolutePath.Extension is ".pdb" or ".xml") + { + absolutePath.DeleteFile(); + } + } + + var archiveFile = RootDirectory / "Kitopia"+AvaloniaProject.GetProperty("Version")+".zip"; + archiveFile.DeleteFile(); + rootDirectory.ZipTo(archiveFile); + var newRelease = new NewRelease(AvaloniaProject.GetProperty("Version")) + { + Name = "Kitopia", + Prerelease = true, + Draft = true, + + }; + + var release = _gitHubClient.Repository.Release.Create(gitRepository.GetGitHubOwner(), gitRepository.GetGitHubName(), + newRelease).Result; + using var artifactStream = File.OpenRead(archiveFile); + var fileName = Path.GetFileName( "Kitopia"+AvaloniaProject.GetProperty("Version")+".zip"); + var assetUpload = new ReleaseAssetUpload + { + FileName = fileName, + ContentType = "application/octet-stream", + RawData = artifactStream, + }; + _gitHubClient.Repository.Release.UploadAsset(release,assetUpload).Wait(); + Log.Debug(result); + } + ); + Target Clean => _ => _ + .DependsOn(Pack) + .Executes(() => + { + + }); }