Skip to content

Commit 01aa72a

Browse files
committed
ci: Add deploy job to release to PyPI
The release to PyPI is now automated. The trigger is pushing a tag (vX.X.X) to master. A new deploy job has been added to azure pipelines which will be triggered when a tag is pushed to master. The deploy job will check latest tag with the previous tag and will make a release to PyPI if there are changes.
1 parent 05cad40 commit 01aa72a

File tree

2 files changed

+85
-1
lines changed

2 files changed

+85
-1
lines changed

azure-pipelines.yml

Lines changed: 62 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
pr:
33
- master
44

5-
# Release to pypi when a release tag is pushed
5+
# Release to PyPI when a tag (vX.X.X) is pushed to master
66
trigger:
77
tags:
88
include:
@@ -165,3 +165,64 @@ stages:
165165
- script: "pip install ."
166166
displayName: "Ensure mbed-greentea can be installed locally for development"
167167
workingDirectory: "packages/mbed-greentea"
168+
169+
# Collect test and build stages together before the release stages to provide a pass/fail point for the status badge.
170+
- stage: CiCheckpoint
171+
displayName: 'CI Checkpoint'
172+
dependsOn:
173+
- AnalyseTest
174+
jobs:
175+
- job: ChecksPassing
176+
displayName: 'Checks Passing'
177+
# A dummy job is required due to a bug in Azure which runs the previous job if nothing is defined.
178+
steps:
179+
- bash: echo "All prerequisite stages have passed and the package should be suitable for release."
180+
181+
- stage: ProductionReleasePyPI
182+
displayName: 'Production Release'
183+
# Only allow production releases if the tests pass and a tag (vX.X.X) is pushed to master.
184+
dependsOn:
185+
- CiCheckpoint
186+
condition: and(succeeded(), contains(variables['build.sourceBranch'], 'refs/tags/v'))
187+
jobs:
188+
- deployment: PyPIProductionRelease
189+
displayName: 'PyPI Production Release'
190+
# Create an environment to keep track of PyPI releases
191+
environment: 'PyPI Release'
192+
strategy:
193+
runOnce:
194+
deploy:
195+
pool:
196+
vmImage: 'ubuntu-latest'
197+
steps:
198+
- checkout: self
199+
200+
- task: UsePythonVersion@0
201+
inputs:
202+
versionSpec: '3.7'
203+
204+
- script: |
205+
python -m pip install --upgrade wheel
206+
python -m pip install --upgrade twine
207+
python -m pip install --upgrade setuptools-scm
208+
displayName: 'Install python modules required for release'
209+
210+
- template: pypi-release.yml
211+
parameters:
212+
repoName: mbed-os-tools
213+
wDirectory: $(Build.SourcesDirectory)
214+
215+
- template: pypi-release.yml
216+
parameters:
217+
repoName: mbed-ls
218+
wDirectory: packages/mbed-ls
219+
220+
- template: pypi-release.yml
221+
parameters:
222+
repoName: mbed-host-tests
223+
wDirectory: packages/mbed-host-tests
224+
225+
- template: pypi-release.yml
226+
parameters:
227+
repoName: mbed-greentea
228+
wDirectory: packages/mbed-greentea

pypi-release.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# File: simple-param.yml
2+
parameters:
3+
- name: repoName
4+
type: string
5+
- name: wDirectory
6+
type: string
7+
8+
steps:
9+
- task: TwineAuthenticate@1
10+
displayName: 'Twine Authenticate ${{ parameters.repoName }}'
11+
inputs:
12+
pythonUploadServiceConnection: pypi-${{ parameters.repoName }}
13+
14+
# Build the python distribution from source
15+
- script: "python setup.py sdist bdist_wheel --universal"
16+
displayName: "Prepare ${{ parameters.repoName }} for release"
17+
workingDirectory: ${{ parameters.wDirectory }}
18+
19+
# Use command line script to 'twine upload'. Use -r to pass the repository name and --config-file to pass the environment variable set by the authenticate task.
20+
- script: |
21+
python -m twine upload -r ${{ parameters.repoName }} --config-file $(PYPIRC_PATH) dist/*.whl
22+
displayName: "Release ${{ parameters.repoName }} to pypi"
23+
workingDirectory: ${{ parameters.wDirectory }}

0 commit comments

Comments
 (0)