-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDeploy-GitOpsBuild.ps1
More file actions
66 lines (61 loc) · 2.75 KB
/
Deploy-GitOpsBuild.ps1
File metadata and controls
66 lines (61 loc) · 2.75 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
56
57
58
59
60
61
62
63
64
65
66
Function Deploy-GitOpsBuild {
<#
.SYNOPSIS
Compares each file in the build directory with its representation in the
destination directory and copies the build directory file over if the
destination file does not match.
.DESCRIPTION
The 'Deploy-GitOpsBuild' function check each file in the build directory
against it's file in the destination directory. It checks for the file hash
of the Destination file. If the file is there and the hash matches the Build
hash, the file is not copied. Otherwise, the file is copied.
.PARAMETER Build
The Directory that will be parsed and copied from.
.PARAMETER Destination
The Directory that will be parsed and copied to.
.PARAMETER Source
Not Used in this function. Added for splatting purposes.
#>
[CmdletBinding(SupportsShouldProcess = $true)]
param(
[Parameter(Mandatory = $true)]
[ValidateScript( {
Test-Path $_ -PathType Container
})]
[String]
$Build,
[ValidateScript( {
Test-Path $_ -IsValid -PathType Container
})]
[String]
$Destination,
[String]
$Source
)
Process {
$BuildDirectory = Get-Item -Path $Build
If (-not $(Test-Path $Destination )) {
Write-Verbose "Creating $Destination directory"
New-Item $Destination -ItemType Directory | Write-Verbose
}
$DestinationDirectory = Get-Item $Destination
ForEach ($BuildFile in $(Get-ChildItem $BuildDirectory -Recurse -File)) {
$DestinationFile = @{
FullName = Join-Path -Path $DestinationDirectory.FullName -ChildPath $BuildFile.FullName.Replace($BuildDirectory.FullName,"")
Directory = Join-Path -Path $DestinationDirectory.FullName -ChildPath $BuildFile.Directory.Fullname.Replace($BuildDirectory.FullName, "")
}
$BuildFileHash = Get-FileHash $BuildFile
$DestinationFileHash = Get-FileHash $DestinationFile.FullName -ErrorAction SilentlyContinue
If ($DestinationFileHash -and ($BuildFileHash.Hash -eq $DestinationFileHash.Hash)) {
Write-Verbose "$($DestinationFileHash.Path) hash matches $($BuildFileHash.Path) hash, not copying."
} Else {
Write-Verbose "Copying $($BuildFile.FullName) to $($DestinationFile.FullName)"
if (-Not $(Test-Path $DestinationFile.Directory)) {
Write-Verbose "Creating $($DestinationFile.Directory) directory"
New-Item $DestinationFile.Directory -ItemType Directory | Write-Verbose
}
Copy-Item $BuildFile -Destination $DestinationFile.FullName
}
}
}
}