Skip to content

Commit c451882

Browse files
committed
Add check for change log entry to build
1 parent ce5128c commit c451882

File tree

3 files changed

+102
-18
lines changed

3 files changed

+102
-18
lines changed

build.proj

Lines changed: 30 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@
6868
Condition=" '$(Scope)' == 'AzureStorage' "/>
6969
<CmdletSolutionsToBuild Include=".\src\Stack.sln"
7070
Condition=" '$(Stack)' == 'true' "/>
71-
71+
7272
<StaticAnalysis Include=".\tools\StaticAnalysis\StaticAnalysis.sln" />
7373
<LocalBuildTasks Include="$(LibraryToolsFolder)\BuildPackagesTask\Microsoft.Azure.Build.Tasks.sln" />
7474
<LocalBuildTasks Include="$(LibraryToolsFolder)\RepoTasks\RepoTasks.sln" Condition="'$(NetCore)' == 'false'"/>
@@ -204,26 +204,28 @@
204204
</FilesChangedTask>
205205

206206
<!-- Get the list of modules changed -->
207-
<FilterTask FilesChanged="@(FilesChanged)" MapFilePath=".\ModuleMappings.json">
208-
<Output TaskParameter="Output" ItemName="ModulesChanged"/>
209-
</FilterTask>
210-
<Message Text="Filtering help generation and StaticAnalysis by the following modules:"/>
211-
<Message Text="%(ModulesChanged.Identity)"/>
212-
<Message Text="Total: @(ModulesChanged->Count())"/>
213-
<Message Text=""/>
214-
215-
<!--Get the list of tests to be run based on files changed from a specified PullRequestNumber. Mapping between paths and test DLLs is used to produce the list.-->
216-
<FilterTask FilesChanged="@(FilesChanged)" MapFilePath=".\TestMappings.json">
217-
<Output TaskParameter="Output" ItemName="XUnitTests"/>
218-
</FilterTask>
219-
<Message Text="Using these test assemblies:"/>
220-
<Message Text="%(XUnitTests.Identity)"/>
221-
<Message Text="Total: @(XunitTests->Count())"/>
222-
<Message Text=""/>
207+
<FilterTask FilesChanged="@(FilesChanged)" MapFilePath=".\ModuleMappings.json">
208+
<Output TaskParameter="Output" ItemName="ModulesChanged"/>
209+
</FilterTask>
210+
<Message Text="Filtering help generation and StaticAnalysis by the following modules:"/>
211+
<Message Text="%(ModulesChanged.Identity)"/>
212+
<Message Text="Total: @(ModulesChanged->Count())"/>
213+
<Message Text=""/>
214+
215+
<!--Get the list of tests to be run based on files changed from a specified PullRequestNumber. Mapping between paths and test DLLs is used to produce the list.-->
216+
<FilterTask FilesChanged="@(FilesChanged)" MapFilePath=".\TestMappings.json">
217+
<Output TaskParameter="Output" ItemName="XUnitTests"/>
218+
</FilterTask>
219+
<Message Text="Using these test assemblies:"/>
220+
<Message Text="%(XUnitTests.Identity)"/>
221+
<Message Text="Total: @(XunitTests->Count())"/>
222+
<Message Text=""/>
223223
</Target>
224224

225225
<!-- Build all flavors of the Cmdlets -->
226226
<Target Name="Build" DependsOnTargets="RestoreNugetPackages;BuildMsBuildTask;FilterBuild">
227+
<CallTarget targets="ChangeLogCheck" ContinueOnError="false" />
228+
227229
<Message Importance="high" Text="Building Cmdlets..." />
228230

229231
<MakeDir Directories="$(PackageDirectory)" />
@@ -506,6 +508,17 @@
506508
<Error Text="StaticAnalysis has failed. Please follow the instructions on this doc: https://github.com/Azure/azure-powershell/blob/preview/documentation/Debugging-StaticAnalysis-Errors.md"/>
507509
</Target>
508510

511+
<Target Name="ChangeLogCheck">
512+
<Exec Command="&quot;$(PowerShellCommand)&quot; -NonInteractive -NoLogo -NoProfile -Command &quot;. $(LibraryToolsFolder)\CheckChangeLog.ps1 -FilesChanged '@(FilesChanged)' &quot;"
513+
ContinueOnError="false"
514+
Condition="'$(Latest)' == 'true'"/>
515+
<OnError ExecuteTargets="ChangeLogErrorMessage"/>
516+
</Target>
517+
518+
<Target Name="ChangeLogErrorMessage">
519+
<Error Text="Modified files were found with no update to their change log. Please add a snippet to the affected modules' change log."/>
520+
</Target>
521+
509522
<!-- Publish all packages -->
510523
<Target Name="Publish">
511524
<Error Condition=" '$(NuGetKey)' == '' " Text="You must provide the NuGetKey parameter to the build: /p:NuGetKey=YOUR_PUBLISHING_KEY" />

tools/BuildPackagesTask/Microsoft.Azure.Build.Tasks/GetPullRequestFileChanges.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ function Invoke-SafeWebRequest{
4646
{
4747
Write-Debug "Sending query to the server..."
4848
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
49-
$jsonResult = Invoke-WebRequest $Query -ErrorAction Stop
49+
$jsonResult = Invoke-WebRequest $Query -ErrorAction Stop -UseBasicParsing
5050
}
5151
catch
5252
{

tools/CheckChangeLog.ps1

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
[CmdletBinding()]
2+
Param
3+
(
4+
[Parameter()]
5+
[string]$FilesChanged
6+
)
7+
8+
if ([string]::IsNullOrEmpty($FilesChanged))
9+
{
10+
Write-Host "The list of files changed is empty; skipping check for change log entry"
11+
return
12+
}
13+
14+
$PathsToCheck = @(
15+
"src/Common",
16+
"src/ResourceManager",
17+
"src/ServiceManagement",
18+
"src/Storage"
19+
)
20+
21+
$PathStringsToIgnore = @(
22+
"Test"
23+
)
24+
25+
$FilesChangedList = $FilesChanged -split ';'
26+
$ChangeLogs = $FilesChangedList | where { $_ -like "*ChangeLog.md*" }
27+
$UpdatedServicePaths = New-Object System.Collections.Generic.HashSet[string]
28+
foreach ($ChangeLog in $ChangeLogs)
29+
{
30+
if ($ChangeLog -like "src/ServiceManagement*")
31+
{
32+
$UpdatedServicePaths.Add("src/ServiceManagement") | Out-Null
33+
}
34+
elseif ($ChangeLog -like "src/Storage*")
35+
{
36+
$UpdatedServicePaths.Add("src/Storage") | Out-Null
37+
}
38+
else
39+
{
40+
# Handle ResourceManager to construct a string like "src/ResourceManager/{{service}}"
41+
$SplitPath = $ChangeLog -split '/'
42+
$BasePath = $SplitPath[0],$SplitPath[1],$SplitPath[2] -join "/"
43+
$UpdatedServicePaths.Add($BasePath) | Out-Null
44+
}
45+
}
46+
47+
foreach ($File in $FilesChangedList)
48+
{
49+
if ($File -like "*ChangeLog.md*")
50+
{
51+
continue
52+
}
53+
54+
# If a file in src/Common is updated, check for change log entry in Profile
55+
if ($File.StartsWith("src/Common") -and ($UpdatedServicePaths | where { $_ -like "*Profile*" } | Measure-Object).Count -gt 0)
56+
{
57+
continue
58+
}
59+
60+
if (($PathsToCheck | where { $File.StartsWith($_) } | Measure-Object).Count -gt 0 -and `
61+
($PathStringsToIgnore | where { $File -like "*$_*" } | Measure-Object).Count -eq 0 -and `
62+
($UpdatedServicePaths | where { $File.StartsWith($_) } | Measure-Object).Count -eq 0)
63+
{
64+
$FlaggedFiles += $File
65+
}
66+
}
67+
68+
if ($FlaggedFiles.Count -gt 0)
69+
{
70+
throw "Modified files were found with no update to their change log. Please add a snippet to the affected modules' change log."
71+
}

0 commit comments

Comments
 (0)