From 8b847425e8a9bde9f714ace2e55e331ba075727b Mon Sep 17 00:00:00 2001 From: David Guida <1432872+mizrael@users.noreply.github.com> Date: Thu, 25 Jan 2024 13:19:08 -0500 Subject: [PATCH] updated az pipeline (#521) --- azure-pipelines.yml | 16 ++++++++++++++-- targets/Program.cs | 34 ++++++++++++++++++++++++---------- 2 files changed, 38 insertions(+), 12 deletions(-) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 5c2fae7d..f633599a 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -115,7 +115,7 @@ jobs: inputs: command: 'run' projects: '$(Build.SourcesDirectory)/targets/targets.csproj' - arguments: '-- pack -c $(BuildConfiguration)' + arguments: '-- pack -c $(BuildConfiguration) -p .\src\PAModel\Microsoft.PowerPlatform.Formulas.Tools.csproj .\src\Microsoft.PowerPlatform.PowerApps.Persistence\Microsoft.PowerPlatform.PowerApps.Persistence.csproj' - task: SFP.build-tasks.custom-build-task-1.EsrpCodeSigning@3 displayName: 'ESRP sign nuget packages' @@ -144,10 +144,15 @@ jobs: ServiceEndpointUrl: 'https://api.esrp.microsoft.com/api/v1' - task: AzureArtifacts.manifest-generator-task.manifest-generator-task.ManifestGeneratorTask@0 - displayName: 'Generation Task' + displayName: 'PAModel Generation Task' inputs: BuildDropPath: '$(Build.SourcesDirectory)/bin/$(BuildConfiguration)/PAModel/' + - task: AzureArtifacts.manifest-generator-task.manifest-generator-task.ManifestGeneratorTask@0 + displayName: 'Persistence Generation Task' + inputs: + BuildDropPath: '$(Build.SourcesDirectory)/bin/$(BuildConfiguration)/Microsoft.PowerPlatform.PowerApps.Persistence/' + - task: PublishBuildArtifacts@1 inputs: PathtoPublish: '$(Build.SourcesDirectory)/bin/$(BuildConfiguration)/PAModel/' @@ -155,6 +160,13 @@ jobs: publishLocation: 'Container' condition: and(succeeded(), eq(variables['BuildConfiguration'], 'Release')) + - task: PublishBuildArtifacts@1 + inputs: + PathtoPublish: '$(Build.SourcesDirectory)/bin/$(BuildConfiguration)/Microsoft.PowerPlatform.PowerApps.Persistence/' + ArtifactName: 'Persistence Generation Task' + publishLocation: 'Container' + condition: and(succeeded(), eq(variables['BuildConfiguration'], 'Release')) + - task: PublishBuildArtifacts@1 inputs: PathtoPublish: '$(Build.SourcesDirectory)/pkg/PackResult' diff --git a/targets/Program.cs b/targets/Program.cs index 6d5ff436..1ce0fda8 100644 --- a/targets/Program.cs +++ b/targets/Program.cs @@ -2,7 +2,9 @@ // Licensed under the MIT License. using System; +using System.Collections.Generic; using System.IO; +using System.Linq; using System.Text.Json; using CommandLine; using SimpleExec; @@ -18,6 +20,9 @@ class Options [Option('c', "configuration", Required = false, Default = "Debug")] public string Configuration { get; set; } + + [Option('p', "projects", Required = false)] + public IEnumerable Projects { get; set; } } class Program @@ -26,10 +31,10 @@ class Program static void Main(string[] args) { - + string RootDir = "", gitHash = ""; bool gitExists = true; - try + try { RootDir = Read("git", "rev-parse --show-toplevel", noEcho: true).Trim(); gitHash = Read("git", "rev-parse HEAD", noEcho: true).Trim(); @@ -51,8 +56,8 @@ static void Main(string[] args) string PAModelDir = Path.Combine(SrcDir, "PAModel"); var solution = Path.Combine(SrcDir, "PASopa.sln"); - - var project = Path.Combine(PAModelDir, "Microsoft.PowerPlatform.Formulas.Tools.csproj"); + + var defaultPackProject = Path.Combine(PAModelDir, "Microsoft.PowerPlatform.Formulas.Tools.csproj"); Target("squeaky-clean", () => @@ -70,7 +75,8 @@ static void Main(string[] args) () => RunDotnet("restore", $"{EscapePath(solution)}", gitExists, LogDir)); Target("build", - () => { + () => + { if (gitExists) CreateBuildHashFile(ObjDir, gitHash); RunDotnet("build", $"{EscapePath(solution)} --configuration {options.Configuration} --no-restore", gitExists, LogDir); @@ -83,7 +89,13 @@ static void Main(string[] args) DependsOn("restore", "build")); Target("pack", - () => RunDotnet("pack", $"{EscapePath(project)} --configuration {options.Configuration} --output {EscapePath(Path.Combine(PkgDir, "PackResult"))} --no-build -p:Packing=true", gitExists, LogDir)); + () => + { + var projects = (options.Projects.Any()) ? options.Projects : new[]{ defaultPackProject }; + + foreach (var project in projects) + RunDotnet("pack", $"{EscapePath(project)} --configuration {options.Configuration} --output {EscapePath(Path.Combine(PkgDir, "PackResult"))} --no-build -p:Packing=true", gitExists, LogDir); + }); Target("ci", DependsOn("squeaky-clean", "rebuild", "test")); @@ -92,7 +104,7 @@ static void Main(string[] args) .WithParsed(o => { options = o; - RunTargetsAndExit(new[] {options.Target}, + RunTargetsAndExit(new[] { options.Target }, logPrefix: options.Target, messageOnly: ex => ex is NonZeroExitCodeException); }) @@ -105,7 +117,7 @@ static void Main(string[] args) static void RunDotnet(string verb, string verbArgs, bool gitExists, string LogDir) { var gitDef = ""; - if (gitExists) + if (gitExists) gitDef = "-p:GitExists=true"; var optionsLogPath = Path.Combine(LogDir, $"{verb}-{options.Configuration}"); var logSettings = $"/clp:verbosity=minimal /flp:Verbosity=normal;LogFile={EscapePath(optionsLogPath + ".log")} /flp3:PerformanceSummary;Verbosity=diag;LogFile={EscapePath(optionsLogPath + ".diagnostics.log")}"; @@ -118,7 +130,8 @@ static void CreateBuildHashFile(string objDir, string gitHash) var file = new System.IO.FileInfo(filePath); file.Directory.Create(); - var jsonContents = new { + var jsonContents = new + { CommitHash = gitHash, #if !ADOBuild IsLocalBuild = true @@ -132,7 +145,8 @@ static void CleanDirectory(string directoryPath) { directoryPath = Path.GetFullPath(directoryPath); Console.WriteLine($"Cleaning directory: {directoryPath}"); - try { + try + { if (Directory.Exists(directoryPath)) { Directory.Delete(directoryPath, recursive: true);