-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBuildRDLFiles.yml
More file actions
79 lines (71 loc) · 2.82 KB
/
BuildRDLFiles.yml
File metadata and controls
79 lines (71 loc) · 2.82 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
67
68
69
70
71
72
73
74
75
76
77
78
79
stages:
- stage: Build
jobs:
- job: Build
pool:
name: 'SelfHostedPool'
steps:
# Download previous artifacts (if any)
- task: DownloadBuildArtifacts@1
displayName: 'Download previous manifest'
inputs:
buildType: 'specific'
project: '$(System.TeamProject)'
definition: '$(Build.DefinitionName)'
buildVersionToDownload: 'latestFromBranch'
branchName: 'refs/heads/main'
downloadPath: '$(Pipeline.Workspace)\previous'
continueOnError: true # first build won't have old manifest
# Compare + prepare changed RDLs
- task: PowerShell@2
displayName: 'Compare RDLs and prepare artifacts'
inputs:
targetType: inline
script: |
$rdlFolder = "$(Build.SourcesDirectory)\reports"
$artifactDir = "$(Build.ArtifactStagingDirectory)"
New-Item -ItemType Directory -Force -Path $artifactDir | Out-Null
# script block from above (compute hash + compare + copy)
$rdlFolder = "$(Build.SourcesDirectory)\reports"
$artifactDir = "$(Build.ArtifactStagingDirectory)"
$newManifestPath = Join-Path $artifactDir "rdl-manifest.json"
$newHashes = @()
Get-ChildItem -Path $rdlFolder -Filter *.rdl -File -Recurse | ForEach-Object {
$hash = Get-FileHash -Algorithm SHA256 -Path $_.FullName
$newHashes += [PSCustomObject]@{
FileName = $_.Name
RelativePath = $_.FullName.Substring($rdlFolder.Length+1)
Hash = $hash.Hash
FullPath = $_.FullName
}
}
$oldManifestPath = "$(Pipeline.Workspace)\previous\rdl\rdl-manifest.json"
$oldHashes = @()
if (Test-Path $oldManifestPath) {
$oldHashes = Get-Content $oldManifestPath | ConvertFrom-Json
}
$changed = @()
foreach ($n in $newHashes) {
$match = $oldHashes | Where-Object { $_.FileName -eq $n.FileName }
if (-not $match) {
Write-Host "NEW report: $($n.FileName)"
$changed += $n
}
elseif ($match.Hash -ne $n.Hash) {
Write-Host "CHANGED report: $($n.FileName)"
$changed += $n
}
else {
Write-Host "UNCHANGED report: $($n.FileName)"
}
}
foreach ($c in $changed) {
$targetPath = Join-Path $artifactDir $c.FileName
Copy-Item $c.FullPath $targetPath -Force
}
$newHashes | ConvertTo-Json -Depth 3 | Out-File $newManifestPath
- task: PublishBuildArtifacts@1
displayName: 'Publish changed RDLs'
inputs:
PathtoPublish: '$(Build.ArtifactStagingDirectory)'
ArtifactName: 'rdl'