Skip to content

Add check for change log update in PRs #6342

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 1 commit into from
Jun 9, 2018
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
47 changes: 30 additions & 17 deletions build.proj
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
Condition=" '$(Scope)' == 'AzureStorage' "/>
<CmdletSolutionsToBuild Include=".\src\Stack.sln"
Condition=" '$(Stack)' == 'true' "/>

<StaticAnalysis Include=".\tools\StaticAnalysis\StaticAnalysis.sln" />
<LocalBuildTasks Include="$(LibraryToolsFolder)\BuildPackagesTask\Microsoft.Azure.Build.Tasks.sln" />
<LocalBuildTasks Include="$(LibraryToolsFolder)\RepoTasks\RepoTasks.sln" Condition="'$(NetCore)' == 'false'"/>
Expand Down Expand Up @@ -204,26 +204,28 @@
</FilesChangedTask>

<!-- Get the list of modules changed -->
<FilterTask FilesChanged="@(FilesChanged)" MapFilePath=".\ModuleMappings.json">
<Output TaskParameter="Output" ItemName="ModulesChanged"/>
</FilterTask>
<Message Text="Filtering help generation and StaticAnalysis by the following modules:"/>
<Message Text="%(ModulesChanged.Identity)"/>
<Message Text="Total: @(ModulesChanged->Count())"/>
<Message Text=""/>

<!--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.-->
<FilterTask FilesChanged="@(FilesChanged)" MapFilePath=".\TestMappings.json">
<Output TaskParameter="Output" ItemName="XUnitTests"/>
</FilterTask>
<Message Text="Using these test assemblies:"/>
<Message Text="%(XUnitTests.Identity)"/>
<Message Text="Total: @(XunitTests->Count())"/>
<Message Text=""/>
<FilterTask FilesChanged="@(FilesChanged)" MapFilePath=".\ModuleMappings.json">
<Output TaskParameter="Output" ItemName="ModulesChanged"/>
</FilterTask>
<Message Text="Filtering help generation and StaticAnalysis by the following modules:"/>
<Message Text="%(ModulesChanged.Identity)"/>
<Message Text="Total: @(ModulesChanged->Count())"/>
<Message Text=""/>

<!--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.-->
<FilterTask FilesChanged="@(FilesChanged)" MapFilePath=".\TestMappings.json">
<Output TaskParameter="Output" ItemName="XUnitTests"/>
</FilterTask>
<Message Text="Using these test assemblies:"/>
<Message Text="%(XUnitTests.Identity)"/>
<Message Text="Total: @(XunitTests->Count())"/>
<Message Text=""/>
</Target>

<!-- Build all flavors of the Cmdlets -->
<Target Name="Build" DependsOnTargets="RestoreNugetPackages;BuildMsBuildTask;FilterBuild">
<CallTarget targets="ChangeLogCheck" ContinueOnError="false" />

<Message Importance="high" Text="Building Cmdlets..." />

<MakeDir Directories="$(PackageDirectory)" />
Expand Down Expand Up @@ -506,6 +508,17 @@
<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"/>
</Target>

<Target Name="ChangeLogCheck">
<Exec Command="&quot;$(PowerShellCommand)&quot; -NonInteractive -NoLogo -NoProfile -Command &quot;. $(LibraryToolsFolder)\CheckChangeLog.ps1 -FilesChanged '@(FilesChanged)' &quot;"
ContinueOnError="false"
Condition="'$(Latest)' == 'true'"/>
<OnError ExecuteTargets="ChangeLogErrorMessage"/>
</Target>

<Target Name="ChangeLogErrorMessage">
<Error Text="Modified files were found with no update to their change log. Please add a snippet to the affected modules' change log."/>
</Target>

<!-- Publish all packages -->
<Target Name="Publish">
<Error Condition=" '$(NuGetKey)' == '' " Text="You must provide the NuGetKey parameter to the build: /p:NuGetKey=YOUR_PUBLISHING_KEY" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ function Invoke-SafeWebRequest{
{
Write-Debug "Sending query to the server..."
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
$jsonResult = Invoke-WebRequest $Query -ErrorAction Stop
$jsonResult = Invoke-WebRequest $Query -ErrorAction Stop -UseBasicParsing
}
catch
{
Expand Down
71 changes: 71 additions & 0 deletions tools/CheckChangeLog.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
[CmdletBinding()]
Param
(
[Parameter()]
[string]$FilesChanged
)

if ([string]::IsNullOrEmpty($FilesChanged))
{
Write-Host "The list of files changed is empty; skipping check for change log entry"
return
}

$PathsToCheck = @(
"src/Common",
"src/ResourceManager",
"src/ServiceManagement",
"src/Storage"
)

$PathStringsToIgnore = @(
"Test"
)

$FilesChangedList = $FilesChanged -split ';'
$ChangeLogs = $FilesChangedList | where { $_ -like "*ChangeLog.md*" }
$UpdatedServicePaths = New-Object System.Collections.Generic.HashSet[string]
foreach ($ChangeLog in $ChangeLogs)
{
if ($ChangeLog -like "src/ServiceManagement*")
{
$UpdatedServicePaths.Add("src/ServiceManagement") | Out-Null
}
elseif ($ChangeLog -like "src/Storage*")
{
$UpdatedServicePaths.Add("src/Storage") | Out-Null
}
else
{
# Handle ResourceManager to construct a string like "src/ResourceManager/{{service}}"
$SplitPath = $ChangeLog -split '/'
$BasePath = $SplitPath[0],$SplitPath[1],$SplitPath[2] -join "/"
$UpdatedServicePaths.Add($BasePath) | Out-Null
}
}

foreach ($File in $FilesChangedList)
{
if ($File -like "*ChangeLog.md*")
{
continue
}

# If a file in src/Common is updated, check for change log entry in Profile
if ($File.StartsWith("src/Common") -and ($UpdatedServicePaths | where { $_ -like "*Profile*" } | Measure-Object).Count -gt 0)
{
continue
}

if (($PathsToCheck | where { $File.StartsWith($_) } | Measure-Object).Count -gt 0 -and `
($PathStringsToIgnore | where { $File -like "*$_*" } | Measure-Object).Count -eq 0 -and `
($UpdatedServicePaths | where { $File.StartsWith($_) } | Measure-Object).Count -eq 0)
{
$FlaggedFiles += $File
}
}

if ($FlaggedFiles.Count -gt 0)
{
throw "Modified files were found with no update to their change log. Please add a snippet to the affected modules' change log."
}