Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 32 additions & 37 deletions azure-pipelines-templates/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,57 +28,47 @@

# This is the list of parameters for this template and their default values.
parameters:
name: ''
os_name: ''
vm_image: ''
python_version: ''

jobs:
# The job will be named after the OS and Azure will suffix the strategy to make it unique
# so we'll have a job name "Windows Python 3.9" for example. What's a strategy? Strategies are the
# name of the keys under the strategy.matrix scope. So for each OS we'll have "<OS> Python 3.9" and
# "<OS> Python 3.10".
- job: ${{ parameters.name }}
- job:
displayName: "${{ parameters.os_name }} Python ${{ parameters.python_version }}"
pool:
vmImage: ${{ parameters.vm_image }}
# The strategy is another way of removing repetition. It will create one job per entry in the
# matrix.
strategy:
matrix:
# We support these versions of Python.
Python 3.9:
python.version: '3.9'
Python 3.10:
python.version: '3.10'
Python 3.11:
python.version: '3.11'

maxParallel: 4

variables:
group: sg-credentials

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

# Install all dependencies needed for running the tests. This command is good
# for all OSes
- script: |
python -m pip install --upgrade pip setuptools wheel
python -m pip install -r tests/ci_requirements.txt
displayName: Install tools
- task: Bash@3
displayName: Install dependencies
inputs:
targetType: inline
script: |
pip install --upgrade pip
pip install --upgrade setuptools wheel
pip install --upgrade --requirement tests/ci_requirements.txt

# The {{}} syntax is meant for the the pre-processor of Azure pipeline. Every statement inside
# a {{}} block will be evaluated and substituted before the file is parsed to create the jobs.
# So here we're inserting an extra step if the template is being invoked for Windows.
- ${{ if eq(parameters.name, 'Windows') }}:
- ${{ if eq(parameters.os_name, 'Windows') }}:
# On Windows, we need to update the certificates, the cert store is missing the newer one
# from Amazon like some clients experienced a while back. Who would have thought Microsoft
# would have been out of date! ;)
Expand All @@ -92,10 +82,15 @@ jobs:
# Runs the tests and generates test coverage. The tests results are uploaded to Azure Pipelines in the
# Tests tab of the build and each test run will be named after the --test-run-title argument to pytest,
# for example 'Windows - 2.7'
- bash: |
cp ./tests/example_config ./tests/config
pytest --durations=0 -v --cov shotgun_api3 --cov-report xml --test-run-title="${{parameters.name}}-$(python.version)"
- task: Bash@3
displayName: Running tests
inputs:
targetType: inline
script: |
cp ./tests/example_config ./tests/config
pytest --durations=0 -v \
--cov shotgun_api3 --cov-report xml \
--test-run-title="${{ parameters.os_name }}-${{ parameters.python_version }}"
env:
# Pass the values needed to authenticate with the Flow Production Tracking site and create some entities.
# Remember, on a pull request from a client or on forked repos, those variables
Expand All @@ -110,9 +105,9 @@ jobs:
# build variables are available. Because of this, we need to find another way to generate a
# unique login. So instead, we'll use the the name of the platform and the python version,
# which should make it unique.
SG_HUMAN_LOGIN: $(python_api_human_login)-${{parameters.name}}-$(python.version)
SG_HUMAN_LOGIN: $(python_api_human_login)-${{ parameters.os_name }}-${{ parameters.python_version }}
# This will give a user name like 'something macOS 2.7'
SG_HUMAN_NAME: $(python_api_human_name) ${{parameters.name}} $(python.version)
SG_HUMAN_NAME: $(python_api_human_name) ${{ parameters.os_name }} ${{ parameters.python_version }}
SG_HUMAN_PASSWORD: $(python_api_human_password)
# So, first, we need to make sure that two builds running at the same time do not manipulate
# the same entities, so we're sandboxing build nodes based on their name.
Expand All @@ -123,20 +118,20 @@ jobs:
# Again, this would have been a lot simpler if we could simply have had a login based on the
# agent name, but alas, the agent name has a space in it which needs to be replaced to something
# else and string substitution can't be made on build variables, only template parameters.
SG_ASSET_CODE: CI-$(python_api_human_login)-${{parameters.name}}-$(python.version)
SG_VERSION_CODE: CI-$(python_api_human_login)-${{parameters.name}}-$(python.version)
SG_SHOT_CODE: CI-$(python_api_human_login)-${{parameters.name}}-$(python.version)
SG_TASK_CONTENT: CI-$(python_api_human_login)-${{parameters.name}}-$(python.version)
SG_PLAYLIST_CODE: CI-$(python_api_human_login)-${{parameters.name}}-$(python.version)
SG_ASSET_CODE: CI-$(python_api_human_login)-${{ parameters.os_name }}-${{ parameters.python_version }}
SG_VERSION_CODE: CI-$(python_api_human_login)-${{ parameters.os_name }}-${{ parameters.python_version }}
SG_SHOT_CODE: CI-$(python_api_human_login)-${{ parameters.os_name }}-${{ parameters.python_version }}
SG_TASK_CONTENT: CI-$(python_api_human_login)-${{ parameters.os_name }}-${{ parameters.python_version }}
SG_PLAYLIST_CODE: CI-$(python_api_human_login)-${{ parameters.os_name }}-${{ parameters.python_version }}

# Upload the code coverage result to codecov.io.
- ${{ if eq(parameters.name, 'Windows') }}:
- ${{ if eq(parameters.os_name, 'Windows') }}:
- powershell: |
$ProgressPreference = 'SilentlyContinue'
Invoke-WebRequest -Uri https://uploader.codecov.io/latest/windows/codecov.exe -Outfile codecov.exe
.\codecov.exe -f coverage.xml
displayName: Uploading code coverage
- ${{ elseif eq(parameters.name, 'Linux') }}:
- ${{ elseif eq(parameters.os_name, 'Linux') }}:
- script: |
curl -Os https://uploader.codecov.io/latest/linux/codecov
chmod +x codecov
Expand Down
44 changes: 27 additions & 17 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,26 @@ pr:
include:
- "*"

parameters:
- name: python_versions
type: object
default:
- '3.9'
- '3.10'
- '3.11'

- name: os_versions
type: object
default:
- name: Linux
vm_image: ubuntu-latest

- name: macOS
vm_image: macOS-latest

- name: Windows
vm_image: windows-latest

# This here is the list of jobs we want to run for our build.
# Jobs run in parallel.
jobs:
Expand All @@ -71,20 +91,10 @@ jobs:

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

# These are jobs templates, they allow to reduce the redundancy between
# variations of the same build. We pass in the image name
# and a friendly name that then template can then use to create jobs.
- template: azure-pipelines-templates/run-tests.yml
parameters:
name: Linux
vm_image: 'ubuntu-latest'

- template: azure-pipelines-templates/run-tests.yml
parameters:
name: macOS
vm_image: 'macOS-latest'

- template: azure-pipelines-templates/run-tests.yml
parameters:
name: Windows
vm_image: 'windows-latest'
- ${{ each os_version in parameters.os_versions }}:
- ${{ each python_version in parameters.python_versions }}:
- template: azure-pipelines-templates/run-tests.yml
parameters:
os_name: "${{ os_version.name }}"
vm_image: ${{ os_version.vm_image }}
python_version: ${{ python_version }}