-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheck-GitDevOpsFiles.ps1
More file actions
56 lines (44 loc) · 1.48 KB
/
Copy pathcheck-GitDevOpsFiles.ps1
File metadata and controls
56 lines (44 loc) · 1.48 KB
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
53
54
55
function check-GitDevOpsFiles {
param (
[Parameter(Mandatory = $true)]
[hashtable]$params,
[Parameter(Mandatory = $true)]
[hashtable]$result
)
try {
Set-Location $params.RepoPath
$devopsFiles = @("*azure*.yml", "*.yml", ".github/workflows/*", ".gitlab-ci.yml", "Jenkinsfile", "circle.yml", ".travis.yml", "bamboo-specs/bamboo.yml", "azure-pipelines.yml")
# Get a list of all blob paths in the repo, across all branches
$blobs = @()
git ls-tree -r HEAD | ForEach-Object {
$permissions, $type, $hash, $path = $_ -split '\s+', 4
if ($type -eq "blob") {
$size = git cat-file -s $hash
$item = @{
'Hash' = $hash
'Path' = $path
'Size' = $size
}
$blobs += $item
}
}
$automationFiles = @()
foreach ($blob in $blobs) {
foreach ($file in $devopsFiles) {
if ($blob.Path -like $file) {
Write-Host ("Found: $file")
$automationFiles += $blob
break;
}
}
}
$result.Value = $automationFiles
$result.Success = $true
$result.Comment = "The repo contains "+$automationFiles.Count + " DevOps file(s)."
}
catch {
$result.Success = $false
$result.Comment = "Error: $($_.Exception.Message)"
}
return $result
}