forked from tox-dev/azure-pipelines-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun-tox-vsc-env.yml
211 lines (191 loc) · 9.87 KB
/
run-tox-vsc-env.yml
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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
parameters:
jobs:
py39:
py36:
py27:
# cap versions still compatible with Python 3.6
tox_version: "'virtualenv<20.22.0' 'tox<4.5.0'"
coverage:
with_toxenv: ""
for_envs: []
dependsOn: []
vsc_requires: []
system_requires: []
jobs:
- ${{ each job in parameters.jobs }}:
- job: ${{ coalesce(job.value.name, job.key) }}
dependsOn: ${{ coalesce(job.value.dependsOn, parameters.dependsOn) }}
pool:
vmImage: "ubuntu-20.04"
variables:
TMPDIR: $(Agent.TempDirectory)
PIP_NO_WARN_SCRIPT_LOCATION: "0"
PIP_DISABLE_PIP_VERSION_CHECK: "1"
TOXENV: ${{ coalesce(job.value.toxenv, job.key) }}
PYTHONWARNINGS: "ignore:::pip._internal.cli.base_command"
# make a string with all request system packages if any
${{ if and(parameters.system_requires, gt(length(parameters.system_requires), 0)) }}:
system_packages: ${{ join(' ', parameters.system_requires) }}
# having extra VSC packages moves the source directory into its own sub-folder
# if length 'vsc_requires' > 0, overwrite global TOXDIR variable
${{ if gt(length(parameters.vsc_requires), 0) }}:
TOXDIR: $(Build.SourcesDirectory)/$(Build.Repository.Name)
${{ if eq(length(parameters.vsc_requires), 0) }}:
TOXDIR: $(Build.SourcesDirectory)
steps:
# install any extra system packages if requested
- ${{ if variables.system_packages }}:
- script: |
sudo apt-get -qq -y update
sudo apt-get install -qq -y ${{variables.system_packages}}
displayName: "Install requested system packages"
# checkout with submodules please
- checkout: self
displayName: checkout source code (with submodules)
submodules: true
# azure stuff uses the repo name itself but github has org/repo structure...
path: s/$(Build.Repository.Name)
# load tox
- task: UsePythonVersion@0
displayName: "tox: get python"
inputs:
versionSpec: "3.8"
addToPath: false
name: toxPython
- script: $(toxPython.pythonLocation)/python -m pip install -U --user pip wheel
displayName: "tox: upgrade pip"
- ${{ if parameters.tox_version }}:
- script:
${{ format('$(toxPython.pythonLocation)/python -m pip install -U --user --force-reinstall {0}',
parameters.tox_version) }}
displayName: "${{ format('tox: install {0} from PyPi', parameters.tox_version) }}"
- ${{ if not(parameters.tox_version) }}:
- script: $(toxPython.pythonLocation)/python -m pip install -U --user --force-reinstall . -v
displayName: "tox: install inline"
# acquire target test Python
- ? ${{ if or(eq(job.key, 'py310'), startsWith(job.key, 'py310-'),
eq(job.key, 'py39'), startsWith(job.key, 'py39-'),
eq(job.key, 'py38'), startsWith(job.key, 'py38-'),
eq(job.key, 'py37'), startsWith(job.key, 'py37-'),
eq(job.key, 'py36'), startsWith(job.key, 'py36-'),
eq(job.key, 'py27'), startsWith(job.key, 'py27-'),
eq(job.key, 'pypy'), startsWith(job.key, 'pypy-'),
eq(job.key, 'pypy3'), startsWith(job.key, 'pypy3-'),
eq(job.value.py, '2.7'), eq(job.value.py, '3.6'), eq(job.value.py, '3.7'),
eq(job.value.py, 'pypy2'), eq(job.value.py, 'pypy3')) }}
: - task: UsePythonVersion@0
displayName: ${{ format('provision target test python {0}', job.key) }}
inputs:
${{ if job.value.py }}:
versionSpec: ${{ job.value.py }}
${{ if not(job.value.py) }}:
${{ if or(eq(job.key, 'py27'), startsWith(job.key, 'py27-')) }}:
versionSpec: "2.7"
${{ if or(eq(job.key, 'py36'), startsWith(job.key, 'py36-')) }}:
versionSpec: "3.6"
${{ if or(eq(job.key, 'py37'), startsWith(job.key, 'py37-')) }}:
versionSpec: "3.7"
${{ if or(eq(job.key, 'py38'), startsWith(job.key, 'py38-')) }}:
versionSpec: "3.8"
${{ if or(eq(job.key, 'py39'), startsWith(job.key, 'py39-')) }}:
versionSpec: "3.9"
${{ if or(eq(job.key, 'py310'), startsWith(job.key, 'py310-')) }}:
versionSpec: "3.10"
${{ if or(eq(job.key, 'pypy'), startsWith(job.key, 'pypy-')) }}:
versionSpec: "pypy2"
${{ if or(eq(job.key, 'pypy3'), startsWith(job.key, 'pypy3-')) }}:
versionSpec: "pypy3"
architecture: ${{ coalesce(job.value.architecture, 'x64') }}
- ${{ if or(eq(job.key, 'jython'), startsWith(job.key, 'jython-')) }}:
- script:
wget
http://search.maven.org/remotecontent?filepath=org/python/jython-installer/2.7.2/jython-installer-2.7.2.jar
-O $(Agent.ToolsDirectory)/jython.jar
displayName: download jython
- script: java -jar $(Agent.ToolsDirectory)/jython.jar -sd $(Agent.ToolsDirectory)/jython -e demo src doc
displayName: install jython
- script: echo "##vso[task.setvariable variable=PATH]$(Agent.ToolsDirectory)/jython/bin:$(PATH)"
displayName: add to PATH jython
- script: 'jython -c "import sys; print(sys.version_info); print(sys.platform)'
displayName: show jython information
# allow user to run global before
- ${{ if parameters.before }}:
- ${{ parameters.before }}
# allow user to run per job setup
- ${{ if job.value.before }}:
- ${{ job.value.before }}
- script:
'python -c "import sys; import os; print(\"\n\".join(os.environ[\"PATH\"].split(os.pathsep)));
print(sys.version); print(sys.executable);"'
displayName: show python information
- script: $(toxPython.pythonLocation)/python -m tox -av
displayName: "tox: provision and show envs"
workingDirectory: $(TOXDIR)
# run tests
- script: $(toxPython.pythonLocation)/python -m tox --notest -vv --skip-missing-interpreters false
displayName: "tox: generate test environment"
workingDirectory: $(TOXDIR)
# install VSC required packages inside tox environment
- ${{ if and(parameters.vsc_requires, gt(length(parameters.vsc_requires), 0)) }}:
- script: |
python_toxenv="$(TOXDIR)/.tox/${{ job.key }}/bin/python"
$python_toxenv -m pip install wheel vsc-install
displayName: "vsc: install vsc-install"
env:
PYTHON_HOME: ""
VIRTUAL_ENV: ${{ job.key }}
- ${{ each vscpkg in parameters.vsc_requires }}:
- checkout: ${{ vscpkg }}
persistCredentials: true
displayName: "${{ format('vsc: clone {0}', vscpkg) }}"
- script: |
python_toxenv="$(TOXDIR)/.tox/${{ job.key }}/bin/python"
$python_toxenv -m pip install $(Build.SourcesDirectory)/${{ vscpkg }}
displayName: "${{ format('vsc: install {0}', vscpkg) }}"
env:
PYTHON_HOME: ""
VIRTUAL_ENV: ${{ job.key }}
- script: $(toxPython.pythonLocation)/python -m tox
displayName: "tox: run test environment"
workingDirectory: $(TOXDIR)
# upload junit result if present
- bash:
'printf "##vso[task.setVariable variable=junit]" && ([ -f junit.$(TOXENV).xml ] && printf yes || printf
no) && echo ""'
condition: always()
displayName: check if junit file present
workingDirectory: $(TOXDIR)/.tox
- task: PublishTestResults@2
displayName: publish test results via junit
condition: eq(variables.junit, 'yes')
inputs:
testResultsFormat: "JUnit"
testResultsFiles: "$(TOXDIR)/.tox/junit.$(TOXENV).xml"
testRunTitle: "junit-$(Agent.OS)-$(Agent.OSArchitecture)-$(TOXENV)"
# upload coverage artifacts if present
- ${{ if and(parameters.coverage.with_toxenv, containsValue(parameters.coverage.for_envs, job.key)) }}:
- script:
${{ format('$(toxPython.pythonLocation)/python -m tox -e {0} --skip-missing-interpreters false',
parameters.coverage.with_toxenv) }}
displayName: create coverage report
- task: CopyFiles@2
displayName: move coverage files into staging area
inputs:
sourceFolder: $(TOXDIR)/.tox
contents: |
.coverage
coverage.xml
targetFolder: $(Build.StagingDirectory)
- task: PublishBuildArtifacts@1
displayName: publish coverage file
inputs:
pathtoPublish: $(Build.ArtifactStagingDirectory)
ArtifactName: "coverage-$(Agent.OS)-$(Agent.OSArchitecture)-$(TOXENV)"
- ${{ if job.value.after }}:
- ${{ job.value.after }}
- ${{ if and(parameters.coverage.with_toxenv, parameters.coverage.for_envs) }}:
- template: merge-coverage.yml
parameters:
tox_version: ${{ parameters.tox_version }}
toxenv: ${{ parameters.coverage.with_toxenv }}
dependsOn: ${{ parameters.coverage.for_envs }}