-
Notifications
You must be signed in to change notification settings - Fork 204
Expand file tree
/
Copy pathrun-tests.yml
More file actions
152 lines (143 loc) · 7.85 KB
/
run-tests.yml
File metadata and controls
152 lines (143 loc) · 7.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
# -----------------------------------------------------------------------------
# Copyright (c) 2009-2021, Shotgun Software Inc.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# - Redistributions of source code must retain the above copyright notice, this
# list of conditions and the following disclaimer.
#
# - Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
#
# - Neither the name of the Shotgun Software Inc nor the names of its
# contributors may be used to endorse or promote products derived from this
# software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
# This is the list of parameters for this template and their default values.
parameters:
name: ''
vm_image: ''
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 Python27" 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> Python27" and
# "<OS> Python37".
- job: ${{ parameters.name }}
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.
Python37:
python.version: '3.7'
Python39:
python.version: '3.9'
Python310:
python.version: '3.10'
Python311:
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)
# 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
# Install all dependencies needed for running the tests. This command is good for
# Python 2 and 3, but also for all OSes
- script: |
python -m pip install --upgrade pip setuptools wheel
python -m pip install -r tests/ci_requirements.txt
displayName: Install tools
# 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') }}:
# 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! ;)
- powershell: |
$cert_url = "https://www.amazontrust.com/repository/SFSRootCAG2.cer"
$cert_file = New-TemporaryFile
Invoke-WebRequest -Uri $cert_url -UseBasicParsing -OutFile $cert_file.FullName
Import-Certificate -FilePath $cert_file.FullName -CertStoreLocation Cert:\LocalMachine\Root
displayName: Updating OS Certificates
# 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 -v --cov shotgun_api3 --cov-report xml --test-run-title="${{parameters.name}}-$(python.version)"
displayName: Running tests
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
# will be empty!
SG_SERVER_URL: $(ci_site)
SG_SCRIPT_NAME: $(ci_site_script_name)
SG_API_KEY: $(ci_site_script_key)
# The unit tests manipulate the user and project during the tests, which can cause collisions,
# so sandbox each build variant.
# Ideally, we would use the agent name here. The problem is that the agent name is in a build
# variable, so we can't edit it's value through a ${{replace(a,b,c)}} expression, which are evaluated before
# 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)
# This will give a user name like 'something macOS 2.7'
SG_HUMAN_NAME: $(python_api_human_name) ${{parameters.name}} $(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.
SG_PROJECT_NAME: Python API CI - $(Agent.Name)
# The entities created and then reused between tests assume that the same user is always
# manipulating them. Because different builds will be assigned different agents and therefore
# different projects, it means each project needs to have an entity specific to a given user.
# 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)
# Upload the code coverage result to codecov.io.
- ${{ if eq(parameters.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') }}:
- script: |
curl -Os https://uploader.codecov.io/latest/linux/codecov
chmod +x codecov
./codecov -f coverage.xml
displayName: Uploading code coverage
- ${{ else }}:
- script: |
curl -Os https://uploader.codecov.io/latest/macos/codecov
chmod +x codecov
./codecov -f coverage.xml
displayName: Uploading code coverage