This repository has been archived by the owner on Jul 17, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 18
/
build-helpers.ps1
102 lines (74 loc) · 4.14 KB
/
build-helpers.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
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#
# Build Script helpers
#
function GetServicesFromSfApp($sfAppDirectory) {
# Reads the "application" project file to find all referenced services.
$projectFile = Get-ChildItem -Path $sfAppDirectory -Filter *.sfproj
if ($projectFile -eq $null) {
throw "No *.sfproj file found in directory $sfAppDirectory"
}
$references = Select-Xml -Path $projectFile.FullName -XPath "//*[local-name()='ProjectReference']"
$references | ForEach-Object {
$str = $_.Node.Include.ToString().Trim(".\")
Write-Output $str.Substring(0, $str.IndexOf("\"))
}
}
function UpdateSfVersions($packageLocation, $versionSuffix) {
# appends the given versionSuffix to all ServiceManifest.xml files and to the ApplicationManifest.xml
Write-Host "Updating Service Fabric versions for $packageLocation"
$appManifestPath = "$packageLocation\ApplicationManifest.xml"
$appManifestXml = [XML](Get-Content $appManifestPath)
$appManifestXml.ApplicationManifest.ApplicationTypeVersion += $versionSuffix
$appManifestXml.ApplicationManifest.ServiceManifestImport | ForEach { $_.ServiceManifestRef.ServiceManifestVersion += $versionSuffix }
$appManifestXml.Save($appManifestPath)
"Updated application type '$($appManifestXml.ApplicationManifest.ApplicationTypeName)' to version '$($appManifestXml.ApplicationManifest.ApplicationTypeVersion)'"
$serviceManifestPaths = [System.IO.Directory]::EnumerateFiles($packageLocation, "ServiceManifest.xml", [System.IO.SearchOption]::AllDirectories)
$serviceManifestPaths | ForEach {
$serviceManifestXml = [XML](Get-Content $_)
$serviceManifestXml.ServiceManifest.Version += $versionSuffix
$subPackages = @(
$serviceManifestXml.ServiceManifest.CodePackage,
$serviceManifestXml.ServiceManifest.ConfigPackage,
$serviceManifestXml.ServiceManifest.DataPackage)
$subPackages | Where { $_.Version } | ForEach { $_.Version += $versionSuffix }
$serviceManifestXml.Save($_)
Write-Host "Updated service '$($serviceManifestXml.ServiceManifest.Name)' to version '$($serviceManifestXml.ServiceManifest.Version)'"
}
}
function PublishSfApp($sfBasePath, $sfApp, $outputPath, $buildConfiguration, $buildNumber) {
# it copies all services, application files and scripts into an artifacts folder.
$sfAppPath = Join-Path $sfBasePath $sfApp
Write-Host ""
Write-Host "Publishing Service Fabric-App '$sfAppPath' to $outputPath"
Write-Host ""
$sfServices = GetServicesFromSfApp $sfAppPath
Write-Host "App contains the following services: $sfServices"
Write-Host ""
$applicationPackage = Join-Path $outputPath "ApplicationPackage"
if(!(Test-Path $applicationPackage)) {
New-Item $applicationPackage -ItemType Directory | Out-Null
}
$sfServices | ForEach-Object {
$serviceName = $_
$servicePath = Join-Path $sfBasePath $serviceName
$serviceOutput = Join-Path $applicationPackage $serviceName
Write-Host "Publishing $serviceName to $serviceOutput"
$codeOutput = Join-Path $serviceOutput "Code"
if(!(Test-Path $codeOutput)) {
New-Item $codeOutput -ItemType Directory | Out-Null
}
$versionSuffixArg = if ([String]::IsNullOrWhiteSpace($buildNumber)) { "" } else { "--version-suffix $buildNumber" }
exec { Invoke-Expression "dotnet publish $servicePath -c $buildConfiguration --no-restore $versionSuffixArg -o $codeOutput" }
Copy-Item (Join-Path $servicePath "PackageRoot/*") $serviceOutput -Recurse -Force
}
Write-Host "Publishing application artifacts"
Copy-Item (Join-Path $sfAppPath "ApplicationPackageRoot/*") $applicationPackage -Recurse -Force
# folders required for deployment
Copy-Item (Join-Path $sfAppPath "ApplicationParameters") $outputPath -Recurse -Force
Copy-Item (Join-Path $sfAppPath "PublishProfiles") $outputPath -Recurse -Force
Copy-Item (Join-Path $sfAppPath "Scripts") $outputPath -Recurse -Force
# Update version
$packageLocation = (Get-Item $applicationPackage).FullName
$versionSuffix = "-$buildNumber"
UpdateSfVersions $packageLocation $versionSuffix
}