diff --git a/.config/dotnet-tools.json b/.config/dotnet-tools.json new file mode 100644 index 00000000..3f287339 --- /dev/null +++ b/.config/dotnet-tools.json @@ -0,0 +1,12 @@ +{ + "version": 1, + "isRoot": true, + "tools": { + "cake.tool": { + "version": "4.0.0", + "commands": [ + "dotnet-cake" + ] + } + } +} diff --git a/appveyor.yml b/appveyor.yml new file mode 100644 index 00000000..fd432319 --- /dev/null +++ b/appveyor.yml @@ -0,0 +1,21 @@ +version: 1.0.{build} +branches: + only: + - "release" +build_cloud: HUTAO-SERVER +image: Visual Studio 2022 +clone_depth: 3 +clone_folder: D:\appveyor\project\Snap.Hutao.Project +install: +- pwsh: dotnet tool restore +build_script: +- pwsh: dotnet cake +artifacts: +- path: src/output/*.msix + type: file +deploy: +- provider: Webhook + url: https://app.signpath.io/API/v1/7a941fa3-64d8-4c45-bd03-92a02bcd4964/Integrations/AppVeyor?ProjectSlug=Snap.Hutao&SigningPolicySlug=test-signing&ArtifactConfigurationSlug=msix + # url: https://app.signpath.io/API/v1/7a941fa3-64d8-4c45-bd03-92a02bcd4964/Integrations/AppVeyor?ProjectSlug=Snap.Hutao&SigningPolicySlug=release-signing&ArtifactConfigurationSlug=msix + authorization: + secure: j8srQ5/UYWhI+jlm3Vo3D3QfXoRyQ9hOn3ynJGtwusKui4+uDi4gykdUFYCITZxK+C/fOCAZNJ+YaKSm/OaiXw== diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 55f9c894..37136b2a 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -7,30 +7,31 @@ # 5. Connect the GitHub in project settings # 6. Run -trigger: - branches: - include: - - main - - develop - paths: - exclude: - - README.md - - azure-pipelines.yml - - .github/ISSUE_TEMPLATE/*.yml - - .github/workflows/*.yml - - src/Snap.Hutao/Snap.Hutao/Resource/Localization/*.resx -pr: - branches: - include: - - main - paths: - exclude: - - README.md - - azure-pipelines.yml - - .github/ISSUE_TEMPLATE/*.yml - - .github/workflows/*.yml - - src/Snap.Hutao/Snap.Hutao/Resource/Localization/*.resx - +trigger: none +# trigger: +# branches: +# include: +# - main +# - develop +# paths: +# exclude: +# - README.md +# - azure-pipelines.yml +# - .github/ISSUE_TEMPLATE/*.yml +# - .github/workflows/*.yml +# - src/Snap.Hutao/Snap.Hutao/Resource/Localization/*.resx +# pr: +# branches: +# include: +# - main +# paths: +# exclude: +# - README.md +# - azure-pipelines.yml +# - .github/ISSUE_TEMPLATE/*.yml +# - .github/workflows/*.yml +# - src/Snap.Hutao/Snap.Hutao/Resource/Localization/*.resx + pool: name: Default @@ -42,15 +43,9 @@ variables: project: $(Build.SourcesDirectory)/src/Snap.Hutao/Snap.Hutao/Snap.Hutao.csproj' buildPlatform: 'x64' buildConfiguration: 'Release' - build_date: $[ format('{0:yyyy}.{0:M}.{0:d}', pipeline.startTime) ] steps: -- task: GetRevision@1 - displayName: get Pipelines revision number - inputs: - VariableName: 'rev_number' - - task: UseDotNet@2 displayName: Install dotNet inputs: @@ -58,94 +53,20 @@ steps: version: '8.x' includePreviewVersions: true -- task: NuGetToolInstaller@1 - name: 'NuGetToolInstaller' - displayName: 'NuGet Installer' - -- task: NuGetCommand@2 - displayName: NuGet restore - inputs: - command: 'restore' - restoreSolution: '$(solution)' - feedsToUse: 'config' - nugetConfigPath: '$(Build.SourcesDirectory)/NuGet.Config' - -- task: MsixPackaging@1 - displayName: Build binary package - inputs: - outputPath: '$(Build.ArtifactStagingDirectory)/' - solution: '$(solution)' - clean: false - generateBundle: false - buildConfiguration: 'Release' - buildPlatform: 'x64' - updateAppVersion: false - appPackageDistributionMode: 'SideloadOnly' - msbuildLocationMethod: 'location' - msbuildLocation: 'C:\Program Files\Microsoft Visual Studio\2022\Enterprise\Msbuild\Current\Bin\MSBuild.exe' - -- task: MagicChunks@2 - inputs: - sourcePath: '$(Build.SourcesDirectory)\src\Snap.Hutao\Snap.Hutao\bin\x64\Release\net8.0-windows10.0.22621.0\win-x64\AppxManifest.xml' - fileType: 'Xml' - targetPathType: 'source' - transformationType: 'json' - transformations: | - { - "Package/Identity/@Name": "7f0db578-026f-4e0b-a75b-d5d06bb0a74c", - "Package/Identity/@Publisher": "CN=DGP Studio CI", - "Package/Identity/@Version": "$(build_date).$(rev_number)", - "Package/Properties/DisplayName": "胡桃 Alpha", - "Package/Properties/PublisherDisplayName":"DGP Studio CI", - "Package/Applications/Application/uap:VisualElements/@DisplayName": "胡桃 Alpha" - } - - task: CmdLine@2 - displayName: Create resources folder + displayName: dotnet cake inputs: - script: | - mkdir Assets - - mkdir Resource - workingDirectory: '$(Build.SourcesDirectory)\src\Snap.Hutao\Snap.Hutao\bin\x64\Release\net8.0-windows10.0.22621.0\win-x64' - - -- task: CopyFiles@2 - displayName: Copy Assets Folder - inputs: - SourceFolder: '$(Build.SourcesDirectory)\src\Snap.Hutao\Snap.Hutao\Assets' - Contents: '**' - TargetFolder: '$(Build.SourcesDirectory)\src\Snap.Hutao\Snap.Hutao\bin\x64\Release\net8.0-windows10.0.22621.0\win-x64\Assets' - -- task: CopyFiles@2 - displayName: Copy Resource Folder - inputs: - SourceFolder: '$(Build.SourcesDirectory)\src\Snap.Hutao\Snap.Hutao\Resource' - Contents: '**' - TargetFolder: '$(Build.SourcesDirectory)\src\Snap.Hutao\Snap.Hutao\bin\x64\Release\net8.0-windows10.0.22621.0\win-x64\Resource' - -- task: CmdLine@2 - displayName: Build MSIX - inputs: - script: '"C:\Program Files (x86)\Windows Kits\10\bin\10.0.22621.0\x64\makeappx.exe" pack /d $(Build.SourcesDirectory)\src\Snap.Hutao\Snap.Hutao\bin\x64\Release\net8.0-windows10.0.22621.0\win-x64 /p $(Build.ArtifactStagingDirectory)/Snap.Hutao.Alpha-$(build_date).$(rev_number).msix' + script: dotnet tool restore && dotnet cake - task: MsixSigning@1 name: signMsix displayName: Sign MSIX package inputs: - package: '$(Build.ArtifactStagingDirectory)/Snap.Hutao.Alpha-$(build_date).$(rev_number).msix' + package: '$(Build.ArtifactStagingDirectory)/Snap.Hutao.Alpha-$(version).msix' certificate: 'DGP_Studio_CI.pfx' passwordVariable: 'pw' condition: succeeded() - -#- task: PublishPipelineArtifact@1 -# displayName: 'Upload Output' -# inputs: -# targetPath: '$(Build.ArtifactStagingDirectory)/' -# artifact: 'Output' -# publishLocation: 'pipeline' - - task: DownloadSecureFile@1 name: cerFile displayName: Download Root CA @@ -155,12 +76,12 @@ steps: - task: GitHubRelease@1 inputs: gitHubConnection: 'github.com_Masterain' - repositoryName: 'DGP-Studio/Snap.Hutao' + repositoryName: 'DGP-Automation/Hutao-Auto-Release' action: 'create' target: '$(Build.SourceVersion)' tagSource: 'userSpecifiedTag' - tag: '$(build_date).$(rev_number)' - title: '$(build_date).$(rev_number)' + tag: '$(version)' + title: '$(version)' releaseNotesSource: 'inline' releaseNotesInline: | ## 普通用户请勿下载 @@ -180,12 +101,12 @@ steps: displayName: Upload CI via Rclone condition: and(succeeded(), eq(variables['Build.SourceBranch'], 'refs/heads/main')) inputs: - arguments: 'copy $(Build.ArtifactStagingDirectory)/Snap.Hutao.Alpha-$(build_date).$(rev_number).msix downloadDGPCN:/releases/Alpha/' + arguments: 'copy $(Build.ArtifactStagingDirectory)/Snap.Hutao.Alpha-$(version).msix downloadDGPCN:/releases/Alpha/' configPath: 'C:\agent\_work\_tasks\rclone.conf' - task: rclone@1 displayName: Upload PR CI via Rclone condition: and(succeeded(), eq(variables['Build.Reason'], 'PullRequest')) inputs: - arguments: 'copy $(Build.ArtifactStagingDirectory)/Snap.Hutao.Alpha-$(build_date).$(rev_number).msix downloadDGPCN:/releases/PR/' + arguments: 'copy $(Build.ArtifactStagingDirectory)/Snap.Hutao.Alpha-$(version).msix downloadDGPCN:/releases/PR/' configPath: 'C:\agent\_work\_tasks\rclone.conf' diff --git a/build.cake b/build.cake new file mode 100644 index 00000000..789958e9 --- /dev/null +++ b/build.cake @@ -0,0 +1,181 @@ +#tool "nuget:?package=nuget.commandline&version=6.5.0" +#addin nuget:?package=Cake.Http&version=3.0.2 + +var target = Argument("target", "Build"); +var configuration = Argument("configuration", "Release"); + +// Pre-define + +var version = "version"; + +var repoDir = "repoDir"; +var outputPath = "outputPath"; + +string solution +{ + get => System.IO.Path.Combine(repoDir, "src", "Snap.Hutao", "Snap.Hutao.sln"); +} +string project +{ + get => System.IO.Path.Combine(repoDir, "src", "Snap.Hutao", "Snap.Hutao", "Snap.Hutao.csproj"); +} +string binPath +{ + get => System.IO.Path.Combine(repoDir, "src", "Snap.Hutao", "Snap.Hutao", "bin", "x64", "Release", "net8.0-windows10.0.22621.0", "win-x64"); +} +string manifest +{ + get => System.IO.Path.Combine(repoDir, "src", "Snap.Hutao", "Snap.Hutao", "Package.appxmanifest"); +} + +if (AzurePipelines.IsRunningOnAzurePipelines) +{ + repoDir = AzurePipelines.Environment.Build.SourcesDirectory.FullPath; + outputPath = AzurePipelines.Environment.Build.ArtifactStagingDirectory.FullPath; + + var versionAuth = HasEnvironmentVariable("VERSION_API_TOKEN") ? EnvironmentVariable("VERSION_API_TOKEN") : throw new Exception("Cannot find VERSION_API_TOKEN"); + version = HttpGet( + "https://internal.snapgenshin.cn/BuildIntergration/RequestNewVersion", + new HttpSettings + { + Headers = new Dictionary + { + { "Authorization", versionAuth } + } + } + ); + Information($"Version: {version}"); + + AzurePipelines.Commands.SetVariable("version", version); +} +else if (AppVeyor.IsRunningOnAppVeyor) +{ + repoDir = AppVeyor.Environment.Build.Folder; + outputPath = System.IO.Path.Combine(repoDir, "src", "output"); + + version = XmlPeek(manifest, "appx:Package/appx:Identity/@Version", new XmlPeekSettings + { + Namespaces = new Dictionary { { "appx", "http://schemas.microsoft.com/appx/manifest/foundation/windows10" } } + })[..^2]; + Information($"Version: {version}"); +} + +Task("Build") + .IsDependentOn("Build binary package") + .IsDependentOn("Copy files") + .IsDependentOn("Build MSIX"); + +Task("NuGet Restore") + .Does(() => +{ + Information("Restoring packages..."); + + var nugetConfig = System.IO.Path.Combine(repoDir, "NuGet.Config"); + DotNetRestore(project, new DotNetRestoreSettings + { + Verbosity = DotNetVerbosity.Detailed, + Interactive = false, + ConfigFile = nugetConfig + }); +}); + +Task("Generate AppxManifest") + .Does(() => +{ + Information("Generating AppxManifest..."); + + var content = System.IO.File.ReadAllText(manifest); + + if (AzurePipelines.IsRunningOnAzurePipelines) + { + Information("Using CI configuraion"); + content = content + .Replace("Snap Hutao", "Snap Hutao Alpha") + .Replace("胡桃", "胡桃 Alpha") + .Replace("DGP Studio", "DGP Studio CI"); + content = System.Text.RegularExpressions.Regex.Replace(content, " Name=\"([^\"]*)\"", " Name=\"7f0db578-026f-4e0b-a75b-d5d06bb0a74c\""); + content = System.Text.RegularExpressions.Regex.Replace(content, " Publisher=\"([^\"]*)\"", " Publisher=\"CN=DGP Studio CI\""); + content = System.Text.RegularExpressions.Regex.Replace(content, " Version=\"([0-9\\.]+)\"", $" Version=\"{version}\""); + } + else if (AppVeyor.IsRunningOnAppVeyor) + { + Information("Using Release configuration"); + content = System.Text.RegularExpressions.Regex.Replace(content, " Publisher=\"([^\"]*)\"", " Publisher=\"CN=Test certificate for 'Snap Hutao [OSS]'\""); + // release + // content = System.Text.RegularExpressions.Regex.Replace(content, " Publisher=\"([^\"]*)\"", " Publisher=\"CN=SignPath Foundation, O=SignPath Foundation, C=US, S=DE, L=Lewes\""); + } + + System.IO.File.WriteAllText(manifest, content); + + Information("Generated."); +}); + +Task("Build binary package") + .IsDependentOn("NuGet Restore") + .IsDependentOn("Generate AppxManifest") + .Does(() => +{ + Information("Building binary package..."); + + var settings = new DotNetBuildSettings + { + Configuration = configuration + }; + + settings.MSBuildSettings = new DotNetMSBuildSettings + { + ArgumentCustomization = args => args.Append("/p:Platform=x64") + .Append("/p:UapAppxPackageBuildMode=SideloadOnly") + .Append("/p:AppxPackageSigningEnabled=false") + .Append("/p:AppxBundle=Never") + .Append("/p:AppxPackageOutput=" + outputPath) + }; + + DotNetBuild(project, settings); +}); + +Task("Copy files") + .IsDependentOn("Build binary package") + .Does(() => +{ + Information("Copying assets..."); + CopyDirectory( + System.IO.Path.Combine(repoDir, "src", "Snap.Hutao", "Snap.Hutao", "Assets"), + System.IO.Path.Combine(binPath, "Assets") + ); + + Information("Copying resource..."); + CopyDirectory( + System.IO.Path.Combine(repoDir, "src", "Snap.Hutao", "Snap.Hutao", "Resource"), + System.IO.Path.Combine(binPath, "Resource") + ); +}); + +Task("Build MSIX") + .IsDependentOn("Build binary package") + .IsDependentOn("Copy files") + .Does(() => +{ + var arguments = "arguments"; + if (AzurePipelines.IsRunningOnAzurePipelines) + { + arguments = "pack /d " + binPath + " /p " + System.IO.Path.Combine(outputPath, $"Snap.Hutao.Alpha-{version}.msix"); + } + else if (AppVeyor.IsRunningOnAppVeyor) + { + arguments = "pack /d " + binPath + " /p " + System.IO.Path.Combine(outputPath, $"Snap.Hutao-{version}.msix"); + } + var p = StartProcess( + "makeappx.exe", + new ProcessSettings + { + Arguments = arguments + } + ); + if (p != 0) + { + throw new InvalidOperationException("Build failed with exit code " + p); + } +}); + +RunTarget(target);