|
| 1 | +parameters: |
| 2 | + - name: TestPipeline |
| 3 | + type: boolean |
| 4 | + default: false |
| 5 | + - name: ServiceDirectory |
| 6 | + type: string |
| 7 | + default: '' |
| 8 | + - name: CondaArtifacts |
| 9 | + type: object |
| 10 | + default: [] |
| 11 | + - name: TestMarkArgument |
| 12 | + type: string |
| 13 | + default: '' |
| 14 | + - name: PythonVersion |
| 15 | + type: string |
| 16 | + default: '' |
| 17 | + - name: OSVmImage |
| 18 | + type: string |
| 19 | + default: '' |
| 20 | + - name: Matrix |
| 21 | + type: string |
| 22 | + - name: DependsOn |
| 23 | + type: string |
| 24 | + default: '' |
| 25 | + - name: UsePlatformContainer |
| 26 | + type: boolean |
| 27 | + default: false |
| 28 | + - name: TestTimeoutInMinutes |
| 29 | + type: number |
| 30 | + default: 0 |
| 31 | + - name: CloudConfig |
| 32 | + type: object |
| 33 | + default: {} |
| 34 | + |
| 35 | +jobs: |
| 36 | + - job: |
| 37 | + displayName: 'Test Conda' |
| 38 | + condition: | |
| 39 | + and( |
| 40 | + succeededOrFailed(), |
| 41 | + ne(variables['Skip.TestConda'], 'true') |
| 42 | + ) |
| 43 | + timeoutInMinutes: ${{ parameters.TestTimeoutInMinutes }} |
| 44 | + |
| 45 | + dependsOn: |
| 46 | + - ${{ parameters.DependsOn }} |
| 47 | + |
| 48 | + strategy: |
| 49 | + matrix: $[ ${{ parameters.Matrix }} ] |
| 50 | + |
| 51 | + pool: |
| 52 | + name: $(Pool) |
| 53 | + vmImage: $(OSVmImage) |
| 54 | + |
| 55 | + ${{ if eq(parameters.UsePlatformContainer, 'true') }}: |
| 56 | + # Add a default so the job doesn't fail when the matrix is empty |
| 57 | + container: $[ variables['Container'] ] |
| 58 | + |
| 59 | + variables: |
| 60 | + - template: ../variables/globals.yml |
| 61 | + |
| 62 | + steps: |
| 63 | + - task: DownloadPipelineArtifact@2 |
| 64 | + inputs: |
| 65 | + artifactName: 'conda' |
| 66 | + targetPath: $(Build.ArtifactStagingDirectory) |
| 67 | + |
| 68 | + - template: /eng/common/pipelines/templates/steps/set-test-pipeline-version.yml |
| 69 | + parameters: |
| 70 | + PackageName: "azure-template" |
| 71 | + ServiceDirectory: "template" |
| 72 | + TestPipeline: ${{ parameters.TestPipeline }} |
| 73 | + |
| 74 | + - task: UsePythonVersion@0 |
| 75 | + displayName: 'Use Python $(PythonVersion)' |
| 76 | + inputs: |
| 77 | + versionSpec: $(PythonVersion) |
| 78 | + |
| 79 | + - pwsh: | |
| 80 | + # due to faulty deployed scripts/how the path gets manipulated by conda actions on |
| 81 | + # ubuntu and mac, we can't rely on bin/scripts being referenced correctly. see |
| 82 | + # https://github.com/MicrosoftDocs/azure-devops-docs/issues/3812 |
| 83 | + $activateMethod = "source $($env:CONDA)/bin/activate" |
| 84 | +
|
| 85 | + # pypy3 is not a true python executable. in conda-land, we need to call it using pypy3, NOT python |
| 86 | +
|
| 87 | + # on windows, we need to add "--user" as otherwise pip won't successfully install/uninstall due to |
| 88 | + # how windows holds reservation on pip.exe. this is unnecessary on ubuntu/mac. |
| 89 | + $requirementSuffix = "" |
| 90 | +
|
| 91 | + # we always want to prepend the path with conda bin |
| 92 | + Write-Host "##vso[task.prependpath]]$($env:CONDA)/bin" |
| 93 | +
|
| 94 | + if ($IsWindows) { |
| 95 | + # powershell does not have an equivalent of call/source, which is necessary when |
| 96 | + # using conda in azure devops. Note that we use `activate` natively here, as |
| 97 | + # a later path prepend of the /scripts directory actually works. |
| 98 | + $activateMethod = "call activate" |
| 99 | + $requirementSuffix = " --user" |
| 100 | +
|
| 101 | + # on windows only, need to prepend with the scripts directory as well |
| 102 | + Write-Host "##vso[task.prependpath]$($env:CONDA)/Scripts" |
| 103 | + } |
| 104 | +
|
| 105 | + if("$(PythonVersion)" -eq "pypy3"){ |
| 106 | + Write-Host "##vso[task.setvariable variable=PyVersion]-c conda-forge pypy3.7 pip" |
| 107 | + } |
| 108 | + else { |
| 109 | + Write-Host "##vso[task.setvariable variable=PyVersion]python=$(PythonVersion)" |
| 110 | + } |
| 111 | + |
| 112 | + # we will use these variables extensively later |
| 113 | + Write-Host "##vso[task.setvariable variable=activate.method]$activateMethod" |
| 114 | + Write-Host "##vso[task.setvariable variable=requirement.suffix]$requirementSuffix" |
| 115 | + displayName: 'Evaluate OS Specific PATH and Parameters' |
| 116 | +
|
| 117 | + - ${{ each artifact in parameters.CondaArtifacts }}: |
| 118 | + # due to the fact that `pypy3` and `conda-build` conda packages are INCOMPATIBLE, we have to create |
| 119 | + # a separate env to install `conda-build` and use that to `conda index` the local file channel |
| 120 | + - script: | |
| 121 | + echo "conda create --name ${{ artifact.name }} $(PyVersion) --yes" |
| 122 | + conda create --name ${{ artifact.name }} $(PyVersion) --yes |
| 123 | +
|
| 124 | + echo "conda create --name index-env --yes" |
| 125 | + conda create --name index-env --yes |
| 126 | +
|
| 127 | + echo "conda install --name index-env --yes --quiet conda-build" |
| 128 | + conda install --name index-env --yes --quiet conda-build |
| 129 | +
|
| 130 | + echo "$(activate.method) index-env" |
| 131 | + $(activate.method) index-env |
| 132 | +
|
| 133 | + echo "conda index $(Build.ArtifactStagingDirectory)/${{ artifact.name }}" |
| 134 | + conda index $(Build.ArtifactStagingDirectory)/${{ artifact.name }} |
| 135 | + displayName: 'Prepare Conda Environment for Testing ${{ artifact.name }}, Index the Target Local Artifact' |
| 136 | +
|
| 137 | + - script: | |
| 138 | + echo "$(activate.method) ${{ artifact.name }}" |
| 139 | + $(activate.method) ${{ artifact.name }} |
| 140 | +
|
| 141 | + echo "python -m pip install -r eng/ci_tools.txt $(requirement.suffix)" |
| 142 | + python -m pip install -r eng/ci_tools.txt $(requirement.suffix) |
| 143 | + displayName: 'Activate Conda Environment and Install General Dependencies ${{ artifact.name }}' |
| 144 | +
|
| 145 | + - pwsh: | |
| 146 | + mkdir $(Agent.BuildDirectory)/conda/ |
| 147 | + Write-Host "##vso[task.setvariable variable=conda.build]$(Agent.BuildDirectory)/conda_checkout" |
| 148 | + displayName: 'Create Conda Working Directory for Testing' |
| 149 | +
|
| 150 | + - script: | |
| 151 | + echo "$(activate.method) ${{ artifact.name }}" |
| 152 | + $(activate.method) ${{ artifact.name }} |
| 153 | +
|
| 154 | + echo "python -m pip install -r $(Build.SourcesDirectory)/eng/conda_test_requirements.txt" |
| 155 | + python -m pip install -r $(Build.SourcesDirectory)/eng/conda_test_requirements.txt |
| 156 | +
|
| 157 | + python -m pip uninstall azure-core -y |
| 158 | + displayName: 'Prep Conda Environment w/ Dependencies' |
| 159 | +
|
| 160 | + - script: | |
| 161 | + echo "conda install --name ${{ artifact.name }} ${{ artifact.name }} -c $(Build.ArtifactStagingDirectory)/${{ artifact.name }} --yes -c $(AzureSDKCondaChannel)" |
| 162 | + conda install --name ${{ artifact.name }} ${{ artifact.name }} -c $(Build.ArtifactStagingDirectory)/${{ artifact.name }} --yes -c $(AzureSDKCondaChannel) |
| 163 | +
|
| 164 | + echo "conda install --name ${{ artifact.name }} azure-identity -c $(Build.ArtifactStagingDirectory)/${{ artifact.name }} -c $(AzureSDKCondaChannel) --yes" |
| 165 | + conda install --name ${{ artifact.name }} azure-identity -c $(Build.ArtifactStagingDirectory)/${{ artifact.name }} -c $(AzureSDKCondaChannel) --yes |
| 166 | +
|
| 167 | + echo "$(activate.method) ${{ artifact.name }}" |
| 168 | + $(activate.method) ${{ artifact.name }} |
| 169 | + python -m pip freeze |
| 170 | + displayName: 'Install ${{ artifact.name }} Conda Package' |
| 171 | +
|
| 172 | + - ${{ each checkout in artifact.checkout }}: |
| 173 | + - pwsh: |
| 174 | + Write-Host "Clean up Conda Build Directory $(conda.build)" |
| 175 | + Remove-Item $(conda.build)/* -Recurse -Force |
| 176 | + displayName: 'Clean Up Before Testing ${{ artifact.name }}' |
| 177 | + |
| 178 | + - template: /eng/common/pipelines/templates/steps/sparse-checkout.yml |
| 179 | + parameters: |
| 180 | + Paths: |
| 181 | + - "${{ checkout.checkout_path }}" |
| 182 | + - "sdk/conftest.py" |
| 183 | + - "tools/" |
| 184 | + Repositories: |
| 185 | + - Name: "Azure/azure-sdk-for-python" |
| 186 | + Commitish: "${{ checkout.Package }}_${{ checkout.Version }}" |
| 187 | + WorkingDirectory: "$(conda.build)" |
| 188 | + SkipDefaultCheckout: true |
| 189 | + |
| 190 | + - script: | |
| 191 | + echo "$(activate.method) ${{ artifact.name }}" |
| 192 | + $(activate.method) ${{ artifact.name }} |
| 193 | + python -m pytest $(conda.build)/${{ checkout.checkout_path }}/${{ checkout.package }} |
| 194 | + displayName: 'Run Tests for ${{ checkout.package }}' |
0 commit comments