Repository navigation
Expand file tree
/
Copy pathbuildfile.m
More file actions
120 lines (96 loc) · 3.19 KB
/
Copy pathbuildfile.m
File metadata and controls
120 lines (96 loc) · 3.19 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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
function plan = buildfile()
%buildfile DocMaker buildfile
% Copyright 2023-2026 The MathWorks, Inc.
% Create a plan from task functions
plan = buildplan( localfunctions() );
% Folders of interest
prj = plan.RootFolder;
tbx = fullfile( prj, "tbx" );
api = fullfile( tbx, tbxname() );
doc = fullfile( tbx, tbxname() + "doc" );
test = fullfile( prj, "tests" );
% Clean task
plan("clean") = matlab.buildtool.tasks.CleanTask;
% Check task
plan("check").Inputs = api;
% Test task
plan("test") = matlab.buildtool.tasks.TestTask( test, ...
"SourceFiles", tbx, "Strict", true );
plan("test").Inputs = [api test];
plan("test").Dependencies = "check";
% Documentation task
plan("doc") = DocMakerTask( fullfile( doc, "**", "*.md" ), ...
"Theme", "light", ...
"FigureSize", [600, 400], ...
"FigureTheme", "light" );
% Package task
plan("package").Inputs = tbx;
plan("package").Dependencies = ["test", "doc"];
% Default task
plan.DefaultTasks = "package";
end % buildfile
function n = tbxname()
%tbxname Toolbox name
n = "docmaker";
end % tbxname
function checkTask( c )
% Identify code and project issues
% Check code
t = matlab.buildtool.tasks.CodeIssuesTask( c.Plan.RootFolder, ...
"Configuration", "factory", ...
"IncludeSubfolders", true, ...
"WarningThreshold", 0 );
t.analyze( c )
fprintf( 1, "** Code checks passed\n" )
% Check project
p = currentProject();
p.updateDependencies()
t = table( p.runChecks() );
ok = t.Passed;
if any( ~ok )
disp( t(~ok,:) )
error( "build:check", "Project check(s) failed." )
else
fprintf( 1, "** Project checks passed\n" )
end
end % checkTask
function packageTask( ~ )
% Package toolbox
% Load and tweak metadata
s = jsondecode( fileread( tbxname() + ".json" ) );
v = ver( tbxname() ); % from Contents.m
assert( isscalar( v ), "build:package", ...
"Found %d instances of %s on the MATLAB path.", numel( v ), tbxname() )
s.ToolboxName = v.Name;
s.ToolboxVersion = v.Version;
if getenv( "GITHUB_ACTIONS" ) == "true"
% Check version and tag compatibility for release
ref = string( getenv( "GITHUB_REF" ) );
gitTagNumber = extractAfter( ref, "refs/tags/v" );
assert( v.Version == gitTagNumber, ...
"build:package:VersionTagMismatch", ...
"%s Toolbox version %s (from Contents.m) does not " + ...
"match the current Git tag number (%s).", ...
v.Name, v.Version, gitTagNumber )
% Define stable name for GitHub
stableName = replace( v.Name, " ", "_" ) + ".mltbx";
s.OutputFile = fullfile( "releases", stableName );
else
% Include version in toolbox file name
s.OutputFile = fullfile( ...
"releases", v.Name + " " + v.Version + ".mltbx" );
end % if
% Create options object
f = s.ToolboxFolder; % mandatory
id = s.Identifier; % mandatory
s = rmfield( s, ["Identifier", "ToolboxFolder"] ); % mandatory
pv = [fieldnames( s ), struct2cell( s )]'; % optional
o = matlab.addons.toolbox.ToolboxOptions( f, id, pv{:} );
o.ToolboxVersion = string( o.ToolboxVersion ); % g3079185
% Package
matlab.addons.toolbox.packageToolbox( o )
fprintf( 1, "[+] %s\n", o.OutputFile );
% Add license
lic = fileread( "LICENSE" );
mlAddonSetLicense( char( o.OutputFile ), struct( "type", 'BSD', "text", lic ) );
end % packageTask