|
| 1 | +# ----------------------------------------------------------------------------- |
| 2 | +# Copyright (c) 2009-2021, Shotgun Software Inc. |
| 3 | +# |
| 4 | +# Redistribution and use in source and binary forms, with or without |
| 5 | +# modification, are permitted provided that the following conditions are met: |
| 6 | +# |
| 7 | +# - Redistributions of source code must retain the above copyright notice, this |
| 8 | +# list of conditions and the following disclaimer. |
| 9 | +# |
| 10 | +# - Redistributions in binary form must reproduce the above copyright notice, |
| 11 | +# this list of conditions and the following disclaimer in the documentation |
| 12 | +# and/or other materials provided with the distribution. |
| 13 | +# |
| 14 | +# - Neither the name of the Shotgun Software Inc nor the names of its |
| 15 | +# contributors may be used to endorse or promote products derived from this |
| 16 | +# software without specific prior written permission. |
| 17 | +# |
| 18 | +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
| 19 | +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 20 | +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 21 | +# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |
| 22 | +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| 23 | +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
| 24 | +# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
| 25 | +# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
| 26 | +# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 27 | +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 28 | + |
| 29 | +# This is the list of parameters for this template and their default values. |
| 30 | +parameters: |
| 31 | + name: '' |
| 32 | + vm_image: '' |
| 33 | + |
| 34 | +jobs: |
| 35 | + # The job will be named after the OS and Azure will suffix the strategy to make it unique |
| 36 | + # so we'll have a job name "Windows Python27" for example. What's a strategy? Strategies are the |
| 37 | + # name of the keys under the strategy.matrix scope. So for each OS we'll have "<OS> Python27" and |
| 38 | + # "<OS> Python37". |
| 39 | +- job: ${{ parameters.name }} |
| 40 | + pool: |
| 41 | + 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 two versions of Python. |
| 47 | + Python27: |
| 48 | + python.version: '2.7' |
| 49 | + Python37: |
| 50 | + python.version: '3.7' |
| 51 | + |
| 52 | + # These are the steps that will be executed inside each job. |
| 53 | + steps: |
| 54 | + # Specifies which version of Python we want to use. That's where the strategy comes in. |
| 55 | + # Each job will share this set of steps, but each of them will receive a different |
| 56 | + # $(python.version) |
| 57 | + - task: UsePythonVersion@0 |
| 58 | + inputs: |
| 59 | + versionSpec: '$(python.version)' |
| 60 | + addToPath: True |
| 61 | + |
| 62 | + # Install all dependencies needed for running the tests. This command is good for |
| 63 | + # Python 2 and 3, but also for all OSes |
| 64 | + - script: | |
| 65 | + python -m pip install --upgrade pip setuptools wheel |
| 66 | + python -m pip install -r tests/ci_requirements.txt |
| 67 | + displayName: Install tools |
| 68 | +
|
| 69 | + # The {{}} syntax is meant for the the pre-processor of Azure pipeline. Every statement inside |
| 70 | + # a {{}} block will be evaluated and substituted before the file is parsed to create the jobs. |
| 71 | + # So here we're inserting an extra step if the template is being invoked for Windows. |
| 72 | + - ${{ if eq(parameters.name, 'Windows') }}: |
| 73 | + # On Windows, we need to update the certificates, the cert store is missing the newer one |
| 74 | + # from Amazon like some clients experienced a while back. Who would have thought Microsoft |
| 75 | + # would have been out of date! ;) |
| 76 | + - powershell: | |
| 77 | + $cert_url = "https://www.amazontrust.com/repository/SFSRootCAG2.cer" |
| 78 | + $cert_file = New-TemporaryFile |
| 79 | + Invoke-WebRequest -Uri $cert_url -UseBasicParsing -OutFile $cert_file.FullName |
| 80 | + Import-Certificate -FilePath $cert_file.FullName -CertStoreLocation Cert:\LocalMachine\Root |
| 81 | + displayName: Updating OS Certificates |
| 82 | +
|
| 83 | + # Runs the tests and generates test coverage. The tests results are uploaded to Azure Pipelines in the |
| 84 | + # Tests tab of the build and each test run will be named after the --test-run-title argument to pytest, |
| 85 | + # for example 'Windows - 2.7' |
| 86 | + - bash: | |
| 87 | + cp ./tests/example_config ./tests/config |
| 88 | + pytest -v --cov shotgun_api3 --cov-report xml --test-run-title="${{parameters.name}}-$(python.version)" |
| 89 | + displayName: Running tests |
| 90 | + env: |
| 91 | + # Pass the values needed to authenticate with the Shotgun site and create some entities. |
| 92 | + # Remember, on a pull request from a client or on forked repos, those variables |
| 93 | + # will be empty! |
| 94 | + SG_SERVER_URL: $(ci_site) |
| 95 | + SG_SCRIPT_NAME: $(ci_site_script_name) |
| 96 | + SG_API_KEY: $(ci_site_script_key) |
| 97 | + # The unit tests manipulate the user and project during the tests, which can cause collisions, |
| 98 | + # so sandbox each build variant. |
| 99 | + # Ideally, we would use the agent name here. The problem is that the agent name is in a build |
| 100 | + # variable, so we can't edit it's value through a ${{replace(a,b,c)}} expression, which are evaluated before |
| 101 | + # build variables are available. Because of this, we need to find another way to generate a |
| 102 | + # unique login. So instead, we'll use the the name of the platform and the python version, |
| 103 | + # which should make it unique. |
| 104 | + SG_HUMAN_LOGIN: $(python_api_human_login)-${{parameters.name}}-$(python.version) |
| 105 | + # This will give a user name like 'something macOS 2.7' |
| 106 | + SG_HUMAN_NAME: $(python_api_human_name) ${{parameters.name}} $(python.version) |
| 107 | + SG_HUMAN_PASSWORD: $(python_api_human_password) |
| 108 | + # So, first, we need to make sure that two builds running at the same time do not manipulate |
| 109 | + # the same entities, so we're sandboxing build nodes based on their name. |
| 110 | + SG_PROJECT_NAME: Python API CI - $(Agent.Name) |
| 111 | + # The entities created and then reused between tests assume that the same user is always |
| 112 | + # manipulating them. Because different builds will be assigned different agents and therefore |
| 113 | + # different projects, it means each project needs to have an entity specific to a given user. |
| 114 | + # Again, this would have been a lot simpler if we could simply have had a login based on the |
| 115 | + # agent name, but alas, the agent name has a space in it which needs to be replaced to something |
| 116 | + # else and string substitution can't be made on build variables, only template parameters. |
| 117 | + SG_ASSET_CODE: CI-$(python_api_human_login)-${{parameters.name}}-$(python.version) |
| 118 | + SG_VERSION_CODE: CI-$(python_api_human_login)-${{parameters.name}}-$(python.version) |
| 119 | + SG_SHOT_CODE: CI-$(python_api_human_login)-${{parameters.name}}-$(python.version) |
| 120 | + SG_TASK_CONTENT: CI-$(python_api_human_login)-${{parameters.name}}-$(python.version) |
| 121 | + SG_TICKET_TILE: CI-$(python_api_human_login)-${{parameters.name}}-$(python.version) |
| 122 | + SG_PLAYLIST_CODE: CI-$(python_api_human_login)-${{parameters.name}}-$(python.version) |
| 123 | +
|
| 124 | + # Upload the code coverage result to codecov.io. |
| 125 | + - ${{ if eq(parameters.name, 'Windows') }}: |
| 126 | + - powershell: | |
| 127 | + $ProgressPreference = 'SilentlyContinue' |
| 128 | + Invoke-WebRequest -Uri https://uploader.codecov.io/latest/windows/codecov.exe -Outfile codecov.exe |
| 129 | + .\codecov.exe -f coverage.xml |
| 130 | + displayName: Uploading code coverage |
| 131 | + - ${{ elseif eq(parameters.name, 'Linux') }}: |
| 132 | + - script: | |
| 133 | + curl -Os https://uploader.codecov.io/latest/linux/codecov |
| 134 | + chmod +x codecov |
| 135 | + ./codecov -f coverage.xml |
| 136 | + displayName: Uploading code coverage |
| 137 | + - ${{ else }}: |
| 138 | + - script: | |
| 139 | + curl -Os https://uploader.codecov.io/latest/macos/codecov |
| 140 | + chmod +x codecov |
| 141 | + ./codecov -f coverage.xml |
| 142 | + displayName: Uploading code coverage |
0 commit comments