Skip to content

Commit 030a03d

Browse files
committed
Use deploy box and GitHubRelease task to create GitHub draft release
1 parent fa0948b commit 030a03d

File tree

2 files changed

+147
-77
lines changed

2 files changed

+147
-77
lines changed

.pipelines/Release-Official.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,8 @@ extends:
111111
- stage: PublishGitHubRelease
112112
displayName: Publish GitHub Release
113113
dependsOn: UpdateChangeLog
114+
variables:
115+
ob_release_environment: Production
114116
jobs:
115117
- template: /.pipelines/templates/release-publish-github.yml@self
116118
parameters:

.pipelines/templates/release-publish-github.yml

Lines changed: 145 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,28 @@ jobs:
88
displayName: Create GitHub Release Draft
99
condition: succeeded()
1010
pool:
11-
type: windows
11+
type: release
12+
os: windows
13+
templateContext:
14+
inputs:
15+
- input: pipelineArtifact
16+
pipeline: AIShellPackagePipeline
17+
artifactName: drop_windows_package_arm64
18+
- input: pipelineArtifact
19+
pipeline: AIShellPackagePipeline
20+
artifactName: drop_windows_package_x64
21+
- input: pipelineArtifact
22+
pipeline: AIShellPackagePipeline
23+
artifactName: drop_windows_package_x86
24+
- input: pipelineArtifact
25+
pipeline: AIShellPackagePipeline
26+
artifactName: drop_linux_package_arm64
27+
- input: pipelineArtifact
28+
pipeline: AIShellPackagePipeline
29+
artifactName: drop_linux_package_x64
30+
- input: pipelineArtifact
31+
pipeline: AIShellPackagePipeline
32+
artifactName: macos-pkgs
1233
variables:
1334
- group: 'mscodehub-code-read-akv'
1435
- group: 'Azure Blob variable group'
@@ -19,90 +40,137 @@ jobs:
1940
value: $(Build.SourcesDirectory)\AIShell\.config\tsaoptions.json
2041

2142
steps:
22-
- checkout: self
23-
clean: true
24-
25-
- pwsh: |
26-
Get-ChildItem Env:
43+
- task: PowerShell@2
44+
inputs:
45+
targetType: inline
46+
script: |
47+
Get-ChildItem Env: | Out-String -Width 500
2748
displayName: 'Capture Environment Variables'
2849

29-
- download: AIShellPackagePipeline
30-
artifact: drop_windows_package_arm64
31-
displayName: Download win-arm64 zip
32-
patterns: '**/*.zip'
33-
34-
- download: AIShellPackagePipeline
35-
artifact: drop_windows_package_x64
36-
displayName: Download win-x64 zip
37-
patterns: '**/*.zip'
38-
39-
- download: AIShellPackagePipeline
40-
artifact: drop_windows_package_x86
41-
displayName: Download win-x86 zip
42-
patterns: '**/*.zip'
43-
44-
- download: AIShellPackagePipeline
45-
artifact: drop_linux_package_arm64
46-
displayName: Download linux-arm64 tar.gz
47-
patterns: '**/*.tar.gz'
48-
49-
- download: AIShellPackagePipeline
50-
artifact: drop_linux_package_x64
51-
displayName: Download linux-x64 tar.gz
52-
patterns: '**/*.tar.gz'
53-
54-
- download: AIShellPackagePipeline
55-
artifact: macos-pkgs
56-
displayName: Download macOS tar.gz
57-
patterns: '**/*.tar.gz'
58-
59-
- pwsh: |
60-
$packagesRoot = '$(Pipeline.Workspace)/release'
61-
$null = New-Item -ItemType Directory -Path $packagesRoot
62-
Get-ChildItem -Path '$(Pipeline.Workspace)\AIShellPackagePipeline' -Include *.zip,*.tar.gz -Recurse |
63-
Copy-Item -Destination $packagesRoot -Force -Verbose
64-
65-
Write-Verbose -Verbose "List all packages to be published to GitHub release page:"
66-
Get-ChildItem -Path $packagesRoot | Out-String -Width 500 -Stream
67-
68-
$vstsCommandString = "vso[task.setvariable variable=PackagesRoot]$packagesRoot"
69-
Write-Host "sending " + $vstsCommandString
70-
Write-Host "##$vstsCommandString"
50+
- task: PowerShell@2
51+
inputs:
52+
targetType: inline
53+
script: |
54+
$packagesRoot = '$(Pipeline.Workspace)/release'
55+
$null = New-Item -ItemType Directory -Path $packagesRoot
56+
Get-ChildItem -Path '$(Pipeline.Workspace)/*' -Include *.zip,*.tar.gz |
57+
Copy-Item -Destination $packagesRoot -Force -Verbose
58+
59+
Write-Verbose -Verbose "List all packages to be published to GitHub release page:"
60+
Get-ChildItem -Path $packagesRoot | Out-String -Width 500
61+
62+
$vstsCommandString = "vso[task.setvariable variable=PackagesRoot]$packagesRoot"
63+
Write-Host "sending " + $vstsCommandString
64+
Write-Host "##$vstsCommandString"
7165
displayName: Capture downloaded artifacts
7266

73-
- pwsh: |
74-
$macX64File = (Get-Item "$(PackagesRoot)\AIShell-*-osx-x64.tar.gz").Name
75-
$releaseVersion = $macX64File.Replace("AIShell-", "").Replace("-osx-x64.tar.gz", "")
76-
77-
$vstsCommandString = "vso[task.setvariable variable=ReleaseVersion]$releaseVersion"
78-
Write-Host "sending " + $vstsCommandString
79-
Write-Host "##$vstsCommandString"
67+
- task: PowerShell@2
68+
inputs:
69+
targetType: inline
70+
script: |
71+
$hashPath = Join-Path $(PackagesRoot) 'hashes.sha256'
72+
$checksums = Get-ChildItem -Path $(PackagesRoot) |
73+
ForEach-Object {
74+
$packageName = $_.Name
75+
$fullPath = $_.FullName
76+
Write-Verbose -Verbose "Generating checksum for $fullPath"
77+
$hash = (Get-FileHash -Path $fullPath -Algorithm SHA256).Hash.ToLower()
78+
# the '*' before the packagename signifies it is a binary
79+
"$hash *$packageName"
80+
}
81+
$checksums | Out-File -FilePath $hashPath -Force
82+
Get-Content -Path $hashPath -Raw | Out-String -Width 500
83+
displayName: Add sha256 hashes
84+
85+
- task: PowerShell@2
86+
inputs:
87+
targetType: inline
88+
script: |
89+
$macX64File = (Get-Item "$(PackagesRoot)/AIShell-*-osx-x64.tar.gz").Name
90+
$releaseVersion = $macX64File.Replace("AIShell-", "").Replace("-osx-x64.tar.gz", "")
91+
92+
$vstsCommandString = "vso[task.setvariable variable=ReleaseVersion]$releaseVersion"
93+
Write-Host "sending " + $vstsCommandString
94+
Write-Host "##$vstsCommandString"
8095
displayName: 'Set release version'
8196

82-
- pwsh: |
83-
git clone https://$(mscodehubCodeReadPat)@mscodehub.visualstudio.com/PowerShellCore/_git/Internal-PowerShellTeam-Tools '$(Pipeline.Workspace)\tools'
84-
displayName: Clone Internal-Tools repository
85-
86-
- pwsh: |
87-
Import-module '$(Pipeline.Workspace)\tools\Scripts\GitHubRelease.psm1'
88-
$releaseTag = 'v$(ReleaseVersion)'
89-
$description = '<!-- TODO: Generate release notes on GitHub! -->'
90-
Publish-ReleaseDraft -Tag $releaseTag -Name "$releaseTag Release of AIShell" -Description $description -User PowerShell -Repository AIShell -PackageFolder $(PackagesRoot) -Token $(GitHubReleasePat)
91-
displayName: Publish Release Draft
97+
- task: PowerShell@2
98+
inputs:
99+
targetType: inline
100+
script: |
101+
$content = '<!-- TODO: Generate release notes on GitHub! -->'
102+
$StringBuilder = [System.Text.StringBuilder]::new($content, $content.Length + 2kb)
103+
$StringBuilder.AppendLine().AppendLine() > $null
104+
$StringBuilder.AppendLine("#### SHA256 Hashes of the release artifacts").AppendLine() > $null
105+
Get-ChildItem -Path $(PackagesRoot) -File | ForEach-Object {
106+
$PackageName = $_.Name
107+
$SHA256 = (Get-FileHash -Path $_.FullName -Algorithm SHA256).Hash
108+
$StringBuilder.AppendLine("- $PackageName").AppendLine(" - $SHA256") > $null
109+
}
110+
111+
$content = $StringBuilder.ToString()
112+
Write-Verbose -Verbose "Selected content: `n$content"
113+
$releaseNotesFilePath = "$(Pipeline.Workspace)/release-notes.md"
114+
$content | Out-File -FilePath $releaseNotesFilePath -Encoding utf8
115+
Write-Host "##vso[task.setvariable variable=ReleaseNotesFilePath;]$releaseNotesFilePath"
116+
117+
# If it's prelease then make prerelease true as a variable
118+
if ($(ReleaseVersion) -like '*-*') {
119+
Write-Host "##vso[task.setvariable variable=IsPreRelease;]true"
120+
} else {
121+
Write-Host "##vso[task.setvariable variable=IsPreRelease;]false"
122+
}
123+
displayName: Set variables for GitHub release task
124+
125+
- task: PowerShell@2
126+
inputs:
127+
targetType: inline
128+
script: |
129+
Write-Host "ReleaseNotes content:"
130+
Get-Content $(ReleaseNotesFilePath) | Out-String -width 500
131+
displayName: Verify Release Notes
132+
133+
- task: GitHubRelease@1
134+
displayName: 'Publish Release Draft'
92135
condition: and(ne('${{ parameters.publish }}', 'false'), succeeded())
136+
inputs:
137+
gitHubConnection: GitHubReleasePAT
138+
repositoryName: PowerShell/AIShell
139+
target: main
140+
assets: '$(PackagesRoot)/*'
141+
tagSource: 'userSpecifiedTag'
142+
tag: 'v$(ReleaseVersion)'
143+
title: 'v$(ReleaseVersion) Release of AIShell'
144+
isDraft: true
145+
addChangeLog: false
146+
action: 'create'
147+
releaseNotesFilePath: '$(ReleaseNotesFilePath)'
148+
isPrerelease: '$(IsPreRelease)'
149+
150+
- job: PushGitTag
151+
dependsOn: GithubReleaseDraft
152+
displayName: Push Git Tag
153+
pool:
154+
type: server
155+
timeoutInMinutes: 1440
93156

94-
- template: /.pipelines/templates/wait-for-approval.yml@self
95-
parameters:
157+
steps:
158+
- task: ManualValidation@0
96159
displayName: Push Git Tag
97-
jobName: PushGitTag
98-
dependsOnJob: GithubReleaseDraft
99-
instructions: |
100-
Push the git tag to upstream
160+
inputs:
161+
instructions: Push the git tag to upstream
162+
timeoutInMinutes: 1440
163+
164+
- job: DraftPublic
165+
dependsOn: PushGitTag
166+
displayName: Make Draft Public
167+
pool:
168+
type: server
169+
timeoutInMinutes: 1440
101170

102-
- template: /.pipelines/templates/wait-for-approval.yml@self
103-
parameters:
171+
steps:
172+
- task: ManualValidation@0
104173
displayName: Make Draft Public
105-
jobName: DraftPublic
106-
dependsOnJob: PushGitTag
107-
instructions: |
108-
Make the GitHub Release Draft Public
174+
inputs:
175+
instructions: Make the GitHub Release Draft Public
176+
timeoutInMinutes: 1440

0 commit comments

Comments
 (0)