Skip to content

Commit 1ff7844

Browse files
hallvictoriaVictoria Hall
andauthored
build: move library release to internal (#272)
* move library release to internal * fix merge back step * use official template * replace email --------- Co-authored-by: Victoria Hall <[email protected]>
1 parent 684f38c commit 1ff7844

File tree

2 files changed

+288
-0
lines changed

2 files changed

+288
-0
lines changed

eng/ci/library-release.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
resources:
2+
repositories:
3+
- repository: 1es
4+
type: git
5+
name: 1ESPipelineTemplates/1ESPipelineTemplates
6+
ref: refs/tags/release
7+
8+
extends:
9+
template: v1/1ES.Official.PipelineTemplate.yml@1es
10+
parameters:
11+
pool:
12+
name: 1es-pool-azfunc-public
13+
image: 1es-windows-2022
14+
os: windows
15+
sdl:
16+
codeql:
17+
compiled:
18+
enabled: true # still only runs for default branch
19+
runSourceLanguagesInSourceAnalysis: true
20+
settings:
21+
skipBuildTagsForGitHubPullRequests: ${{ variables['System.PullRequest.IsFork'] }}
22+
23+
stages:
24+
- stage: Release
25+
jobs:
26+
- template: /eng/templates/official/jobs/publish-release.yml@self
Lines changed: 262 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,262 @@
1+
jobs:
2+
3+
- job: "CreateReleaseBranch"
4+
displayName: 'Create Release Branch'
5+
pool:
6+
name: 1es-pool-azfunc
7+
image: 1es-ubuntu-22.04
8+
os: linux
9+
steps:
10+
- powershell: |
11+
$githubToken = "$(GithubPat)"
12+
$newLibraryVersion = "$(NewLibraryVersion)"
13+
14+
if($newLibraryVersion -match '(\d)+.(\d)+.(\d)+') {
15+
# Create GitHub credential
16+
git config --global user.name "AzureFunctionsPython"
17+
git config --global user.email "[email protected]"
18+
19+
# Heading to Artifact Repository
20+
Write-Host "Operating based on $stagingDirectory/azure-functions-python-library"
21+
git checkout -b "release/$newLibraryVersion"
22+
23+
# Change __init__.py version
24+
Write-Host "Change version number in azure/functions/__init__.py to $newLibraryVersion"
25+
((Get-Content azure/functions/__init__.py) -replace "__version__ = '(\d)+.(\d)+.*'", "__version__ = '$newLibraryVersion'" -join "`n") + "`n" | Set-Content -NoNewline azure/functions/__init__.py
26+
git add azure/functions/__init__.py
27+
git commit -m "build: update Python Library Version to $newLibraryVersion"
28+
29+
# Create release branch release/X.Y.Z
30+
Write-Host "Creating release branch release/$newLibraryVersion"
31+
git push --repo="https://[email protected]/Azure/azure-functions-python-library.git"
32+
} else {
33+
Write-Host "NewLibraryVersion $newLibraryVersion is malformed (example: 1.5.0)"
34+
exit -1
35+
}
36+
displayName: 'Push release/x.y.z'
37+
38+
- job: "CheckReleaseBranch"
39+
dependsOn: ['CreateReleaseBranch']
40+
displayName: '(Manual) Check Release Branch'
41+
pool: server
42+
steps:
43+
- task: ManualValidation@1
44+
displayName: '(Optional) Modify release/x.y.z branch'
45+
inputs:
46+
notifyUsers: '' # No email notifications sent
47+
instructions: |
48+
1. Check if the https://github.com/Azure/azure-functions-python-library/tree/release/$(NewLibraryVersion) build succeeds and passes all unit tests.
49+
2. If not, modify the release/$(NewLibraryVersion) branch.
50+
3. Ensure release/$(NewLibraryVersion) branch contains all necessary changes.
51+
52+
- job: "CreateReleaseTag"
53+
dependsOn: ['CheckReleaseBranch']
54+
displayName: 'Create Release Tag'
55+
steps:
56+
- powershell: |
57+
$githubToken = "$(GithubPat)"
58+
$newLibraryVersion = "$(NewLibraryVersion)"
59+
60+
if($newLibraryVersion -match '(\d)+.(\d)+.(\d)+') {
61+
# Create GitHub credential
62+
git config --global user.name "AzureFunctionsPython"
63+
git config --global user.email "[email protected]"
64+
65+
# Clone Repository
66+
git clone https://[email protected]/Azure/azure-functions-python-library
67+
Write-Host "Cloned azure-functions-python-library into local"
68+
Set-Location "azure-functions-python-library"
69+
git checkout "origin/release/$newLibraryVersion"
70+
71+
# Create release tag X.Y.Z
72+
Write-Host "Creating release tag $newLibraryVersion"
73+
git tag -a "$newLibraryVersion" -m "$newLibraryVersion"
74+
75+
# Push tag to remote
76+
git push origin $newLibraryVersion
77+
} else {
78+
Write-Host "NewLibraryVersion $newLibraryVersion is malformed (example: 1.5.0)"
79+
exit -1
80+
}
81+
displayName: 'Tag and push x.y.z'
82+
- powershell: |
83+
$githubUser = "$(GithubUser)"
84+
$githubToken = "$(GithubPat)"
85+
$newLibraryVersion = "$(NewLibraryVersion)"
86+
87+
if($newLibraryVersion -match '(\d)+.(\d)+.(\d)+') {
88+
# Create GitHub credential
89+
$credential = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes("${githubUser}:${githubToken}"))
90+
91+
# Create Release Note
92+
Write-Host "Creating release note in GitHub"
93+
$body = (@{tag_name="$newLibraryVersion";name="Release $newLibraryVersion";body="- Fill in Release Note Here";draft=$true} | ConvertTo-Json -Compress)
94+
$response = Invoke-WebRequest -Headers @{"Cache-Control"="no-cache";"Content-Type"="application/json";"Authorization"="Basic $credential"} -Method Post -Body "$body" -Uri "https://api.github.com/repos/Azure/azure-functions-python-library/releases"
95+
96+
# Return Value
97+
if ($response.StatusCode -ne 201) {
98+
Write-Host "Failed to create release note in GitHub"
99+
exit -1
100+
}
101+
102+
$draftUrl = $response | ConvertFrom-Json | Select -expand url
103+
Write-Host "Release draft created in $draftUrl"
104+
} else {
105+
Write-Host "NewLibraryVersion $newLibraryVersion is malformed (example: 1.1.8)"
106+
exit -1
107+
}
108+
displayName: 'Create GitHub release draft'
109+
110+
- job: "CheckGitHubRelease"
111+
dependsOn: ['CreateReleaseTag']
112+
displayName: '(Manual) Check GitHub release note'
113+
pool: server
114+
steps:
115+
- task: ManualValidation@1
116+
displayName: 'Write GitHub release note'
117+
inputs:
118+
notifyUsers: ''
119+
instructions: 'Please head to https://github.com/Azure/azure-functions-python-library/releases to finish the release note'
120+
121+
- job: "TestWithWorker"
122+
dependsOn: ['CheckGitHubRelease']
123+
displayName: 'Test with Worker'
124+
steps:
125+
- powershell: |
126+
$githubUser = "$(GithubUser)"
127+
$githubToken = "$(GithubPat)"
128+
$newLibraryVersion = "$(NewLibraryVersion)"
129+
$newBranch = "sdk/$newLibraryVersion"
130+
131+
if($newLibraryVersion -match '(\d)+.(\d)+.(\d)+') {
132+
# Create GitHub credential
133+
git config --global user.name "AzureFunctionsPython"
134+
git config --global user.email "[email protected]"
135+
136+
# Create GitHub credential
137+
$credential = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes("${githubUser}:${githubToken}"))
138+
139+
# Clone Repository
140+
git clone https://[email protected]/Azure/azure-functions-python-worker
141+
Write-Host "Cloned azure-functions-python-worker into local and checkout $newBranch branch"
142+
Set-Location "azure-functions-python-worker"
143+
git checkout -b $newBranch "origin/dev"
144+
145+
# Modify SDK Version in pyproject.toml
146+
Write-Host "Replacing SDK version in worker's pyproject.toml"
147+
((Get-Content pyproject.toml) -replace '"azure-functions==(\d)+.(\d)+.*"','"azure-functions==$(NewLibraryVersion)"' -join "`n") + "`n" | Set-Content -NoNewline pyproject.toml
148+
149+
# Commit Python Version
150+
Write-Host "Pushing $newBranch to azure-functions-python-worker repo"
151+
git add pyproject.toml
152+
git commit -m "Update Python SDK Version to $newLibraryVersion"
153+
git push origin $newBranch
154+
155+
# Create PR
156+
Write-Host "Creating PR draft in GitHub"
157+
$body = (@{head="$newBranch";base="dev";body="Python SDK Version [$newLibraryVersion](https://github.com/Azure/azure-functions-python-library/releases/tag/$newLibraryVersion)";draft=$true;maintainer_can_modify=$true;title="build: update Python SDK Version to $newLibraryVersion"} | ConvertTo-Json -Compress)
158+
$response = Invoke-WebRequest -Headers @{"Cache-Control"="no-cache";"Content-Type"="application/json";"Authorization"="Basic $credential";"Accept"="application/vnd.github.v3+json"} -Method Post -Body "$body" -Uri "https://api.github.com/repos/Azure/azure-functions-python-worker/pulls"
159+
160+
# Return Value
161+
if ($response.StatusCode -ne 201) {
162+
Write-Host "Failed to create PR in Azure Functions Python Worker"
163+
exit -1
164+
}
165+
166+
$draftUrl = $response | ConvertFrom-Json | Select -expand url
167+
Write-Host "PR draft created in $draftUrl"
168+
} else {
169+
Write-Host "NewLibraryVersion $newLibraryVersion is malformed (example: 1.1.8)"
170+
exit -1
171+
}
172+
displayName: 'Create PR in Worker Repo'
173+
174+
- job: "WaitForPythonWorkerPR"
175+
dependsOn: ['TestWithWorker']
176+
displayName: '(Manual) Check Python Worker PR'
177+
pool: server
178+
steps:
179+
- task: ManualValidation@1
180+
displayName: 'Check Python Worker PR'
181+
inputs:
182+
notifyUsers: ''
183+
instructions: |
184+
1. Please wait and check if all goes green in the https://github.com/Azure/azure-functions-python-worker/pulls
185+
2. Merge the PR into worker dev branch
186+
187+
- job: "PyPIPackage"
188+
dependsOn: ['WaitForPythonWorkerPR']
189+
displayName: 'PyPI Package'
190+
steps:
191+
- task: DownloadPipelineArtifact@2
192+
displayName: 'Download Python SDK release/x.y.z Artifact'
193+
inputs:
194+
buildType: specific
195+
project: '3f99e810-c336-441f-8892-84983093ad7f'
196+
definition: 679
197+
specificBuildWithTriggering: true
198+
buildVersionToDownload: latestFromBranch
199+
branchName: refs/heads/dev
200+
targetPath: PythonSdkArtifact
201+
- task: UsePythonVersion@0
202+
displayName: 'Use Python 3.11'
203+
inputs:
204+
versionSpec: 3.11
205+
- powershell: |
206+
$newLibraryVersion = "$(NewLibraryVersion)"
207+
$pypiToken = "$(PypiToken)"
208+
209+
# Setup local Python environment
210+
Write-Host "Setup local Python environment"
211+
python -m pip install -U pip
212+
pip install twine
213+
214+
# Publish artifacts to PyPi
215+
twine upload --repository-url https://upload.pypi.org/legacy/ --username "__token__" --password "$pypiToken" PythonSdkArtifact/azure-functions/dist/*
216+
Start-Sleep -Seconds 3
217+
218+
# Checking if the new version is uploaded
219+
Write-Host "Check if new version is uploaded"
220+
$response = Invoke-WebRequest -Headers @{"Cache-Control"="no-cache"} -Method Get -Uri "https://pypi.org/project/azure-functions/$newLibraryVersion/"
221+
222+
# Return Value
223+
if ($response.StatusCode -ne 200) {
224+
Write-Host "Failed to verify https://pypi.org/project/azure-functions/$newLibraryVersion/"
225+
exit -1
226+
}
227+
displayName: 'Publish package to pypi.org'
228+
229+
- job: "MergeBack"
230+
dependsOn: ['PyPIPackage']
231+
displayName: 'Merge Back'
232+
steps:
233+
- powershell: |
234+
$githubToken = "$(GithubPat)"
235+
$newLibraryVersion = "$(newLibraryVersion)"
236+
237+
if($newLibraryVersion -match '(\d)+.(\d)+.(\d)+') {
238+
# Create GitHub credential
239+
git config --global user.name "AzureFunctionsPython"
240+
git config --global user.email "[email protected]"
241+
242+
# Clone Repository
243+
git clone https://[email protected]/Azure/azure-functions-python-library
244+
Write-Host "Cloned azure-functions-python-library into local"
245+
Set-Location "azure-functions-python-library"
246+
247+
# Merge back to master
248+
Write-Host "Merging release/$newLibraryVersion back to master"
249+
git checkout master
250+
git merge "origin/release/$newLibraryVersion"
251+
git push origin master
252+
253+
# Merge back to dev
254+
Write-Host "Merging release/$newLibraryVersion back to dev"
255+
git checkout dev
256+
git merge "origin/release/$newLibraryVersion"
257+
git push origin dev
258+
} else {
259+
Write-Host "newLibraryVersion $newLibraryVersion is malformed (example: 1.1.8)"
260+
exit -1
261+
}
262+
displayName: 'Merge release/x.y.z back to master & dev'

0 commit comments

Comments
 (0)