Skip to content

Commit 3db26c4

Browse files
committed
Skip publishing if already published
1 parent 4c82bc2 commit 3db26c4

File tree

1 file changed

+21
-14
lines changed

1 file changed

+21
-14
lines changed

azure-pipelines/green-insertion.yml

+21-14
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ schedules:
99
- feature/lsp_tools_host
1010

1111
parameters:
12-
- name: InsertTargetBranch
13-
displayName: Target branch
14-
type: string
15-
default: main
12+
- name: InsertTargetBranch
13+
displayName: Target branch
14+
type: string
15+
default: main
1616

1717
resources:
1818
pipelines:
@@ -87,16 +87,23 @@ jobs:
8787
$vsix = $_.FullName
8888
$npmName = "@microsoft/csharp-vscode-extension.$os-$arch"
8989
90-
Write-Host "##[group]Translating $os-$arch VSIX to NPM package $npmName"
91-
$packageStagingDir = "$(Agent.TempDirectory)/csharp/$os-$arch"
92-
New-Item -Type Directory -Path $packageStagingDir | Set-Location
93-
Spawn-Tool '7z' ('x', '-y', $vsix)
94-
Set-Content -Path package.json -Value "{`n `"description`": `"C# for Visual Studio Code ($os-$arch) as NPM package for insertion into the C# Dev Kit extension for testing.`"`n}"
95-
Spawn-Tool 'npm' ('pkg','set',"name=$npmName","version=$version",'publishConfig.registry=https://pkgs.dev.azure.com/devdiv/DevDiv/_packaging/vs-green/npm/registry/','repository.type=git','repository.url=https://devdiv.visualstudio.com/DevDiv/_git/vscode-csharp-next',"repository.commit=$(resources.pipeline.BlueCI.sourceCommit)")
96-
Get-Content -Path package.json
97-
Spawn-Tool 'npm' @('publish','--userconfig','$(Pipeline.Workspace)/.npmrc')
98-
$InsertNpmDependencies += "$npmName@$version "
99-
Write-Host "##[endgroup]"
90+
$packageNameAndVersion = "$npmName@$version"
91+
$InsertNpmDependencies += "$packageNameAndVersion "
92+
& npm view $packageNameAndVersion --userconfig $(Pipeline.Workspace)/.npmrc
93+
# If the command succeeded it means the package is already published, so we need to skip it.
94+
if ($LASTEXITCODE -eq 0) {
95+
Write-Host "$packageNameAndVersion is already published, skipping."
96+
} else {
97+
Write-Host "##[group]Translating $os-$arch VSIX to NPM package $npmName"
98+
$packageStagingDir = "$(Agent.TempDirectory)/csharp/$os-$arch"
99+
New-Item -Type Directory -Path $packageStagingDir | Set-Location
100+
Spawn-Tool '7z' ('x', '-y', $vsix)
101+
Set-Content -Path package.json -Value "{`n `"description`": `"C# for Visual Studio Code ($os-$arch) as NPM package for insertion into the C# Dev Kit extension for testing.`"`n}"
102+
Spawn-Tool 'npm' ('pkg','set',"name=$npmName","version=$version",'publishConfig.registry=https://pkgs.dev.azure.com/devdiv/DevDiv/_packaging/vs-green/npm/registry/','repository.type=git','repository.url=https://devdiv.visualstudio.com/DevDiv/_git/vscode-csharp-next',"repository.commit=$(resources.pipeline.BlueCI.sourceCommit)")
103+
Get-Content -Path package.json
104+
Spawn-Tool 'npm' @('publish','--userconfig','$(Pipeline.Workspace)/.npmrc')
105+
Write-Host "##[endgroup]"
106+
}
100107
}
101108
}
102109

0 commit comments

Comments
 (0)