Skip to content

Commit a910511

Browse files
committed
latest buildfile and publish
1 parent 15c7813 commit a910511

5 files changed

Lines changed: 67 additions & 68 deletions

File tree

.github/workflows/composite-buildtool/action.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@ runs:
77
steps:
88

99
- name: Run Matlab buildtool
10-
if: ${{ matrix.release >= 'R2022b' || matrix.release == 'latest' || matrix.release == 'latest-including-prerelease' }}
10+
if: ${{ matrix.release >= 'R2022b' || startsWith(matrix.release, 'latest') }}
1111
uses: matlab-actions/run-build@v2
1212
with:
1313
startup-options: ${{ matrix.startup-options }}
14-
tasks: test
14+
tasks: check test
1515

1616

1717
- name: Run tests (manual)
18-
if: ${{ matrix.release < 'R2022b' && matrix.release != 'latest' && matrix.release != 'latest-including-prerelease' }}
18+
if: ${{ matrix.release < 'R2022b' && !startsWith(matrix.release, 'latest') }}
1919
uses: matlab-actions/run-tests@v2
2020
with:
2121
select-by-folder: test

.gitignore

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@ docs/
22
resources/
33
*.asv
44
*.m~
5-
code-coverage/
6-
test-results/
5+
code-coverage.xml
6+
.buildtool/

buildfile.m

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,42 @@
11
function plan = buildfile
2-
plan = buildplan(localfunctions);
2+
3+
plan = buildplan();
4+
35
plan.DefaultTasks = "test";
4-
plan("test").Dependencies = "check";
6+
7+
pkg_name = "+matmap3d";
8+
9+
if isMATLABReleaseOlderThan("R2023b")
10+
plan("test") = matlab.buildtool.Task(Actions=@legacyTestTask);
11+
else
12+
plan("check") = matlab.buildtool.tasks.CodeIssuesTask(pkg_name, IncludeSubfolders=true);
13+
plan("test") = matlab.buildtool.tasks.TestTask("test", Strict=false);
514
end
615

7-
function checkTask(~)
8-
% Identify code issues (recursively all Matlab .m files)
9-
issues = codeIssues;
10-
assert(isempty(issues.Issues), formattedDisplayText(issues.Issues))
16+
if ~isMATLABReleaseOlderThan("R2024a")
17+
plan("coverage") = matlab.buildtool.tasks.TestTask(Description="code coverage", SourceFiles="test", Strict=false, CodeCoverageResults="code-coverage.xml");
1118
end
1219

13-
function testTask(~)
14-
r = runtests(IncludeSubfolders=true, strict=true, UseParallel=true);
20+
plan("publish") = matlab.buildtool.Task(Description="HTML inline doc generate", Actions=@publishTask);
21+
1522

16-
assert(~isempty(r), "No tests were run")
17-
assertSuccess(r)
1823
end
1924

20-
function coverageTask(~)
21-
cwd = fileparts(mfilename('fullpath'));
2225

23-
coverage_run("matmap3d", fullfile(cwd, "test"))
26+
function legacyTestTask(context)
27+
r = runtests(fullfile(context.Plan.RootFolder, "test"), Strict=false);
28+
% Parallel Computing Toolbox takes more time to startup than is worth it for this task
29+
30+
assert(~isempty(r), "No tests were run")
31+
assertSuccess(r)
2432
end
2533

26-
function publishTask(~)
27-
cwd = fileparts(mfilename('fullpath'));
28-
outdir = fullfile(cwd, "docs");
34+
35+
function publishTask(context)
36+
outdir = fullfile(context.Plan.RootFolder, "docs");
2937

3038
publish_gen_index_html("matmap3d", ...
31-
"Geographic Map coordinate transform functions for Matlab", ...
39+
"Geographic coordinate tranformation functions for Matlab.", ...
40+
"https://github.com/geospace-code/matmap3d", ...
3241
outdir)
3342
end

private/coverage_run.m

Lines changed: 0 additions & 32 deletions
This file was deleted.

private/publish_gen_index_html.m

Lines changed: 36 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,16 @@
77
% * https://www.mathworks.com/help/matlab/matlab_prog/marking-up-matlab-comments-for-publishing.html
88
%
99
% for package code -- assumes no classes and depth == 1
10-
function publish_gen_index_html(pkg_name, tagline, outdir)
10+
%
11+
% if *.mex* files are present, publish fails
12+
13+
function publish_gen_index_html(pkg_name, tagline, project_url, outdir)
14+
arguments
15+
pkg_name (1,1) string
16+
tagline (1,1) string
17+
project_url (1,1) string
18+
outdir (1,1) string
19+
end
1120

1221
pkg = what("+" + pkg_name);
1322
% "+" avoids picking up cwd of same name
@@ -24,37 +33,50 @@ function publish_gen_index_html(pkg_name, tagline, outdir)
2433
mkdir(outdir);
2534
end
2635

27-
txt = ["<!DOCTYPE html> <head> <title>" + pkg_name + " API</title> <body>", ...
28-
"<h1>" + pkg_name + " API</h1>", ...
29-
"<p>" + tagline + "</p>", ...
30-
"<p>" + git_txt + "</p>", ...
31-
"<h2>API Reference</h2>"];
36+
txt = ["<!DOCTYPE html>", ...
37+
"<head>",...
38+
'<meta name="color-scheme" content="dark light">', ...
39+
'<meta name="viewport" content="width=device-width, initial-scale=1">', ...
40+
'<meta name="generator" content="Matlab ' + matlabRelease().Release + '">', ...
41+
"<title>" + pkg_name + " API</title>", ...
42+
"</head>", ...
43+
"<body>", ...
44+
"<h1>" + pkg_name + " API</h1>", ...
45+
"<p>" + tagline + "</p>", ...
46+
"<p>" + git_txt + "</p>", ...
47+
"<p>Project URL: <a href=" + project_url + ">" + project_url + "</a></p>", ...
48+
"<h2>API Reference</h2>"];
3249
fid = fopen(readme, 'w');
3350
fprintf(fid, join(txt, "\n"));
3451

3552
for sub = pkg.m.'
3653

3754
s = sub{1};
3855
[~, name] = fileparts(s);
56+
3957
doc_fn = publish(pkg_name + "." + name, evalCode=false, outputDir=outdir);
4058
disp(doc_fn)
4159

42-
% inject summary into Readme.md
43-
summary = split(string(help(pkg_name + "." + name)), newline);
44-
words = split(strip(summary(1)), " ");
60+
% inject summary for each function into Readme.md
61+
help_txt = split(string(help(pkg_name + "." + name)), newline);
62+
words = split(strip(help_txt(1)), " ");
4563

46-
% purposefully this will error if no docstring
64+
% error if no docstring
4765
fname = words(1);
48-
if(lower(fname) ~= lower(name))
49-
error("fname %s does not match name %s", fname, name)
50-
end
66+
assert(lower(fname) == lower(name), "fname %s does not match name %s \nis there a docstring at the top of the .m file?", fname, name)
5167

5268
line = "<a href=" + name + ".html>" + fname + "</a> ";
5369
if(length(words) > 1)
5470
line = line + join(words(2:end));
5571
end
5672

57-
fprintf(fid, line + "<br>\n");
73+
req = "";
74+
75+
if contains(help_txt(2), "requires:") || contains(help_txt(2), "optional:")
76+
req = "<strong>(" + strip(help_txt(2), " ") + ")</strong>";
77+
end
78+
79+
fprintf(fid, line + " " + req + "<br>\n");
5880

5981
end
6082

0 commit comments

Comments
 (0)