Skip to content

Commit cb546fb

Browse files
committed
Initial commit.
1 parent 0bd79da commit cb546fb

File tree

2 files changed

+62
-1
lines changed

2 files changed

+62
-1
lines changed

azure-pipelines.yml

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,4 +95,27 @@ steps:
9595
displayName: 'Publish mdoc Artifact'
9696
inputs:
9797
PathtoPublish: '$(Build.ArtifactStagingDirectory)/zips'
98-
ArtifactName: 'mdoc.Artifact'
98+
ArtifactName: 'mdoc.Artifact'
99+
100+
- task: PowerShell@2
101+
name: 'mdocVersion'
102+
displayName: 'Checking remote and local version of mdoc'
103+
condition: and(succeeded(), eq(variables['Build.SourceBranch'], 'refs/heads/master'))
104+
inputs:
105+
filePath: 'mdoc/CheckNugetPublish.ps1'
106+
107+
- task: NuGetCommand@2
108+
displayName: 'Create a NuGet package for mdoc'
109+
condition: eq(variables['mdocVersion.NeedUpdate'], true)
110+
inputs:
111+
command: 'pack'
112+
packagesToPack: 'mdoc/mdoc.nuspec'
113+
114+
- task: NuGetCommand@2
115+
displayName: 'Publishing mdoc package to nuget.org'
116+
condition: eq(variables['mdocVersion.NeedUpdate'], true)
117+
inputs:
118+
command: 'push'
119+
packagesToPush: '$(Build.ArtifactStagingDirectory)/**/*.nupkg;!$(Build.ArtifactStagingDirectory)/**/*.symbols.nupkg'
120+
nuGetFeedType: 'external'
121+
publishFeedCredentials: 'modc_nuget_org'

mdoc/CheckNugetPublish.ps1

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
$packageName = "mdoc"
2+
$packageOwner = "Microsoft"
3+
$nugetConfigPath = "mdoc/mdoc.nuspec"
4+
5+
$nugetSearchResult = nuget list PackageId:$packageName Owner:$packageOwner
6+
$packageSearchResult = $nugetSearchResult.Split(' ')
7+
if ($packageSearchResult.Count -ne 2)
8+
{
9+
Write-Host "Searching $packageName on nuget.org returns an invalid result: $nugetSearchResult"
10+
return
11+
}
12+
13+
$remoteLatestVersion = $packageSearchResult[1]
14+
Write-Host "The lastest version of $packageName on nuget.org is: $remoteLatestVersion"
15+
if (!$remoteLatestVersion)
16+
{
17+
Write-Host "Current lastest version of $packageName on nuget.org is an invalid value."
18+
return
19+
}
20+
21+
[xml]$localNugetConfig = Get-Content($nugetConfigPath)
22+
$localVersion = $localNugetConfig.package.metadata.version
23+
Write-Host "The local version of $packageName in package metadata file is: $localVersion"
24+
if (!$localVersion)
25+
{
26+
Write-Host "Current local version of $packageName in package metadata file is an invalid value."
27+
return
28+
}
29+
30+
$needUpdate = $false
31+
if ($localVersion -gt $remoteLatestVersion)
32+
{
33+
$needUpdate = $true
34+
Write-Host "We need to publish a new version to nuget.org."
35+
}
36+
37+
Write-Host "##vso[task.setvariable variable=NeedUpdate;isOutput=true]$needUpdate"
38+
Write-Host "##vso[task.setvariable variable=Version;isOutput=true]$localVersion"

0 commit comments

Comments
 (0)