forked from OctopusDeploy/OctoTFS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pack.ps1
140 lines (115 loc) · 6.16 KB
/
pack.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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
param (
[Parameter(Mandatory=$true,HelpMessage="Test or Production")]
[ValidateSet("Test", "Production")]
[string]
$environment,
[Parameter(Mandatory=$true,HelpMessage="The three number version for this release")]
[string]
$version
)
$ErrorActionPreference = "Stop"
$sourcePath = "$PSScriptRoot\source"
$extensionsDirectoryPath = Join-Path $sourcePath "VSTSExtensions"
$buildDirectoryPath = "$PSScriptRoot\build"
$buildArtifactsPath = "$buildDirectoryPath\Artifacts"
$buildTempPath = "$buildDirectoryPath\Temp"
$tasksTempPath = Join-Path -Path $buildTempPath -ChildPath "VSTSExtensions" | Join-Path -ChildPath "OctopusBuildAndReleaseTasks" | Join-Path -ChildPath "Tasks"
function UpdateTfxCli() {
Write-Host "Updating tfx-cli..."
& npm up -g tfx-cli
}
function InstallNodeModules() {
Push-Location -Path "$sourcePath"
& npm install
Pop-Location
}
function PrepareBuildDirectory() {
if (Test-Path $buildDirectoryPath) {
$buildDirectory = Get-Item "$buildDirectoryPath"
Write-Host "Cleaning $buildDirectory..."
Remove-Item $buildDirectory -Force -Recurse
}
New-Item -Type Directory -Path $buildTempPath | Out-Null
Copy-Item $extensionsDirectoryPath -Destination $buildTempPath -Recurse
}
function CopyCommonTaskItems() {
Write-Host "Copying common task components into each task"
# for each task
ForEach($TaskPath in Get-ChildItem -Path $tasksTempPath -Exclude "Common") {
# Copy VSTS PowerShell Modules from node_modules to each task's ps_modules directory
$VstsSdkModuleNpmPath = Join-Path -Path $sourcePath -ChildPath "node_modules" | Join-Path -ChildPath "vsts-task-sdk" | Join-Path -ChildPath "VstsTaskSdk"
$PSModulesPath = Join-Path $TaskPath "ps_modules"
$VstsSdkModulePath = Join-Path $PSModulesPath "VstsTaskSdk"
New-Item -Type Directory -Path $PSModulesPath -Force | Out-Null
Copy-Item -Path $VstsSdkModuleNpmPath -Destination $VstsSdkModulePath -Recurse -Force
#Copy common task items into each task
ForEach($CommonFile in Get-ChildItem -Path (Join-Path $tasksTempPath "Common") -File) {
Copy-Item -Path $CommonFile.FullName -Destination $TaskPath | Out-Null
}
}
}
function UpdateExtensionManifestOverrideFile($extensionBuildTempPath, $environment, $version) {
Write-Host "Finding environment-specific manifest overrides..."
$overridesSourceFilePath = "$extensionBuildTempPath\extension-manifest.$environment.json"
$overridesSourceFile = Get-ChildItem -Path $overridesSourceFilePath
if ($overridesSourceFile -eq $null) {
Write-Error "Could not find the extension-manifest override file: $overridesSourceFilePath"
return $null
}
Write-Host "Using $overridesSourceFile for overriding the standard extension-manifest.json, updating version to $version..."
$manifest = ConvertFrom-JSON -InputObject (Get-Content $overridesSourceFile -Raw)
$manifest.version = $version
$overridesFilePath = "$extensionBuildTempPath\extension-manifest.$environment.$version.json"
ConvertTo-JSON $manifest | Out-File $overridesFilePath -Encoding ASCII # tfx-cli doesn't support UTF8 with BOM
Get-Content $overridesFilePath | Write-Host
return Get-Item $overridesFilePath
}
function UpdateTaskManifests($extensionBuildTempPath, $version) {
$taskManifestFiles = Get-ChildItem $extensionBuildTempPath -Include "task.json" -Recurse
foreach ($taskManifestFile in $taskManifestFiles) {
Write-Host "Updating version to $version in $taskManifestFile..."
$task = ConvertFrom-JSON -InputObject (Get-Content $taskManifestFile -Raw)
$netVersion = [System.Version]::Parse($version)
$task.version.Major = $netVersion.Major
$task.version.Minor = $netVersion.Minor
$task.version.Patch = $netVersion.Build
$task.helpMarkDown = "Version: $version. [More Information](http://docs.octopusdeploy.com/display/OD/Use+the+Team+Foundation+Build+Custom+Task)"
ConvertTo-JSON $task | Out-File $taskManifestFile -Encoding UTF8
}
}
function OverrideExtensionLogo($extensionBuildTempPath, $environment) {
$extensionLogoOverrideFile = Get-Item "$extensionBuildTempPath\extension-icon.$environment.png" -ErrorAction SilentlyContinue
if ($extensionLogoOverrideFile) {
$directory = Split-Path $extensionLogoOverrideFile
$target = Join-Path $directory "extension-icon.png"
Write-Host "Replacing extension logo with $extensionLogoOverrideFile..."
Move-Item $extensionLogoOverrideFile $target -Force
}
Remove-Item "$extensionBuildTempPath\extension-icon.*.png" -Force
}
function OverrideTaskLogos($extensionBuildTempPath, $environment) {
$taskLogoOverrideFiles = Get-ChildItem $extensionBuildTempPath -Include "icon.$environment.png" -Recurse
foreach ($logoOverrideFile in $taskLogoOverrideFiles) {
$directory = Split-Path $logoOverrideFile
$target = Join-Path $directory "icon.png"
Write-Host "Replacing task logo $target with $logoOverrideFile..."
Move-Item $logoOverrideFile $target -Force
}
Get-ChildItem $extensionBuildTempPath -Include "icon.*.png" -Recurse | Remove-Item -Force
}
function Pack($extensionName) {
Write-Host "Packing $extensionName..."
$extensionBuildTempPath = Get-ChildItem $buildTempPath -Include $extensionName -Recurse
Write-Host "Found extension working directory $extensionBuildTempPath"
$overridesFile = UpdateExtensionManifestOverrideFile $extensionBuildTempPath $environment $version
OverrideExtensionLogo $extensionBuildTempPath $environment
UpdateTaskManifests $extensionBuildTempPath $version
OverrideTaskLogos $extensionBuildTempPath $environment
Write-Host "Creating VSIX using tfx..."
& tfx extension create --root $extensionBuildTempPath --manifest-globs extension-manifest.json --overridesFile $overridesFile --outputPath "$buildArtifactsPath\$environment" --no-prompt
}
UpdateTfxCli
InstallNodeModules
PrepareBuildDirectory
CopyCommonTaskItems
Pack "OctopusBuildAndReleaseTasks"