-
Notifications
You must be signed in to change notification settings - Fork 348
/
Copy pathShouldSkipPRBuild.ps1
52 lines (36 loc) · 1.28 KB
/
ShouldSkipPRBuild.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# Determine if the current PR payload requires a build.
# We skip the build if the only files changed are .md files.
function AllChangedFilesAreSkippable
{
Param($files)
$skipExts = @(".md", ".png", ".PNG")
$allFilesAreSkippable = $true
foreach($file in $files)
{
Write-Host "Checking '$file'"
$ext = [System.IO.Path]::GetExtension($file)
$fileIsSkippable = $ext -in $skipExts
Write-Host "File '$file' is skippable: '$fileIsSkippable'"
if(!$fileIsSkippable)
{
$allFilesAreSkippable = $false
}
}
return $allFilesAreSkippable
}
Set-StrictMode -Version 3.0
$ErrorActionPreference = 'Stop'
$shouldSkipBuild = $false
if($env:BUILD_REASON -eq "PullRequest")
{
$targetBranch = "origin/$env:SYSTEM_PULLREQUEST_TARGETBRANCH"
$gitCommandLine = "git diff $targetBranch --name-only"
Write-Host "$gitCommandLine"
$diffOutput = Invoke-Expression $gitCommandLine
Write-Host $diffOutput
$files = $diffOutput.Split([Environment]::NewLine)
Write-Host "Files changed: $files"
$shouldSkipBuild = AllChangedFilesAreSkippable($files)
}
Write-Host "shouldSkipBuild = $shouldSkipBuild"
Write-Host "##vso[task.setvariable variable=shouldSkipPRBuild;isOutput=true]$shouldSkipBuild"