diff --git a/.pipelines/templates/release-Nuget.yml b/.pipelines/templates/release-Nuget.yml new file mode 100644 index 00000000000..84866ebaddb --- /dev/null +++ b/.pipelines/templates/release-Nuget.yml @@ -0,0 +1,59 @@ +parameters: + - name: skipPublish + type: boolean + +jobs: +- job: NuGetPublish + displayName: Publish to NuGet + condition: succeeded() + pool: + type: release + os: windows + templateContext: + inputs: + - input: pipelineArtifact + pipeline: PSPackagesOfficial + artifactName: drop_upload_upload_packages + variables: + - template: ./variables/release-shared.yml@self + parameters: + VERSION: $[ stageDependencies.setReleaseTagAndChangelog.SetTagAndChangelog.outputs['OutputVersion.Version'] ] + + steps: + - task: PowerShell@2 + inputs: + targetType: inline + script: | + Write-Verbose -Verbose "Version: $(Version)" + Get-ChildItem Env: | Out-String -width 9999 -Stream | write-Verbose -Verbose + displayName: 'Capture Environment Variables' + + - task: PowerShell@2 + inputs: + targetType: inline + script: | + #Exclude all global tool packages. Their names start with 'PowerShell.' + $null = New-Item -ItemType Directory -Path "$(Pipeline.Workspace)/release" + Copy-Item "$(Pipeline.Workspace)/NuGetPackages/*.nupkg" -Destination "$(Pipeline.Workspace)/release" -Exclude "PowerShell.*.nupkg" -Force -Verbose + + $releaseVersion = '$(Version)' + $globalToolPath = "$(Pipeline.Workspace)/NuGetPackages/PowerShell.$releaseVersion.nupkg" + + if ($releaseVersion -notlike '*-*') { + # Copy the global tool package for stable releases + Copy-Item $globalToolPath -Destination "$(Pipeline.Workspace)/release" + } + + Write-Verbose -Verbose "The .nupkgs below will be pushed:" + Get-ChildItem "$(Pipeline.Workspace)/release" -recurse + displayName: Download and capture nupkgs + condition: and(ne('${{ parameters.skipPublish }}', 'true'), succeeded()) + + - task: NuGetCommand@2 + displayName: 'NuGet push' + condition: and(ne('${{ parameters.skipPublish }}', 'true'), succeeded()) + inputs: + command: push + packagesToPush: '$(Pipeline.Workspace)/release/*.nupkg' + nuGetFeedType: external + publishFeedCredentials: PowerShellNuGetOrgPush diff --git a/.pipelines/templates/release-githubNuget.yml b/.pipelines/templates/release-github.yml similarity index 75% rename from .pipelines/templates/release-githubNuget.yml rename to .pipelines/templates/release-github.yml index e7c36a49fe6..36ada93f494 100644 --- a/.pipelines/templates/release-githubNuget.yml +++ b/.pipelines/templates/release-github.yml @@ -64,7 +64,7 @@ jobs: $fileContent = Get-Content -Path $OutputPath -Raw | Out-String Write-Verbose -Verbose -Message $fileContent displayName: Add sha256 hashes - + - task: PowerShell@2 inputs: targetType: inline @@ -81,18 +81,18 @@ jobs: Get-Module | Write-Verbose -Verbose $filePath = Get-ChildItem -Path "$(Pipeline.Workspace)/CHANGELOG" -Filter '*.md' | Select-Object -First 1 -ExpandProperty FullName - + if (-not (Test-Path $filePath)) { throw "$filePath not found" } - + $changelog = Get-Content -Path $filePath - + $headingPattern = "^## \[\d+\.\d+\.\d+" $headingStartLines = $changelog | Select-String -Pattern $headingPattern | Select-Object -ExpandProperty LineNumber $startLine = $headingStartLines[0] $endLine = $headingStartLines[1] - 1 - + $clContent = $changelog | Select-Object -Skip ($startLine-1) -First ($endLine - $startLine) | Out-String $StringBuilder = [System.Text.StringBuilder]::new($clContent, $clContent.Length + 2kb) @@ -105,14 +105,14 @@ jobs: } $clContent = $StringBuilder.ToString() - + Write-Verbose -Verbose "Selected content: `n$clContent" $releaseNotesFilePath = "$(Pipeline.Workspace)/release-notes.md" $clContent | Out-File -FilePath $releaseNotesFilePath -Encoding utf8 - + Write-Host "##vso[task.setvariable variable=ReleaseNotesFilePath;]$releaseNotesFilePath" - + #if name has prelease then make prerelease true as a variable if ($releaseVersion -like '*-*') { Write-Host "##vso[task.setvariable variable=IsPreRelease;]true" @@ -161,58 +161,3 @@ jobs: action: 'create' releaseNotesFilePath: '$(ReleaseNotesFilePath)' isPrerelease: '$(IsPreRelease)' - -- job: NuGetPublish - displayName: Publish to NuGet - condition: succeeded() - pool: - type: release - os: windows - templateContext: - inputs: - - input: pipelineArtifact - pipeline: PSPackagesOfficial - artifactName: drop_upload_upload_packages - variables: - - template: ./variables/release-shared.yml@self - parameters: - VERSION: $[ stageDependencies.setReleaseTagAndChangelog.SetTagAndChangelog.outputs['OutputVersion.Version'] ] - - steps: - - task: PowerShell@2 - inputs: - targetType: inline - script: | - Write-Verbose -Verbose "Version: $(Version)" - Get-ChildItem Env: | Out-String -width 9999 -Stream | write-Verbose -Verbose - displayName: 'Capture Environment Variables' - - - task: PowerShell@2 - inputs: - targetType: inline - script: | - #Exclude all global tool packages. Their names start with 'PowerShell.' - $null = New-Item -ItemType Directory -Path "$(Pipeline.Workspace)/release" - Copy-Item "$(Pipeline.Workspace)/NuGetPackages/*.nupkg" -Destination "$(Pipeline.Workspace)/release" -Exclude "PowerShell.*.nupkg" -Force -Verbose - - $releaseVersion = '$(Version)' - $globalToolPath = "$(Pipeline.Workspace)/NuGetPackages/PowerShell.$releaseVersion.nupkg" - - if ($releaseVersion -notlike '*-*') { - # Copy the global tool package for stable releases - Copy-Item $globalToolPath -Destination "$(Pipeline.Workspace)/release" - } - - Write-Verbose -Verbose "The .nupkgs below will be pushed:" - Get-ChildItem "$(Pipeline.Workspace)/release" -recurse - displayName: Download and capture nupkgs - condition: and(ne('${{ parameters.skipPublish }}', 'true'), succeeded()) - - - task: NuGetCommand@2 - displayName: 'NuGet push' - condition: and(ne('${{ parameters.skipPublish }}', 'true'), succeeded()) - inputs: - command: push - packagesToPush: '$(Pipeline.Workspace)/release/*.nupkg' - nuGetFeedType: external - publishFeedCredentials: PowerShellNuGetOrgPush diff --git a/.pipelines/templates/stages/PowerShell-Release-Stages.yml b/.pipelines/templates/stages/PowerShell-Release-Stages.yml index 52ce428a663..412bab76cf9 100644 --- a/.pipelines/templates/stages/PowerShell-Release-Stages.yml +++ b/.pipelines/templates/stages/PowerShell-Release-Stages.yml @@ -159,21 +159,21 @@ stages: Update and merge the changelog for the release. This step is required for creating GitHub draft release. -- stage: PublishGitHubReleaseAndNuget - displayName: Publish GitHub and Nuget Release +- stage: PublishGitHubRelease + displayName: Publish GitHub dependsOn: - setReleaseTagAndChangelog - UpdateChangeLog variables: ob_release_environment: ${{ parameters.releaseEnvironment }} jobs: - - template: /.pipelines/templates/release-githubNuget.yml@self + - template: /.pipelines/templates/release-github.yml@self parameters: skipPublish: ${{ parameters.SkipPublish }} - stage: PushGitTagAndMakeDraftPublic displayName: Push Git Tag and Make Draft Public - dependsOn: PublishGitHubReleaseAndNuget + dependsOn: PublishGitHubRelease jobs: - template: /.pipelines/templates/approvalJob.yml@self parameters: @@ -190,6 +190,18 @@ stages: instructions: | Make the GitHub Release Draft Public +- stage: PublishNugetRelease + displayName: Publish Nuget Release + dependsOn: + - PushGitTagAndMakeDraftPublic + - UpdateChangeLog + variables: + ob_release_environment: ${{ parameters.releaseEnvironment }} + jobs: + - template: /.pipelines/templates/release-nuget.yml@self + parameters: + skipPublish: ${{ parameters.SkipPublish }} + - stage: BlobPublic displayName: Make Blob Public dependsOn: