-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuildfile.m
More file actions
99 lines (77 loc) · 3.18 KB
/
Copy pathbuildfile.m
File metadata and controls
99 lines (77 loc) · 3.18 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
function plan = buildfile
% Create a plan from the tasks in this file
plan = buildplan;
% Add tasks
plan("test") = matlab.buildtool.Task();
plan("test").Actions = @testAction;
plan("check") = matlab.buildtool.Task();
plan("check").Actions = @checkAction;
plan("package") = matlab.buildtool.Task();
plan("package").Actions = @packageAction;
plan("ci") = matlab.buildtool.Task();
plan("ci").Description = "Full CI pipeline";
plan("ci").Dependencies = ["check", "test", "package"];
% Default task is 'test'
plan.DefaultTasks = "test";
end
function testAction(context)
% Run the full test suite with code coverage
import matlab.unittest.TestRunner
import matlab.unittest.plugins.CodeCoveragePlugin
import matlab.unittest.plugins.codecoverage.CoverageReport
import matlab.unittest.plugins.codecoverage.CoberturaFormat
suite = testsuite("tests");
runner = TestRunner.withTextOutput;
covFolder = fullfile("build", "coverage");
if ~exist(covFolder, 'dir')
mkdir(covFolder);
end
% Cobertura and HTML
xmlFile = fullfile(covFolder, "coverage.xml");
% Target only runtime .m files in toolbox/ and its subfolders,
% excluding documentation and examples.
allFiles = dir(fullfile("toolbox", "**", "*.m"));
allFiles = allFiles(~[allFiles.isdir]);
sourceFiles = fullfile({allFiles.folder}, {allFiles.name});
% Exclude documentation and examples from runtime coverage checks.
isExample = contains(sourceFiles, fullfile("toolbox", "examples"));
isDoc = contains(sourceFiles, fullfile("toolbox", "doc"));
sourceFiles = sourceFiles(endsWith(sourceFiles, ".m") & ~isExample & ~isDoc);
% Use multiple formats in one plugin call
formats = [CoverageReport(covFolder), CoberturaFormat(xmlFile)];
runner.addPlugin(CodeCoveragePlugin.forFile(sourceFiles, ...
'Producing', formats));
results = runner.run(suite);
if any([results.Failed]) || any([results.Incomplete])
error("test:Failed", "One or more tests failed or were incomplete.");
end
% Check coverage threshold
addpath("scripts");
checkCoverage(xmlFile, 0.90);
end
function checkAction(context)
% Run CodeIssuesTask on toolbox/
issues = codeIssues("toolbox");
if ~isempty(issues.Issues)
disp(issues.Issues);
end
end
function packageAction(context)
% Package the toolbox
prjFile = "matlab-http-server.prj";
outFile = "matlab-http-server.mltbx";
% Check for GITHUB_REF_NAME environment variable to set version
version = string(getenv("GITHUB_REF_NAME"));
if startsWith(version, "v")
version = extractAfter(version, 1);
fprintf('Setting toolbox version to %s (from GITHUB_REF_NAME)\n', version);
opts = matlab.addons.toolbox.ToolboxOptions(prjFile);
opts.ToolboxVersion = version;
opts.OutputFile = outFile;
fprintf('Packaging into %s...\n', outFile);
matlab.addons.toolbox.packageToolbox(opts);
else
fprintf('Packaging %s into %s...\n', prjFile, outFile);
matlab.addons.toolbox.packageToolbox(prjFile, outFile);
end
end