forked from mathworks/matlab-azure-devops-extension
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinteg-test-promote.pipeline.yml
441 lines (416 loc) · 17.7 KB
/
integ-test-promote.pipeline.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
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
resources:
pipelines:
- pipeline: integ_test_promote
source: pre-integ-test
trigger: true
trigger: none
pr: none
stages:
- stage: integration_test
displayName: Integration test
jobs:
- job: test_install
strategy:
matrix:
microsoft_hosted_linux:
poolName: Azure Pipelines
vmImage: ubuntu-22.04
microsoft_hosted_macos:
poolName: Azure Pipelines
vmImage: macOS-latest
microsoft_hosted_windows:
poolName: Azure Pipelines
vmImage: windows-latest
pool:
name: $(poolName)
vmImage: $(vmImage)
steps:
- checkout: none
- task: MathWorks.matlab-azure-devops-extension-dev.InstallMATLAB.InstallMATLAB@0
displayName: Install MATLAB
- bash: |
set -e
matlab -batch version
os=$(uname)
if [[ $os = CYGWIN* || $os = MINGW* || $os = MSYS* ]]; then
mex.bat -h
else
mex -h
fi
displayName: Check matlab and mex
- job: test_install_release
strategy:
matrix:
microsoft_hosted_linux:
poolName: Azure Pipelines
vmImage: ubuntu-22.04
microsoft_hosted_macos:
poolName: Azure Pipelines
vmImage: macOS-latest
microsoft_hosted_windows:
poolName: Azure Pipelines
vmImage: windows-latest
pool:
name: $(poolName)
vmImage: $(vmImage)
steps:
- checkout: none
- task: MathWorks.matlab-azure-devops-extension-dev.InstallMATLAB.InstallMATLAB@0
displayName: Install MATLAB
inputs:
release: R2021a
- bash: |
set -e
matlab -batch "assert(strcmp(version('-release'),'2021a'))"
displayName: Check matlab release
- job: test_run_command
strategy:
matrix:
microsoft_hosted_linux:
poolName: Azure Pipelines
vmImage: ubuntu-22.04
microsoft_hosted_macos:
poolName: Azure Pipelines
vmImage: macOS-latest
microsoft_hosted_windows:
poolName: Azure Pipelines
vmImage: windows-latest
self_hosted_windows:
poolName: vmssagentpool
vmImage: # blank for self-hosted
pool:
name: $(poolName)
vmImage: $(vmImage)
steps:
- checkout: none
- task: MathWorks.matlab-azure-devops-extension-dev.InstallMATLAB.InstallMATLAB@0
displayName: Install MATLAB on Microsoft-hosted agents
condition: not(startsWith(variables['Agent.Name'], 'vmss'))
- task: MathWorks.matlab-azure-devops-extension-dev.RunMATLABCommand.RunMATLABCommand@0
displayName: Run MATLAB statement
inputs:
command: f = fopen('myscript.m', 'w'); fwrite(f, 'assert(true)'); fclose(f);
- task: MathWorks.matlab-azure-devops-extension-dev.RunMATLABCommand.RunMATLABCommand@0
displayName: Run MATLAB script
inputs:
command: myscript
- task: MathWorks.matlab-azure-devops-extension-dev.RunMATLABCommand.RunMATLABCommand@0
displayName: Run MATLAB statement with quotes 1
inputs:
command: "eval(\"a = 1+2\"); assert(a == 3); eval('b = 3+4'); assert(b == 7);"
- task: MathWorks.matlab-azure-devops-extension-dev.RunMATLABCommand.RunMATLABCommand@0
displayName: Run MATLAB statement with quotes 2
inputs:
command: 'eval("a = 1+2"); assert(a == 3); eval(''b = 3+4''); assert(b == 7);'
- task: MathWorks.matlab-azure-devops-extension-dev.RunMATLABCommand.RunMATLABCommand@0
displayName: Run MATLAB statement with quotes 3
inputs:
command: a = """hello world"""; b = '"hello world"'; assert(strcmp(a,b));
- task: MathWorks.matlab-azure-devops-extension-dev.RunMATLABCommand.RunMATLABCommand@0
displayName: Run MATLAB statement with symbols
inputs:
command: a = " !""#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~"; b = char([32:126]); assert(strcmp(a, b), a+b);
- task: MathWorks.matlab-azure-devops-extension-dev.RunMATLABCommand.RunMATLABCommand@0
displayName: Run MATLAB statement in working directory
inputs:
command: exp = getenv('SYSTEM_DEFAULTWORKINGDIRECTORY'); act = pwd; assert(strcmp(act, exp), strjoin({act exp}, '\n'));
- bash: |
echo 'myvar = 123' > startup.m
displayName: Create startup.m
- task: MathWorks.matlab-azure-devops-extension-dev.RunMATLABCommand.RunMATLABCommand@0
displayName: MATLAB runs startup.m automatically
inputs:
command: assert(myvar==123, 'myvar was not set as expected by startup.m')
- job: test_run_tests
strategy:
matrix:
microsoft_hosted_linux:
poolName: Azure Pipelines
vmImage: ubuntu-22.04
self_hosted_windows:
poolName: vmssagentpool
vmImage: # blank for self-hosted
pool:
name: $(poolName)
vmImage: $(vmImage)
workspace:
clean: all
steps:
- checkout: none
- task: MathWorks.matlab-azure-devops-extension-dev.InstallMATLAB.InstallMATLAB@0
displayName: Install MATLAB on Microsoft-hosted agents
condition: not(startsWith(variables['Agent.Name'], 'vmss'))
- bash: |
echo 'myvar = 123' > startup.m
mkdir src
echo 'function c=add(a,b);c=a+b;' > src/add.m
mkdir tests
echo "%% StartupTest" > tests/mytest.m
echo "evalin('base','assert(myvar==123)')" >> tests/mytest.m
echo "%% FirstTest" >> tests/mytest.m
echo "assert(add(1,2)==3)" >> tests/mytest.m
mkdir tests/filteredTest
echo "%% simpleTest" >> tests/filteredTest/filtertest.m
echo "assert(2==2)" >> tests/filteredTest/filtertest.m
echo "%% FilterByTag" >> tests/filteredTest/TaggedTest.m
cat << EOF > tests/filteredTest/TaggedTest.m
classdef (TestTags = {'FILTERED'}) TaggedTest < matlab.unittest.TestCase
methods(Test)
function testTag(testCase)
assert(2==2);
end
end
end
EOF
displayName: Make MATLAB tests
- task: MathWorks.matlab-azure-devops-extension-dev.RunMATLABTests.RunMATLABTests@0
displayName: Run MATLAB tests with defaults
inputs:
sourceFolder: src
- task: MathWorks.matlab-azure-devops-extension-dev.RunMATLABTests.RunMATLABTests@0
displayName: Run MATLAB tests producing artifacts
inputs:
testResultsJUnit: test-results/matlab/results.xml
codeCoverageCobertura: code-coverage/coverage.xml
sourceFolder: src
- task: MathWorks.matlab-azure-devops-extension-dev.RunMATLABTests.RunMATLABTests@0
displayName: Run MATLAB tests filter by folder
inputs:
testResultsJUnit: test-results/matlab/selectbyfolder.xml
selectByFolder: tests/filteredTest
- task: MathWorks.matlab-azure-devops-extension-dev.RunMATLABTests.RunMATLABTests@0
displayName: Run MATLAB tests filter by folder
inputs:
testResultsJUnit: test-results/matlab/selectbytag.xml
selectByTag: FILTERED
- bash: |
set -e
grep -q FirstTest test-results/matlab/results.xml
displayName: Verify test results file was created
- bash: |
set -e
grep -q add code-coverage/coverage.xml
displayName: Verify code coverage file was created
- bash: |
set -e
grep -q simpleTest test-results/matlab/selectbyfolder.xml
grep -v FirstTest test-results/matlab/selectbyfolder.xml
displayName: Verify test filtered by folder
- bash: |
set -e
grep -q TaggedTest test-results/matlab/selectbytag.xml
grep -v FirstTest test-results/matlab/selectbytag.xml
grep -v simpleTest test-results/matlab/selectbytag.xml
displayName: Verify test filtered by tag name
- bash: |
mkdir simtests
cat << EOF > simtests/createModel.m
% Create model
model = 'new_temp_model';
new_system(model);
load_system(model);
% add blocks
add_block('built-in/Inport', [model, '/InputPort'], ...
'Position', [50 50 100 100]);
add_block('built-in/Gain', [model, '/Gain'], 'Gain', '1', ...
'Position', [150 50 200 100]);
add_block('built-in/Outport', [model, '/OutputPort'], ...
'Position', [250 50 300 100]);
% add lines
add_line(model, 'InputPort/1', 'Gain/1');
add_line(model, 'Gain/1', 'OutputPort/1');
% save system
save_system(model);
close_system(model);
% Create Simulink Test File
sltest.testmanager.clear;
sltest.testmanager.clearResults;
tf = sltest.testmanager.TestFile('test.mldatx');
% Set coverage related options.
cs = tf.getCoverageSettings;
cs.RecordCoverage = true;
cs.MdlRefCoverage = true;
cs.MetricSettings = 'd';
% Set model and collect baseline.
ts = tf.getTestSuites;
tc = ts.getTestCases;
tc.setProperty('model', model);
captureBaselineCriteria(tc,'baseline_API.mat',true);
% Save test file and close.
tf.saveToFile;
tf.close;
sltest.testmanager.close;
disp('Created Model and Simulink Test file to simulate the model.');
evalin('base', 'clear all');
EOF
displayName: Create model file and Simulink test.
condition: eq(variables['Agent.OS'], 'Linux')
- task: MathWorks.matlab-azure-devops-extension-dev.RunMATLABCommand.RunMATLABCommand@0
displayName: Run model creator and test Simulink test generator
inputs:
command: "cd simtests;createModel"
condition: eq(variables['Agent.OS'], 'Linux')
- task: MathWorks.matlab-azure-devops-extension-dev.RunMATLABTests.RunMATLABTests@0
displayName: Run MATLAB tests and generate Simulink test artifacts
inputs:
selectByFolder: "simtests"
modelCoverageCobertura: test-results/matlab/modelcoverage.xml
testResultsSimulinkTest: test-results/matlab/stmResult.mldatx
testResultsPDF: test-results/matlab/results.pdf
condition: eq(variables['Agent.OS'], 'Linux')
- bash: |
set -e
grep -q new_temp_model test-results/matlab/modelcoverage.xml
displayName: Verify Model coverage was created
condition: eq(variables['Agent.OS'], 'Linux')
- bash: |
set -e
test -f test-results/matlab/stmResult.mldatx
displayName: Verify STM report was created
condition: eq(variables['Agent.OS'], 'Linux')
- bash: |
set -e
test -f test-results/matlab/results.pdf
displayName: Verify PDF report was created
condition: eq(variables['Agent.OS'], 'Linux')
- job: test_run_build
strategy:
matrix:
microsoft_hosted_linux:
poolName: Azure Pipelines
vmImage: ubuntu-22.04
microsoft_hosted_macos:
poolName: Azure Pipelines
vmImage: macOS-latest
microsoft_hosted_windows:
poolName: Azure Pipelines
vmImage: windows-latest
pool:
name: $(poolName)
vmImage: $(vmImage)
steps:
- checkout: none
- task: MathWorks.matlab-azure-devops-extension-dev.InstallMATLAB.InstallMATLAB@0
displayName: Install MATLAB on Microsoft-hosted agents
condition: not(startsWith(variables['Agent.Name'], 'vmss'))
- bash: |
cat << EOF > buildfile.m
function plan = buildfile
plan = buildplan(localfunctions);
plan("test").Dependencies = "build";
plan("deploy").Dependencies = "test";
plan.DefaultTasks = "test";
function buildTask(~)
f = fopen('buildlog.txt', 'a+'); fprintf(f, 'building\n'); fclose(f);
function testTask(~)
f = fopen('buildlog.txt', 'a+'); fprintf(f, 'testing\n'); fclose(f);
function deployTask(~)
f = fopen('buildlog.txt', 'a+'); fprintf(f, 'deploying\n'); fclose(f);
function checkTask(~)
f = fopen('buildlog.txt', 'a+'); fprintf(f, 'checking\n'); fclose(f);
EOF
displayName: Create buildfile.m in project root
- task: MathWorks.matlab-azure-devops-extension-dev.RunMATLABBuild.RunMATLABBuild@0
displayName: Run build with default tasks
- bash: |
set -e
grep "building" buildlog.txt
grep "testing" buildlog.txt
! grep "deploying" buildlog.txt
! grep "checking" buildlog.txt
rm buildlog.txt
displayName: Verify that correct tasks appear in buildlog.txt
- task: MathWorks.matlab-azure-devops-extension-dev.RunMATLABBuild.RunMATLABBuild@0
displayName: Run build with specified task
inputs:
tasks: deploy
- bash: |
set -e
grep "building" buildlog.txt
grep "testing" buildlog.txt
grep "deploying" buildlog.txt
! grep "checking" buildlog.txt
rm buildlog.txt
displayName: Verify that correct tasks appear in buildlog.txt
- task: MathWorks.matlab-azure-devops-extension-dev.RunMATLABBuild.RunMATLABBuild@0
displayName: Run build with multiple specified tasks
inputs:
tasks: deploy check
- bash: |
set -e
grep "building" buildlog.txt
grep "testing" buildlog.txt
grep "deploying" buildlog.txt
grep "checking" buildlog.txt
rm buildlog.txt
displayName: Verify that correct tasks appear in buildlog.txt
- stage: publish_prerelease
displayName: Publish prerelease
condition: and(succeeded(), eq(variables['Build.SourceBranch'], 'refs/heads/master'))
pool:
vmImage: ubuntu-latest
jobs:
- deployment: publish_prerelease
environment: prerelease
strategy:
runOnce:
deploy:
steps:
- checkout: none
- task: DownloadPipelineArtifact@2
displayName: Get stored extension
inputs:
source: specific
project: b3d35465-d584-454b-a4e9-e60757510c12
pipeline: 6
runVersion: latest
artifact: extension
path: $(Build.StagingDirectory)
- task: TfxInstaller@2
displayName: Install tfx-cli
inputs:
version: v0.7.x
- task: PublishAzureDevOpsExtension@2
displayName: Publish prerelease
inputs:
connectTo: VsTeam
connectedServiceName: MathWorks
fileType: vsix
extensionTag: -prerelease
extensionVisibility: private
vsixFile: $(Build.StagingDirectory)/*.vsix
updateTasksVersion: false
- stage: publish_release
displayName: Publish release
condition: and(succeeded(), eq(variables['Build.SourceBranch'], 'refs/heads/master'))
pool:
vmImage: ubuntu-latest
jobs:
- deployment: publish_release
environment: release
strategy:
runOnce:
deploy:
steps:
- checkout: none
- task: DownloadPipelineArtifact@2
displayName: Get stored extension
inputs:
source: specific
project: b3d35465-d584-454b-a4e9-e60757510c12
pipeline: 6
runVersion: latest
artifact: extension
path: $(Build.StagingDirectory)
- task: TfxInstaller@2
displayName: Install tfx-cli
inputs:
version: v0.7.x
- task: PublishAzureDevOpsExtension@2
displayName: Publish release
inputs:
connectTo: VsTeam
connectedServiceName: MathWorks
fileType: vsix
vsixFile: $(Build.StagingDirectory)/*.vsix
updateTasksVersion: false