-
Notifications
You must be signed in to change notification settings - Fork 42
/
publish.ps1
76 lines (63 loc) · 2.91 KB
/
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
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,
[Parameter(Mandatory=$true,HelpMessage="Get a personal access token from https://octopus-deploy.visualstudio.com/_details/security/tokens following the instructions https://www.visualstudio.com/en-us/integrate/extensions/publish/command-line")]
[string]
$accessToken,
[Parameter(Mandatory=$true,HelpMessage="The path where the vsix file is")]
[string]
$packagePath,
[Parameter(Mandatory=$true,HelpMessage="The path where the manifest files are")]
[string]
$manifestsPath,
[string]
$shareWith=""
)
$ErrorActionPreference = "Stop"
function IsPublishRequired($extensionManifest){
$manifest = Get-Content $extensionManifest | ConvertFrom-Json
Write-Host "Checking whether publish is required for '$($manifest.publisher)' extension id '$($manifest.id)' version '$version'"
$versions = & tfx extension show --publisher $manifest.publisher --extension-id $manifest.id --token $accessToken --json --no-prompt | ConvertFrom-Json | Select-Object -ExpandProperty versions | Group-Object -AsHashTable -Property version
if (-not $?) {throw "Failed to check whether publish is required. Exit Code $LASTEXITCODE"}
return !($versions.ContainsKey($version))
}
function PublishVSIX($vsixFile, $environment) {
$manifest = "$manifestsPath/dist/extension-manifest.$environment.json"
if(!($environment -eq "Production") -and !($environment -eq "Test")){
throw "The valid environments are 'Test' and 'Production'"
}
if(!(IsPublishRequired $manifest)){
Write-Host "Version already published. Skipping publishing."
return;
}
if ($environment -eq "Production") {
Write-Host "Publishing $vsixFile to everyone (public extension)..."
& tfx extension publish --vsix $vsixFile --token $accessToken --no-prompt
} elseif ($environment -eq "Test") {
Write-Host "Publishing $vsixFile as a private extension, sharing with $shareWith"
& tfx extension publish --vsix $vsixFile --token $accessToken --share-with $shareWith --no-prompt
}
if (-not $?) {throw "Failed to publish. Exit Code $LASTEXITCODE"}
}
function PublishExtension($environment) {
Write-Output "Looking for VSIX file(s) to publish in $packagePath..."
$include = ''
if ($environment -ne "Production")
{
$include = "$environment-".ToLowerInvariant()
}
$vsixFiles = Get-ChildItem $packagePath -Include "*$include$version.vsix" -Recurse
if ($vsixFiles) {
foreach ($vsixFile in $vsixFiles) {
PublishVSIX $vsixFile $environment
}
} else {
Write-Error "There were no VSIX files found for *$version.vsix in $packagePath"
}
}
PublishExtension $environment