From f4d23d617435da583136a2f2b15fcc49694a6757 Mon Sep 17 00:00:00 2001 From: qhy040404 Date: Fri, 8 Dec 2023 16:39:36 +0800 Subject: [PATCH] better abstract --- azure-pipelines.yml | 15 +++++---------- build.cake | 44 ++++++++++++++++++++++++++++++++++++-------- 2 files changed, 41 insertions(+), 18 deletions(-) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index a4ca8a38..1f4b7cdf 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -46,11 +46,6 @@ variables: steps: -- task: GetRevision@1 - displayName: get Pipelines revision number - inputs: - VariableName: 'rev_number' - - task: UseDotNet@2 displayName: Install dotNet inputs: @@ -61,7 +56,7 @@ steps: - task: CmdLine@2 displayName: dotnet cake inputs: - script: dotnet tool restore && dotnet cake --Version=$(build_date).$(rev_number) --pw=$(pw) + script: dotnet tool restore && dotnet cake --pw=$(pw) - task: DownloadSecureFile@1 name: cerFile @@ -81,8 +76,8 @@ steps: action: 'create' target: '$(Build.SourceVersion)' tagSource: 'userSpecifiedTag' - tag: '$(build_date).$(rev_number)' - title: '$(build_date).$(rev_number)' + tag: '$(version)' + title: '$(version)' releaseNotesSource: 'inline' releaseNotesInline: | ## 普通用户请勿下载 @@ -102,12 +97,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 index aa282fe7..1e9ece3f 100644 --- a/build.cake +++ b/build.cake @@ -1,20 +1,48 @@ #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"); -var version = HasArgument("Version") ? Argument("Version") : throw new Exception("Empty Version"); +var versionAuth = HasEnvironmentVariable("VERSION_API_TOKEN") ? EnvironmentVariable("VERSION_API_TOKEN") : throw new Exception("Cannot find VERSION_API_TOKEN"); +var version = HttpGet( + "https://internal.snapgenshin.cn/BuildIntergration/RequestNewVersion", + new HttpSettings + { + Headers = new Dictionary + { + { "Authorization", versionAuth } + } + } + ); +Information($"Version: {version}"); + var pw = HasArgument("pw") ? Argument("pw") : throw new Exception("Empty pw"); -// Default Azure Pipelines +// Pre-define -var repoDir = AzurePipelines.Environment.Build.SourcesDirectory.FullPath; -var outputPath = AzurePipelines.Environment.Build.ArtifactStagingDirectory.FullPath; +var repoDir = "repoDir"; +var outputPath = "outputPath"; -var solution = System.IO.Path.Combine(repoDir, "src", "Snap.Hutao", "Snap.Hutao.sln"); -var project = System.IO.Path.Combine(repoDir, "src", "Snap.Hutao", "Snap.Hutao", "Snap.Hutao.csproj"); -var binPath = System.IO.Path.Combine(repoDir, "src", "Snap.Hutao", "Snap.Hutao", "bin", "x64", "Release", "net8.0-windows10.0.22621.0", "win-x64"); +var solution = "solution"; +var project = "project"; +var binPath = "binPath"; -var pfxFile = System.IO.Path.Combine(AzurePipelines.Environment.Agent.HomeDirectory.FullPath, "_work", "_temp", "DGP_Studio_CI.pfx"); +var pfxFile = "pfxFile"; + +if (AzurePipelines.IsRunningOnAzurePipelines) +{ + AzurePipelines.Commands.SetVariable("version", version); + + repoDir = AzurePipelines.Environment.Build.SourcesDirectory.FullPath; + outputPath = AzurePipelines.Environment.Build.ArtifactStagingDirectory.FullPath; + + solution = System.IO.Path.Combine(repoDir, "src", "Snap.Hutao", "Snap.Hutao.sln"); + project = System.IO.Path.Combine(repoDir, "src", "Snap.Hutao", "Snap.Hutao", "Snap.Hutao.csproj"); + binPath = System.IO.Path.Combine(repoDir, "src", "Snap.Hutao", "Snap.Hutao", "bin", "x64", "Release", "net8.0-windows10.0.22621.0", "win-x64"); + + pfxFile = System.IO.Path.Combine(AzurePipelines.Environment.Agent.HomeDirectory.FullPath, "_work", "_temp", "DGP_Studio_CI.pfx"); +} Task("Build") .IsDependentOn("Build binary package")