-
Notifications
You must be signed in to change notification settings - Fork 0
/
build-publish.ps1
executable file
·159 lines (131 loc) · 5.85 KB
/
build-publish.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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
Param(
[string]$WorkingDirectory = $PSScriptRoot,
[switch]$Publish,
[string]$ACCOUNT = "",
[string]$PUBLISHER = "",
[string]$PAT,
[string]$EXTENSION_NAME,
[switch]$PublishFromFile
)
#####################################################
# Stop script on any error
#####################################################
$ErrorActionPreference = "Stop"
if ($Env:SYSTEM_DEBUG) {
$DebugPreference = 'Continue'
$VerbosePreference = "Continue"
}
$ProgressPreference = "SilentlyContinue"
#####################################################
##########################################################
# START : Validation
##########################################################
if ([String]::IsNullOrWhiteSpace($(Get-Command tfx -ErrorAction SilentlyContinue | Select-Object -ExpandProperty Definition))) {
throw "TFX CLI is missing"
}
else {
$(Get-Command tfx -ErrorAction SilentlyContinue | Select-Object -ExpandProperty Definition)
Write-Host "Found TFX CLI"
}
if (-not($PublishFromFile)) {
if ([String]::IsNullOrWhiteSpace($(Get-Command tsc -ErrorAction SilentlyContinue | Select-Object -ExpandProperty Definition))) {
throw "TypeScript CLI is missing"
}
}
$WorkingDirectory = Resolve-Path -Path $WorkingDirectory
##########################################################
# END : Validation
##########################################################
#####################################################
# Input Parameters
#####################################################
Write-Host "Working Directory: ............. [$WorkingDirectory]"
Write-Host "Publish: ....................... [$Publish]"
if ($Publish) {
Write-Host "Account: ....................... [$ACCOUNT]"
Write-Host "Publisher: ..................... [$PUBLISHER]"
Write-Host "Extension Name: ................ [$EXTENSION_NAME]"
}
Write-Host "Publish From File: ............. [$PublishFromFile]"
#####################################################
try {
Push-Location -Path $WorkingDirectory
if (-not($PublishFromFile)) {
<#
Push-Location -Path "../"
./build.ps1
$tasks = @("get-build-definition-id")
$tasks | ForEach-Object {
Copy-Item -Path "*.psd1" -Destination "$WorkingDirectory/tasks/$_" -Force | Out-Null
Copy-Item -Path "*.psm1" -Destination "$WorkingDirectory/tasks/$_" -Force | Out-Null
switch ($_) {
"get-build-definition-id" {
Copy-Item -Path "./Invoke-AzDO.ps1" -Destination "$WorkingDirectory/tasks/$_/powershell.ps1" -Force -Verbose
}
}
}
Pop-Location
#>
#############################################
# Build TypeScript tasks
#############################################
# Fix for VPN SSL issues
npm set strict-ssl false
#$tasks = @("generate-build-info-file")
(Get-ChildItem -Path "$PSScriptRoot/tasks" -Directory | Select-Object Name).Name | ForEach-Object {
if ($PSVersionTable.PSEdition -ieq "Core") {
Push-Location "$WorkingDirectory/tasks/$_"
}
else {
# Windows
Push-Location "$WorkingDirectory/tasks/$_"
}
npm install
Write-Host "Last Exit Code: $($LASTEXITCODE)"
tsc
Pop-Location
}
#############################################
tfx extension create --manifest-globs extension-manifest.json
}
else {
Write-Warning "Skipping compile of extension"
}
if ($Publish) {
if (-not($PublishFromFile)) {
Write-Host "Publish Extension..."
tfx extension publish --manifest-globs vss-extension.json --share-with $ACCOUNT --service-url "https://marketplace.visualstudio.com/" --auth-type pat --token "$PAT" --publisher $PUBLISHER --no-prompt --trace-level
}
else {
Write-Host "Publish Extension [From File]..."
$ExtensionFile = Get-ChildItem -Filter '*.vsix' | Select-Object -First 1
Write-Host "Extension File: $($ExtensionFile.FullName)"
Write-Host "tfx extension publish --vsix $($ExtensionFile.FullName) --share-with $ACCOUNT --service-url `"https://marketplace.visualstudio.com/`" --auth-type pat --token `"$PAT`" --publisher $PUBLISHER --no-prompt --trace-level"
tfx extension publish --vsix "$($ExtensionFile.FullName)" --share-with $ACCOUNT --service-url "https://marketplace.visualstudio.com/" --auth-type pat --token "$PAT" --publisher $PUBLISHER --no-prompt --trace-level
}
Write-Host "Last Exit Code: $LASTEXITCODE"
if ($LASTEXITCODE -ne 0) { throw "Failure publishing extension" }
Write-Host "Completed Publishing Extension"
# Uninstall VSTS Extension
Write-Host "Uninstalling Extension (if exists)..."
$Authentication = [Text.Encoding]::ASCII.GetBytes(":$PAT")
$Authentication = [System.Convert]::ToBase64String($Authentication)
$Headers = @{
Authorization = ("Basic {0}" -f $Authentication)
}
$Uri = "https://$ACCOUNT.extmgmt.visualstudio.com/_apis/extensionmanagement/installedextensionsbyname/$PUBLISHER/$($EXTENSION_NAME)?api-version=4.1-preview.1"
Invoke-RestMethod -Method Delete -Uri $Uri -Headers $Headers -ContentType 'application/json'
Write-Host "Completed Uninstalling Extension"
# Install VSTS Extension
Write-Host "Installing Extension..."
$Uri = "https://{0}.visualstudio.com/" -f $ACCOUNT
tfx extension install --service-url $Uri --auth-type pat --token "$PAT" --publisher $PUBLISHER --extension-id $EXTENSION_NAME --no-prompt --trace-level debug
Write-Host "Completed Installing Extension"
}
}
catch {
throw
}
finally {
Pop-Location
}