Skip to content

Commit 8a4dd4f

Browse files
committed
publish Git info
functionalize publish
1 parent 01cfa5c commit 8a4dd4f

File tree

2 files changed

+17
-86
lines changed

2 files changed

+17
-86
lines changed

buildfile.m

Lines changed: 11 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -4,104 +4,30 @@
44
plan("test").Dependencies = "check";
55
end
66

7-
87
function checkTask(~)
98
% Identify code issues (recursively all Matlab .m files)
109
issues = codeIssues;
1110
assert(isempty(issues.Issues), formattedDisplayText(issues.Issues))
1211
end
1312

14-
1513
function testTask(~)
16-
r = runtests('test/', strict=true, UseParallel=false);
17-
% UseParallel can be a lot slower, especially on Mac
18-
assert(~isempty(r), "No tests were run")
19-
assertSuccess(r)
20-
end
14+
r = runtests(IncludeSubfolders=true, strict=true, UseParallel=true);
2115

16+
assert(~isempty(r), "No tests were run")
17+
assertSuccess(r)
18+
end
2219

2320
function coverageTask(~)
24-
import matlab.unittest.TestRunner
25-
import matlab.unittest.Verbosity
26-
import matlab.unittest.plugins.CodeCoveragePlugin
27-
% import matlab.unittest.plugins.XMLPlugin
28-
% import matlab.unittest.plugins.codecoverage.CoberturaFormat
29-
30-
31-
pkg = "stdlib";
32-
33-
suite = testsuite("test/");
34-
35-
% not import to allow use of rest of buildfile with R2022b
36-
format = matlab.unittest.plugins.codecoverage.CoverageResult;
37-
38-
39-
runner = TestRunner.withTextOutput();
40-
runner.addPlugin(...
41-
CodeCoveragePlugin.forPackage(pkg, ...
42-
IncludingSubpackages=true, Producing=format))
43-
44-
% runner.addPlugin(XMLPlugin.producingJUnitFormat('test-results.xml'))
45-
% runner.addPlugin(CodeCoveragePlugin.forPackage(pkg, 'Producing', ...
46-
% CoberturaFormat('test-coverage.xml')))
47-
48-
run_results = runner.run(suite);
49-
assert(~isempty(run_results), "no tests found")
21+
cwd = fileparts(mfilename('fullpath'));
5022

51-
assertSuccess(run_results)
52-
53-
generateHTMLReport(format.Result)
23+
coverage_run("stdlib", fullfile(cwd, "test"))
5424
end
5525

56-
5726
function publishTask(~)
58-
% publish (generate) docs from Matlab project
59-
% https://www.mathworks.com/help/matlab/ref/publish.html
60-
% https://www.mathworks.com/help/matlab/matlab_prog/marking-up-matlab-comments-for-publishing.html
61-
%
62-
% for package code -- assumes no classes and depth == 1
63-
pkg_name = "stdlib";
64-
65-
pkg = what(pkg_name);
66-
67-
%% generate docs
68-
cwd = fileparts(mfilename('fullpath'));
69-
docs = fullfile(cwd, "docs");
70-
readme = fullfile(docs, "index.html");
71-
72-
if ~isfolder(docs)
73-
mkdir(docs);
74-
end
75-
76-
txt = ["<!DOCTYPE html> <head> <title>Standard library for Matlab API</title> <body>", ...
77-
"<h1>stdlib for Matlab API</h1>", ...
78-
"A standard library of functions for Matlab.", ...
79-
"<h2>API Reference</h2>"];
80-
fid = fopen(readme, 'w');
81-
fprintf(fid, join(txt, "\n"));
82-
83-
for sub = pkg.m.'
84-
s = sub{1};
85-
[~, name] = fileparts(s);
86-
doc_fn = publish(pkg_name + "." + name, evalCode=false, outputDir=docs);
87-
disp(doc_fn)
88-
% inject summary into Readme.md
89-
summary = split(string(help(pkg_name + "." + name)), newline);
90-
words = split(strip(summary(1)), " ");
91-
% purposefully this will error if no docstring
92-
fname = words(1);
93-
if(lower(fname) ~= lower(name))
94-
error("fname %s does not match name %s", fname, name)
95-
end
96-
line = "<a href=" + name + ".html>" + fname + "</a> ";
97-
if(length(words) > 1)
98-
line = line + join(words(2:end));
99-
end
100-
fprintf(fid, line + "<br>\n");
101-
end
102-
103-
fprintf(fid, "</body> </html>");
104-
105-
fclose(fid);
27+
cwd = fileparts(mfilename('fullpath'));
28+
outdir = fullfile(cwd, "docs");
10629

30+
publish_gen_index_html("stdlib", ...
31+
"A standard library of functions for Matlab.", ...
32+
outdir)
10733
end

private/publish_gen_index_html.m

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ function publish_gen_index_html(pkg_name, tagline, outdir)
1313
% "+" avoids picking up cwd of same name
1414
assert(~isempty(pkg), pkg_name + " is not detected as a Matlab directory or package")
1515

16+
%% Git info
17+
repo = gitrepo(pkg.path);
18+
git_txt = "Git branch / commit: " + repo.CurrentBranch.Name + " " + extractBefore(repo.LastCommit.ID, 8);
19+
1620
%% generate docs
1721
readme = fullfile(outdir, "index.html");
1822

@@ -22,7 +26,8 @@ function publish_gen_index_html(pkg_name, tagline, outdir)
2226

2327
txt = ["<!DOCTYPE html> <head> <title>" + pkg_name + " API</title> <body>", ...
2428
"<h1>" + pkg_name + " API</h1>", ...
25-
tagline, ...
29+
"<p>" + tagline + "</p>", ...
30+
"<p>" + git_txt + "</p>", ...
2631
"<h2>API Reference</h2>"];
2732
fid = fopen(readme, 'w');
2833
fprintf(fid, join(txt, "\n"));

0 commit comments

Comments
 (0)