Skip to content

[Tools] Update tools to compatible CI pipeline for generation branch #15276

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 20 additions & 7 deletions .ci-config.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
{
"rules": [
{
"patterns": [
"src/{ModuleName}/readme.md",
"src/{ModuleName}[a-zA-Z`.`/]*/readme.md"
],
"phases": [
"build:related-module",
"breaking-change:module",
"help:module",
"signature:module",
"test:dependence-module"
]
},
{
"patterns": [
".azure-pipeline/*",
Expand Down Expand Up @@ -96,10 +109,10 @@
},
{
"patterns": [
"tools/StaticAnalysis/Exceptions/{ModuleName}/MissingAssemblies.csv",
"tools/StaticAnalysis/Exceptions/{ModuleName}/AssemblyVersionConflict.csv",
"tools/StaticAnalysis/Exceptions/{ModuleName}/ExtraAssemblies.csv",
"tools/StaticAnalysis/Exceptions/{ModuleName}/SharedAssemblyConflict.csv"
"tools/StaticAnalysis/Exceptions/Az.{ModuleName}/MissingAssemblies.csv",
"tools/StaticAnalysis/Exceptions/Az.{ModuleName}/AssemblyVersionConflict.csv",
"tools/StaticAnalysis/Exceptions/Az.{ModuleName}/ExtraAssemblies.csv",
"tools/StaticAnalysis/Exceptions/Az.{ModuleName}/SharedAssemblyConflict.csv"
],
"phases": [
"build:module",
Expand All @@ -108,7 +121,7 @@
},
{
"patterns": [
"tools/StaticAnalysis/Exceptions/{ModuleName}/BreakingChangeIssues.csv"
"tools/StaticAnalysis/Exceptions/Az.{ModuleName}/BreakingChangeIssues.csv"
],
"phases": [
"build:module",
Expand All @@ -117,7 +130,7 @@
},
{
"patterns": [
"tools/StaticAnalysis/Exceptions/{ModuleName}/HelpIssues.csv"
"tools/StaticAnalysis/Exceptions/Az.{ModuleName}/HelpIssues.csv"
],
"phases": [
"build:module",
Expand All @@ -126,7 +139,7 @@
},
{
"patterns": [
"tools/StaticAnalysis/Exceptions/{ModuleName}/SignatureIssues.csv"
"tools/StaticAnalysis/Exceptions/Az.{ModuleName}/SignatureIssues.csv"
],
"phases": [
"build:module",
Expand Down
6 changes: 5 additions & 1 deletion build.proj
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
<Configuration Condition="'$(Configuration)' != 'Release'">Debug</Configuration>
<Scope Condition="$(Scope) == ''">All</Scope>
<TestFramework Condition="'$(TestFramework)' == ''">netcoreapp2.2</TestFramework>
<IsGenerateBased Condition="'$(IsGenerateBased)' != 'true'">false</IsGenerateBased>

<!-- Flags -->
<CodeSign Condition ="'$(CodeSign)' == ''">false</CodeSign>
Expand Down Expand Up @@ -108,8 +109,8 @@

<Target Name="FilterBuild" Condition="$(PullRequestNumber) != '' OR $(TargetModule) != ''" DependsOnTargets="BuildTools">
<Message Importance="high" Text="Filtering projects and modules..." />
<Exec Command="$(PowerShellCoreCommandPrefix) &quot;. $(RepoTools)/CreateFilterMappings.ps1&quot;" />

<Message Text="$(IsGenerateBased)" />
<!-- Build the Microsoft.Azure.Build.Tasks project -->
<Exec Command="dotnet publish $(RepoTools)BuildPackagesTask/Microsoft.Azure.Build.Tasks/Microsoft.Azure.Build.Tasks.csproj -c $(Configuration)" />

Expand All @@ -118,6 +119,9 @@
<Output TaskParameter="FilesChanged" ItemName="FilesChanged" />
</FilesChangedTask>

<Exec Command="$(PowerShellCoreCommandPrefix) &quot;$(RepoTools)PrepareAutorestModule.ps1&quot;" Condition="'$(IsGenerateBased)' == 'true'"/>
<Exec Command="$(PowerShellCoreCommandPrefix) &quot;. $(RepoTools)/CreateFilterMappings.ps1&quot;" />

<CIFilterTask FilesChanged="@(FilesChanged)" TargetModule="$(TargetModule)" Mode="$(Configuration)" CsprojMapFilePath="./CsprojMappings.json">
<Output TaskParameter="FilterTaskResult" ItemName="FilterTaskResult" />
</CIFilterTask>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
namespace Microsoft.WindowsAzure.Build.Tasks
{
using System;
using System.IO;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using Microsoft.Build.Framework;
Expand Down Expand Up @@ -142,7 +143,15 @@ public override bool Execute()
FilesChanged = new string[] { };
}

SerializeChangedFilesToFile(FilesChanged);

return true;
}

// This method will record the changed files into FilesChanged.txt under root folder for other task to consum.
private void SerializeChangedFilesToFile(string[] FilesChanged)
{
File.WriteAllLines("FilesChanged.txt", FilesChanged);
}
}
}
2 changes: 1 addition & 1 deletion tools/CreateFilterMappings.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ function Create-SolutionToProjectMappings
$Mappings = [ordered]@{}
foreach ($ServiceFolder in $Script:ServiceFolders)
{
$SolutionFiles = Get-ChildItem -Path $ServiceFolder.FullName -Filter "*.sln"
$SolutionFiles = Get-ChildItem -Path $ServiceFolder.FullName -Filter "*.sln" -Recurse
foreach ($SolutionFile in $SolutionFiles)
{
$Mappings = Add-ProjectDependencies -Mappings $Mappings -SolutionPath $SolutionFile.FullName
Expand Down
58 changes: 51 additions & 7 deletions tools/Gen2Master/MoveFromGeneration2Master.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,25 @@ Function Move-Generation2Master {
)

process {
$ModuleName = ($SourcePath.Trim("\").Split("\"))[-1]
#Region Handle the hybrid module whoes folder is a subfolder of the module folder.
$ModuleName = $SourcePath.Replace('/', '\').Split('\src\')[1].Split('\')[0]
$SourcePsd1Path = Get-ChildItem -path $ModuleFolder -filter Az.$ModuleName.psd1 -Recurse
$FolderPathRelativeToSrc = $SourcePsd1Path.Directory.FullName.Replace('/', '\').Split('\src\')[1]
if ($FolderPathRelativeToSrc -eq $ModuleName)
{
$IsHybridModule = $False
}
else
{
$IsHybridModule = $True
}
$SourcePath = $SourcePsd1Path.Directory.FullName
If (-not ($DestPath.Trim("\").Split("\")[-1] -eq $ModuleName)) {
$DestPath = Join-Path -Path $DestPath -ChildPath $ModuleName
$DestPath = Join-Path -Path $DestPath -ChildPath $FolderPathRelativeToSrc
}
#EndRegion
If (-not (Test-Path $DestPath)) {
New-Item -ItemType Directory -Path $DestPath
New-Item -ItemType Directory -Path $DestPath -Force
}
$Dir2Copy = @('custom', 'examples', 'exports', 'generated', 'internal', 'test', 'utils')
Foreach($Dir in $Dir2Copy) {
Expand Down Expand Up @@ -64,7 +77,8 @@ Function Move-Generation2Master {
$Psd1Version = $Psd1Metadata.ModuleVersion
}
$Psd1Metadata = Import-LocalizedData -BaseDirectory $SourcePath -FileName "Az.$ModuleName.psd1"
if ($Null -ne $Psd1Version) {
If ($Null -ne $Psd1Version)
{
$Psd1Metadata.ModuleVersion = $Psd1Version
}
If ($Null -ne $ModuleGuid) {
Expand All @@ -76,7 +90,10 @@ Function Move-Generation2Master {
$AccountsMetadata = Import-LocalizedData -BaseDirectory $AccountsModulePath -FileName "Az.Accounts.psd1"
$RequiredModule = @(@{ModuleName = 'Az.Accounts'; ModuleVersion = $AccountsMetadata.ModuleVersion; })
}
$Psd1Metadata.RequiredModules = $RequiredModule
If ($Null -ne $RequiredModule)
{
$Psd1Metadata.RequiredModules = $RequiredModule
}
If ($Psd1Metadata.FunctionsToExport -Contains "*") {
$Psd1Metadata.FunctionsToExport = ($Psd1Metadata.FunctionsToExport | Where-Object {$_ -ne "*"})
}
Expand Down Expand Up @@ -143,9 +160,36 @@ Function Move-Generation2Master {
Set-Content -Path $GeneratedModuleListPath -Value $NewModules
#EndRegion

Copy-Template -SourceName Az.ModuleName.csproj -DestPath $DestPath -DestName "Az.$ModuleName.csproj"
if ($IsHybridModule)
{
Copy-Template -SourceName Az.ModuleName.hybrid.csproj -DestPath $DestPath -DestName "Az.$ModuleName.csproj"
}
else
{
Copy-Template -SourceName Az.ModuleName.csproj -DestPath $DestPath -DestName "Az.$ModuleName.csproj"
}
Copy-Template -SourceName Changelog.md -DestPath $DestPath -DestName Changelog.md
Copy-Template -SourceName ModuleName.sln -DestPath $DestPath -DestName "$ModuleName.sln"
#Region create a solution file for module and add the related csproj files to this solution.
dotnet new sln -n $ModuleName -o $DestPath
$DestParentPath = $DestPath
While ("" -eq $DestParentPath)
{
$DestAccountsPath = Get-ChildItem -Path $DestParentPath -Filter Accounts
if ($Null -eq $DestAccountsPath)
{
$DestParentPath = Split-Path -path $DestParentPath -Parent
}
else
{
Break
}
}
$SolutionPath = Join-Path -Path $DestPath -ChildPath $ModuleName.sln
foreach ($DependenceCsproj in (Get-ChildItem -path $DestAccountsPath -Recurse -Filter *.csproj -Exclude *test*))
{
dotnet sln $SolutionPath add $DependenceCsproj
}
#EndRegion

$PropertiesPath = Join-Path -Path $DestPath -ChildPath "Properties"
If (-not (Test-Path $PropertiesPath)) {
Expand Down
2 changes: 1 addition & 1 deletion tools/Gen2Master/Templates/Az.ModuleName.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
<PsModuleName>{ModuleNamePlaceHolder}</PsModuleName>
</PropertyGroup>

<Import Project="$(MSBuildThisFileDirectory)..\Az.autorest.props" />
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory).., build.proj))\src\Az.autorest.props" />
</Project>
7 changes: 7 additions & 0 deletions tools/Gen2Master/Templates/Az.ModuleName.hybrid.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<PsModuleName>{ModuleNamePlaceHolder}</PsModuleName>
</PropertyGroup>

<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory).., build.proj))\src\Az.autorest.hybrid.props" />
</Project>
86 changes: 86 additions & 0 deletions tools/PrepareAutorestModule.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
# ----------------------------------------------------------------------------------
#
# Copyright Microsoft Corporation
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ----------------------------------------------------------------------------------

#This script will pack build artifacts under temporary folder "artifacts/tmp" and output Az.*.nupkg to "artifacts"


param(
)
$ChangedFiles = Get-Content -Path "$PSScriptRoot\..\FilesChanged.txt"

$ALL_MODULE = "ALL_MODULE"

#Region Detect which module should be processed
$ModuleSet = New-Object System.Collections.Generic.HashSet[string]
foreach ($file in $ChangedFiles)
{
$ParentFolder = Split-Path -Path $file -Parent
if ($ParentFolder.StartsWith("src"))
{
if ($ParentFolder -eq "src")
{
$NUll = $ModuleSet.Add($ALL_MODULE)
}
else
{
$NUll = $ModuleSet.Add($ParentFolder.Replace("/", "\").Split('\')[1])
}
}
else
{
$NUll = $ModuleSet.Add($ALL_MODULE)
}
}
if ($ModuleSet.Contains($ALL_MODULE))
{
$ModuleList = (Get-ChildItem "$PSScriptRoot\..\src\" -Directory).Name
}
else
{
$ModuleList = $ModuleSet | Where-Object { $_ }
}
#EndRegion

Import-Module "$PSScriptRoot\..\tools\Gen2Master\MoveFromGeneration2Master.ps1" -Force
$TmpFolder = "$PSScriptRoot\..\tmp"
New-Item -ItemType Directory -Force -Path $TmpFolder
Remove-Item -Path "$TmpFolder\*" -Recurse -Force

#Region Clone latest Az.Accounts code
Set-Location -Path $TmpFolder
git init
git remote add -f origin https://github.com/Azure/azure-powershell.git
git config core.sparseCheckout true
Add-Content -Path .git/info/sparse-checkout -Value "src/Accounts/"
git pull origin main
Move-Item -Path "$TmpFolder\src\Accounts" -Destination "$TmpFolder\Accounts"
#EndRegion

#Region generate the code and make the struture same with main branch.
foreach ($Module in $ModuleList)
{
$ModuleFolder = "$PSScriptRoot\..\src\$Module\"
$ModuleFolder = (Get-ChildItem -path $ModuleFolder -filter Az.$Module.psd1 -Recurse).Directory
if ($Null -eq $ModuleFolder)
{
Throw "Cannot find Az.$Module.psd1 in $ModuleFolder."
}
Set-Location -Path $ModuleFolder
autorest
./build-module.ps1
Move-Generation2Master -SourcePath "$PSScriptRoot\..\src\$Module\" -DestPath $TmpFolder
Remove-Item "$ModuleFolder\*" -Recurse
}
#EndRegion
Copy-Item "$TmpFolder\*" "$PSScriptRoot\..\src" -Recurse -Force
2 changes: 1 addition & 1 deletion tools/UpdateModules.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ function New-ModulePsm1 {
PROCESS {
$manifestDir = Get-Item -Path $ModulePath
$moduleName = $manifestDir.Name + ".psd1"
$manifestPath = Join-Path -Path $ModulePath -ChildPath $moduleName
$manifestPath = Get-ChildItem -Path $manifestDir -Filter $moduleName -Recurse
$file = Get-Item $manifestPath
Import-LocalizedData -BindingVariable ModuleMetadata -BaseDirectory $file.DirectoryName -FileName $file.Name

Expand Down