diff --git a/.pipelines/PowerShell-Release-Official.yml b/.pipelines/PowerShell-Release-Official.yml index 237508ec56..3a224adfa1 100644 --- a/.pipelines/PowerShell-Release-Official.yml +++ b/.pipelines/PowerShell-Release-Official.yml @@ -18,7 +18,7 @@ parameters: # parameters are shown up in ADO UI in a build queue time type: string default: 'NO' - name: SkipPublish - displayName: Skip Publishing to GitHub and Nuget + displayName: Skip Publishing to Nuget type: boolean default: false - name: SkipPSInfraInstallers diff --git a/.pipelines/templates/release-githubNuget.yml b/.pipelines/templates/release-githubNuget.yml index 126cd3a895..4c4bcd7e86 100644 --- a/.pipelines/templates/release-githubNuget.yml +++ b/.pipelines/templates/release-githubNuget.yml @@ -30,12 +30,9 @@ jobs: Get-ChildItem Env: | Out-String -Stream | Write-Verbose -Verbose displayName: 'Capture Environment Variables' - - template: release-install-pwsh.yml - - task: PowerShell@2 inputs: targetType: inline - pwsh: true script: | $Path = "$(Pipeline.Workspace)/GitHubPackages" $OutputPath = Join-Path $Path 'hashes.sha256' @@ -52,40 +49,48 @@ jobs: $fileContent = Get-Content -Path $OutputPath -Raw | Out-String Write-Verbose -Verbose -Message $fileContent displayName: Add sha256 hashes - + - task: PowerShell@2 inputs: targetType: inline - pwsh: true script: | Get-ChildItem $(Pipeline.Workspace) -recurse | Select-Object -ExpandProperty FullName displayName: List all files in the workspace - task: PowerShell@2 - condition: and(ne('${{ parameters.skipPublish }}', 'false'), succeeded()) inputs: targetType: inline - pwsh: true script: | $releaseVersion = '$(ReleaseTag)' -replace '^v','' Write-Verbose -Verbose "Available modules: " 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) + $StringBuilder.AppendLine().AppendLine() > $null + $StringBuilder.AppendLine("### SHA256 Hashes of the release artifacts").AppendLine() > $null + Get-ChildItem -Path "$(Pipeline.Workspace)/GitHubPackages/" -File | ForEach-Object { + $PackageName = $_.Name + $SHA256 = (Get-FileHash -Path $_.FullName -Algorithm SHA256).Hash + $StringBuilder.AppendLine("- $PackageName").AppendLine(" - $SHA256") > $null + } + + $clContent = $StringBuilder.ToString() + Write-Verbose -Verbose "Selected content: `n$clContent" $releaseNotesFilePath = "$(Pipeline.Workspace)/release-notes.md" @@ -101,11 +106,32 @@ jobs: } displayName: Set variables for GitHub release task - - pwsh: | - Write-Host "ReleaseNotes content:" - Get-Content "$(Pipeline.Workspace)/release-notes.md" -Raw | Out-String -width 9999 | Write-Host + - task: PowerShell@2 + inputs: + targetType: inline + script: | + Write-Host "ReleaseNotes content:" + Get-Content "$(Pipeline.Workspace)/release-notes.md" -Raw | Out-String -width 9999 | Write-Host displayName: Verify Release Notes + - task: PowerShell@2 + inputs: + targetType: inline + script: | + $middleURL = '' + $tagString = "$(ReleaseTag)" + Write-Verbose -Verbose "Use the following command to push the tag:" + if ($tagString -match '-') { + $middleURL = "preview" + } + elseif ($tagString -match '(\d+\.\d+)') { + $middleURL = $matches[1] + } + $endURL = $tagString -replace '[v\.]','' + $message = "https://github.com/PowerShell/PowerShell/blob/master/CHANGELOG/$middleURL.md#$endURL" + Write-Verbose -Verbose "git tag -a $(ReleaseTag) $env:BUILD_SOURCEVERSION -m $message" + displayName: Git Push Tag Command + - task: GitHubRelease@1 inputs: gitHubConnection: GitHubReleasePAT @@ -114,6 +140,7 @@ jobs: assets: '$(Pipeline.Workspace)/GitHubPackages/*' tagSource: 'userSpecifiedTag' tag: '$(ReleaseTag)' + title: "$(ReleaseTag) Release of PowerShell" isDraft: true addChangeLog: false action: 'create' @@ -128,39 +155,41 @@ jobs: os: windows templateContext: inputs: - - input: pipelineArtifact - artifactName: drop_setReleaseTagAndUploadTools_SetTagAndTools - input: pipelineArtifact pipeline: PSPackagesOfficial artifactName: drop_upload_upload_packages variables: - template: ./variable/release-shared.yml@self parameters: - VERSION: $[ stageDependencies.setReleaseTagAndUploadTools.SetTagAndTools.outputs['OutputVersion.Version'] ] + VERSION: $[ stageDependencies.setReleaseTagAndChangelog.SetTagAndChangelog.outputs['OutputVersion.Version'] ] steps: - - template: release-install-pwsh.yml - - - pwsh: | - Write-Verbose -Verbose "Version: $(Version)" - Get-ChildItem Env: | Out-String -width 9999 -Stream | write-Verbose -Verbose + - 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' - - pwsh: | - #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 + - 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" + $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" - } + 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 + 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 }}', 'false'), succeeded())