Skip to content

Commit 13be391

Browse files
authored
SG-40980 Simplify Azure Pipeline CI pipeline (#436)
1 parent e56d41c commit 13be391

File tree

2 files changed

+59
-54
lines changed

2 files changed

+59
-54
lines changed

azure-pipelines-templates/run-tests.yml

Lines changed: 32 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -28,57 +28,47 @@
2828

2929
# This is the list of parameters for this template and their default values.
3030
parameters:
31-
name: ''
31+
os_name: ''
3232
vm_image: ''
33+
python_version: ''
3334

3435
jobs:
3536
# The job will be named after the OS and Azure will suffix the strategy to make it unique
3637
# so we'll have a job name "Windows Python 3.9" for example. What's a strategy? Strategies are the
3738
# name of the keys under the strategy.matrix scope. So for each OS we'll have "<OS> Python 3.9" and
3839
# "<OS> Python 3.10".
39-
- job: ${{ parameters.name }}
40+
- job:
41+
displayName: "${{ parameters.os_name }} Python ${{ parameters.python_version }}"
4042
pool:
4143
vmImage: ${{ parameters.vm_image }}
42-
# The strategy is another way of removing repetition. It will create one job per entry in the
43-
# matrix.
44-
strategy:
45-
matrix:
46-
# We support these versions of Python.
47-
Python 3.9:
48-
python.version: '3.9'
49-
Python 3.10:
50-
python.version: '3.10'
51-
Python 3.11:
52-
python.version: '3.11'
53-
54-
maxParallel: 4
5544

5645
variables:
5746
group: sg-credentials
5847

5948
# These are the steps that will be executed inside each job.
6049
steps:
61-
# Specifies which version of Python we want to use. That's where the strategy comes in.
62-
# Each job will share this set of steps, but each of them will receive a different
63-
# $(python.version)
50+
# Specifies which version of Python we want to use.
6451
# TODO: We should provide `githubToken` if we want to download a python release.
6552
# Otherwise we may hit the GitHub anonymous download limit.
6653
- task: UsePythonVersion@0
6754
inputs:
68-
versionSpec: '$(python.version)'
69-
addToPath: True
55+
versionSpec: ${{ parameters.python_version }}
7056

7157
# Install all dependencies needed for running the tests. This command is good
7258
# for all OSes
73-
- script: |
74-
python -m pip install --upgrade pip setuptools wheel
75-
python -m pip install -r tests/ci_requirements.txt
76-
displayName: Install tools
59+
- task: Bash@3
60+
displayName: Install dependencies
61+
inputs:
62+
targetType: inline
63+
script: |
64+
pip install --upgrade pip
65+
pip install --upgrade setuptools wheel
66+
pip install --upgrade --requirement tests/ci_requirements.txt
7767
7868
# The {{}} syntax is meant for the the pre-processor of Azure pipeline. Every statement inside
7969
# a {{}} block will be evaluated and substituted before the file is parsed to create the jobs.
8070
# So here we're inserting an extra step if the template is being invoked for Windows.
81-
- ${{ if eq(parameters.name, 'Windows') }}:
71+
- ${{ if eq(parameters.os_name, 'Windows') }}:
8272
# On Windows, we need to update the certificates, the cert store is missing the newer one
8373
# from Amazon like some clients experienced a while back. Who would have thought Microsoft
8474
# would have been out of date! ;)
@@ -92,10 +82,15 @@ jobs:
9282
# Runs the tests and generates test coverage. The tests results are uploaded to Azure Pipelines in the
9383
# Tests tab of the build and each test run will be named after the --test-run-title argument to pytest,
9484
# for example 'Windows - 2.7'
95-
- bash: |
96-
cp ./tests/example_config ./tests/config
97-
pytest --durations=0 -v --cov shotgun_api3 --cov-report xml --test-run-title="${{parameters.name}}-$(python.version)"
85+
- task: Bash@3
9886
displayName: Running tests
87+
inputs:
88+
targetType: inline
89+
script: |
90+
cp ./tests/example_config ./tests/config
91+
pytest --durations=0 -v \
92+
--cov shotgun_api3 --cov-report xml \
93+
--test-run-title="${{ parameters.os_name }}-${{ parameters.python_version }}"
9994
env:
10095
# Pass the values needed to authenticate with the Flow Production Tracking site and create some entities.
10196
# Remember, on a pull request from a client or on forked repos, those variables
@@ -110,9 +105,9 @@ jobs:
110105
# build variables are available. Because of this, we need to find another way to generate a
111106
# unique login. So instead, we'll use the the name of the platform and the python version,
112107
# which should make it unique.
113-
SG_HUMAN_LOGIN: $(python_api_human_login)-${{parameters.name}}-$(python.version)
108+
SG_HUMAN_LOGIN: $(python_api_human_login)-${{ parameters.os_name }}-${{ parameters.python_version }}
114109
# This will give a user name like 'something macOS 2.7'
115-
SG_HUMAN_NAME: $(python_api_human_name) ${{parameters.name}} $(python.version)
110+
SG_HUMAN_NAME: $(python_api_human_name) ${{ parameters.os_name }} ${{ parameters.python_version }}
116111
SG_HUMAN_PASSWORD: $(python_api_human_password)
117112
# So, first, we need to make sure that two builds running at the same time do not manipulate
118113
# the same entities, so we're sandboxing build nodes based on their name.
@@ -123,20 +118,20 @@ jobs:
123118
# Again, this would have been a lot simpler if we could simply have had a login based on the
124119
# agent name, but alas, the agent name has a space in it which needs to be replaced to something
125120
# else and string substitution can't be made on build variables, only template parameters.
126-
SG_ASSET_CODE: CI-$(python_api_human_login)-${{parameters.name}}-$(python.version)
127-
SG_VERSION_CODE: CI-$(python_api_human_login)-${{parameters.name}}-$(python.version)
128-
SG_SHOT_CODE: CI-$(python_api_human_login)-${{parameters.name}}-$(python.version)
129-
SG_TASK_CONTENT: CI-$(python_api_human_login)-${{parameters.name}}-$(python.version)
130-
SG_PLAYLIST_CODE: CI-$(python_api_human_login)-${{parameters.name}}-$(python.version)
121+
SG_ASSET_CODE: CI-$(python_api_human_login)-${{ parameters.os_name }}-${{ parameters.python_version }}
122+
SG_VERSION_CODE: CI-$(python_api_human_login)-${{ parameters.os_name }}-${{ parameters.python_version }}
123+
SG_SHOT_CODE: CI-$(python_api_human_login)-${{ parameters.os_name }}-${{ parameters.python_version }}
124+
SG_TASK_CONTENT: CI-$(python_api_human_login)-${{ parameters.os_name }}-${{ parameters.python_version }}
125+
SG_PLAYLIST_CODE: CI-$(python_api_human_login)-${{ parameters.os_name }}-${{ parameters.python_version }}
131126

132127
# Upload the code coverage result to codecov.io.
133-
- ${{ if eq(parameters.name, 'Windows') }}:
128+
- ${{ if eq(parameters.os_name, 'Windows') }}:
134129
- powershell: |
135130
$ProgressPreference = 'SilentlyContinue'
136131
Invoke-WebRequest -Uri https://uploader.codecov.io/latest/windows/codecov.exe -Outfile codecov.exe
137132
.\codecov.exe -f coverage.xml
138133
displayName: Uploading code coverage
139-
- ${{ elseif eq(parameters.name, 'Linux') }}:
134+
- ${{ elseif eq(parameters.os_name, 'Linux') }}:
140135
- script: |
141136
curl -Os https://uploader.codecov.io/latest/linux/codecov
142137
chmod +x codecov

azure-pipelines.yml

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,26 @@ pr:
5858
include:
5959
- "*"
6060

61+
parameters:
62+
- name: python_versions
63+
type: object
64+
default:
65+
- '3.9'
66+
- '3.10'
67+
- '3.11'
68+
69+
- name: os_versions
70+
type: object
71+
default:
72+
- name: Linux
73+
vm_image: ubuntu-latest
74+
75+
- name: macOS
76+
vm_image: macOS-latest
77+
78+
- name: Windows
79+
vm_image: windows-latest
80+
6181
# This here is the list of jobs we want to run for our build.
6282
# Jobs run in parallel.
6383
jobs:
@@ -71,20 +91,10 @@ jobs:
7191

7292
- template: azure-pipelines-templates/type_checking.yml
7393

74-
# These are jobs templates, they allow to reduce the redundancy between
75-
# variations of the same build. We pass in the image name
76-
# and a friendly name that then template can then use to create jobs.
77-
- template: azure-pipelines-templates/run-tests.yml
78-
parameters:
79-
name: Linux
80-
vm_image: 'ubuntu-latest'
81-
82-
- template: azure-pipelines-templates/run-tests.yml
83-
parameters:
84-
name: macOS
85-
vm_image: 'macOS-latest'
86-
87-
- template: azure-pipelines-templates/run-tests.yml
88-
parameters:
89-
name: Windows
90-
vm_image: 'windows-latest'
94+
- ${{ each os_version in parameters.os_versions }}:
95+
- ${{ each python_version in parameters.python_versions }}:
96+
- template: azure-pipelines-templates/run-tests.yml
97+
parameters:
98+
os_name: "${{ os_version.name }}"
99+
vm_image: ${{ os_version.vm_image }}
100+
python_version: ${{ python_version }}

0 commit comments

Comments
 (0)