Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/badges/tests.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,14 @@ By default, a `LICENSE` file in the project root is included in the packaged too
"RootFilesToPackage": ["LICENSE", "THIRD_PARTY_NOTICES.md"]
```

The packaged toolbox is saved as `releases/<ToolboxName>_v<version>.mltbx`, for example `MatBox_v1_2_3.mltbx`. To use the same file name for every release, add a top-level `MltbxFileName` to `MLToolboxInfo.json`. `.mltbx` is appended if it is missing, and the name must not contain folders:

```json
"MltbxFileName": "MatBox"
```

A fixed file name gives the latest release a stable download link, `https://github.com/<owner>/<repo>/releases/latest/download/<MltbxFileName>.mltbx`.

## Project-Specific Task Wrappers

Projects can keep their own CI entry points in `tools/tasks`. These wrapper functions are useful when a project needs non-default source folders, test folders, tag filters, report settings, or packaging options.
Expand Down
4 changes: 4 additions & 0 deletions code/+matbox/+tasks/packageToolbox.m
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@
% specify a top-level "RootFilesToPackage" list in MLToolboxInfo.json,
% e.g. "RootFilesToPackage": ["LICENSE", "THIRD_PARTY_NOTICES.md"].
%
% The MLTBX file is named <ToolboxName>_v<version>.mltbx. To use a fixed
% file name for every release, specify a top-level "MltbxFileName" in
% MLToolboxInfo.json, e.g. "MltbxFileName": "MatBox".
%
% Adapted from: https://github.com/mathworks/climatedatastore/blob/main/buildUtilities/packageToolbox.m
% See the THIRD_PARTY_NOTICES.md file distributed with MatBox for license terms.

Expand Down
35 changes: 30 additions & 5 deletions code/+matbox/+toolbox/createToolboxOptions.m
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
end

% Read the toolbox info from MLToolboxInfo.json
[toolboxInfo, identifier] = matbox.toolbox.readToolboxInfo(projectRootDirectory);
[toolboxInfo, identifier, toolboxInfoFileContent] = ...
matbox.toolbox.readToolboxInfo(projectRootDirectory);

% Resolve folders to add to path for toolbox. This needs to be done
% before creating the ToolboxOptions object due to a bug in that class
Expand Down Expand Up @@ -67,15 +68,39 @@
end
end

% Specify name for output .mltbx file. Every version separator, including
% the "+" before a build number, becomes an underscore.
versionNumber = replace(opts.ToolboxVersion, [".", "+"], "_");
outputFileName = sprintf('%s_v%s.mltbx', MLTBX_NAME, versionNumber);
outputFileName = resolveOutputFileName(toolboxInfoFileContent, ...
MLTBX_NAME, opts.ToolboxVersion);
opts.OutputFile = fullfile(projectRootDirectory, "releases", outputFileName);

toolboxOptions = opts;
end

function outputFileName = resolveOutputFileName(toolboxInfoFileContent, mltbxName, toolboxVersion)
% resolveOutputFileName - Get the file name of the packaged .mltbx file
%
% A non-empty top-level "MltbxFileName" field in MLToolboxInfo.json is used
% as the file name, with ".mltbx" appended if it is missing. Otherwise the
% name is <mltbxName>_v<version>.mltbx, where every version separator,
% including the "+" before a build number, becomes an underscore.

if isfield(toolboxInfoFileContent, 'MltbxFileName') ...
&& ~isempty(toolboxInfoFileContent.MltbxFileName)
outputFileName = string(toolboxInfoFileContent.MltbxFileName);
if ~isscalar(outputFileName) || contains(outputFileName, ["/", "\"])
error('MatBox:Package:InvalidMltbxFileName', ...
['The "MltbxFileName" field in MLToolboxInfo.json must be a ', ...
'single file name without folders. The packaged toolbox is ', ...
'always saved in the "releases" folder.'])
end
if ~endsWith(outputFileName, ".mltbx", "IgnoreCase", true)
outputFileName = outputFileName + ".mltbx";
end
else
versionNumber = replace(toolboxVersion, [".", "+"], "_");
outputFileName = sprintf("%s_v%s.mltbx", mltbxName, versionNumber);
end
end

function toolboxVersion = formatToolboxVersion(versionNumber)
% formatToolboxVersion - Write a version number in the form ToolboxOptions accepts
%
Expand Down
4 changes: 3 additions & 1 deletion docs/ci.md
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,9 @@ The reusable workflow chains these jobs:
`matbox.tasks.packageToolbox` and creates a draft GitHub release.
Project root files declared in the top-level `RootFilesToPackage`
list in `MLToolboxInfo.json` (by default `LICENSE`) are included in
the packaged toolbox
the packaged toolbox. The `.mltbx` file is named
`<ToolboxName>_v<version>.mltbx`, or by the top-level `MltbxFileName`
in `MLToolboxInfo.json` when that field is set
5. **Verify installation** — installs the packaged toolbox and confirms it
loads

Expand Down
39 changes: 39 additions & 0 deletions tools/tests/+matboxtools/+unittest/TasksTest.m
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,38 @@ function testPackageToolboxShadowedRootFile(testCase)
testCase.verifyTrue(isfile(fullfile(pwd, 'code', 'LICENSE')))
end

function testMltbxFileNameDefaultsToVersionedName(testCase)
copyfile(matboxtools.projectdir(), pwd);

toolboxOptions = matbox.toolbox.createToolboxOptions(pwd, "1.2.3", ...
"SourceFolderName", "code");
[~, fileName, fileExtension] = fileparts(toolboxOptions.OutputFile);
testCase.verifyEqual(string(fileName) + fileExtension, "MatBox_v1_2_3.mltbx")
end

function testMltbxFileNameFromToolboxInfo(testCase)
copyfile(matboxtools.projectdir(), pwd);

fileNames = ["MatBox", "MatBox.mltbx"];
for iFileName = fileNames
setMltbxFileName(pwd, iFileName)
toolboxOptions = matbox.toolbox.createToolboxOptions(pwd, "1.2.3", ...
"SourceFolderName", "code", "ToolboxShortName", "ShortName");
testCase.verifyEqual(string(toolboxOptions.OutputFile), ...
fullfile(pwd, "releases", "MatBox.mltbx"), ...
sprintf('Unexpected output file for MltbxFileName "%s".', iFileName))
end
end

function testMltbxFileNameWithFolderErrors(testCase)
copyfile(matboxtools.projectdir(), pwd);

setMltbxFileName(pwd, "subfolder/MatBox")
testCase.verifyError(...
@() matbox.toolbox.createToolboxOptions(pwd, "1.2.3", "SourceFolderName", "code"), ...
"MatBox:Package:InvalidMltbxFileName")
end

function testTestedWithBadgeCountsReleaseWithSkippedTests(testCase)
% Tests filtered by an unmet assumption are reported as skipped
% rather than failed, so the release is still tested with.
Expand Down Expand Up @@ -179,6 +211,13 @@ function testTestedWithBadgeErrorsWhenNoReleasePassed(testCase)
end
end

function setMltbxFileName(projectRootDirectory, mltbxFileName)
toolboxInfoFile = fullfile(projectRootDirectory, 'tools', 'MLToolboxInfo.json');
toolboxInfo = jsondecode(fileread(toolboxInfoFile));
toolboxInfo.MltbxFileName = mltbxFileName;
matbox.utility.filewrite(toolboxInfoFile, jsonencode(toolboxInfo, "PrettyPrint", true));
end

function writeTestResultsReport(projectRootDirectory, releaseName, options)
% writeTestResultsReport - Write a minimal JUnit-style report for one release
%
Expand Down
Loading