Skip to content

Commit

Permalink
Update tasks to use MatBox
Browse files Browse the repository at this point in the history
  • Loading branch information
ehennestad committed Oct 25, 2024
1 parent 716c1d5 commit 1435d17
Show file tree
Hide file tree
Showing 13 changed files with 132 additions and 227 deletions.
29 changes: 27 additions & 2 deletions .github/workflows/update.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: Update openMINDS_MATLAB
on:
# Triggers the workflow on push or pull request events for the "main" branch
push:
branches: [ "main" ]
branches: [ "main", "change/use-matbox"]
paths-ignore:
- 'README.md'
- 'dev/README.md'
Expand Down Expand Up @@ -52,7 +52,7 @@ jobs:
run: |
git config user.name "${{ github.workflow }} by ${{ github.actor }}"
git config user.email "<>"
git add docs/reports/badge/code_issues.json docs/reports/badge/tests.json
git add .github/badges/code_issues.json .github/badges/tests.json
git commit -m "Update code issues and tests badges"
git fetch
# git push returns error code 1 if there's nothing to push (which there often isn't in this case)
Expand All @@ -79,3 +79,28 @@ jobs:
with:
name: reports
path: docs/reports

- name: Checkout gh-badges branch
uses: actions/checkout@v3
with:
ref: gh-badges
path: gh-badges
token: ${{ secrets.GITHUB_TOKEN }}

- name: Push to gh-badges
run: |
cp .github/badges/code_issues.json gh-badges/.github/badges/code_issues.json
cp .github/badges/tests.json gh-badges/.github/badges/tests.json
cd gh-badges
git config user.name "${{ github.workflow }} by ${{ github.actor }}"
git config user.email "<>"
# Only proceed with commit and push if changes are detected
if [[ $(git add .github/badges/* --dry-run | wc -l) -gt 0 ]]; then
git add .github/badges/*
git commit -m "Update code issues and tests badges"
git push -f
else
echo "Nothing to commit"
fi
3 changes: 0 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@ releases/
# Ignore everything in docs/reports
docs/reports/*

# Don't ignore the badge file/directory
!docs/reports/badge

# Autosave files
*.asv
*.m~
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
function rootFolder = getProjectRootDir()
function rootFolder = projectdir()
scriptFolder = fileparts(mfilename('fullpath'));
% Assumes project root directory is 3 levels up from script location
rootFolder = fileparts(fileparts(fileparts(scriptFolder)));
rootFolder = fileparts(fileparts(scriptFolder));
L = dir(rootFolder);
assert(all(contains( {'code', 'dev'}, {L.name})), ...
'Expected project root directory to contain "code" and "dev" folder.');
'Expected project root directory to contain "code" and "tools" folder.');
end
15 changes: 0 additions & 15 deletions dev/+toolbox/readToolboxInfo.m

This file was deleted.

21 changes: 12 additions & 9 deletions dev/MLToolboxInfo.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
{
"Identifier": "b8bc10bb-6afb-4c6a-b357-a57037d1dcb3",
"ToolboxName": "openMINDS Metadata Models",
"AuthorName": "Eivind Hennestad",
"AuthorEmail": "[email protected]",
"AuthorCompany": "openMetadataInitiative",
"Summary": "A MATLAB toolbox to create metadata instances using the openMINDS metadata models",
"Description": "MATLAB package for the openMINDS metadata models. The package contains all the latest openMINDS schemas as MATLAB classes in addition to schema base classes and utility methods",
"MinimumMatlabRelease": "R2022b",
"MaximumMatlabRelease": ""
"Namespace" : "openminds",
"ToolboxOptions": {
"Identifier": "b8bc10bb-6afb-4c6a-b357-a57037d1dcb3",
"ToolboxName": "openMINDS Metadata Models",
"AuthorName": "Eivind Hennestad",
"AuthorEmail": "[email protected]",
"AuthorCompany": "openMetadataInitiative",
"Summary": "A MATLAB toolbox to create metadata instances using the openMINDS metadata models",
"Description": "MATLAB package for the openMINDS metadata models. The package contains all the latest openMINDS schemas as MATLAB classes in addition to schema base classes and utility methods",
"MinimumMatlabRelease": "R2022b",
"MaximumMatlabRelease": ""
}
}
54 changes: 0 additions & 54 deletions dev/codecheckToolbox.m

This file was deleted.

9 changes: 9 additions & 0 deletions dev/tasks/codecheckToolbox.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
function codecheckToolbox()
% codecheckToolbox - Identify code issues for openMINDS_MATLAB toolbox

installMatBox("commit")
projectRootDirectory = ommtools.projectdir();

matbox.tasks.codecheckToolbox(projectRootDirectory, ...
"CreateBadge", true)
end
60 changes: 4 additions & 56 deletions dev/tasks/createTestedWithBadgeforToolbox.m
Original file line number Diff line number Diff line change
@@ -1,60 +1,8 @@
function createTestedWithBadgeforToolbox(versionNumber, rootDir)
%createTestedWithBadgesforToolbox - Take the test reports from the runs against
% multiple MATLAB releases, and generate the "Tested with" badge
%
% Adapted from: https://github.com/mathworks/climatedatastore/tree/main/buildUtilities

function createTestedWithBadgeforToolbox(versionNumber)
arguments
versionNumber (1,1) string
rootDir (1,1) string {mustBeFolder} = ommtools.getProjectRootDir()
end

releasesTestedWith = "";
releasesFailed = 0;
% Go through the R2* directories and extract the failed test info
releaseDirectoryInfo = dir(fullfile(rootDir, "docs", "reports"));
% Select only folders
releaseDirectoryInfo = releaseDirectoryInfo([releaseDirectoryInfo.isdir]);
% with a name like R2*
releaseDirectoryInfo = releaseDirectoryInfo(startsWith(string({releaseDirectoryInfo.name}), "R2", "IgnoreCase", true));

% Sort releases newest to oldest
[~, ix] = sort(string({releaseDirectoryInfo.name}), "descend");
releaseDirectoryInfo = releaseDirectoryInfo(ix);

% go through the directories and check if tests passed
for iReleaseDirectoryInfo = 1:numel(releaseDirectoryInfo)
releaseName = string(releaseDirectoryInfo(iReleaseDirectoryInfo).name);
testresultsFilename = fullfile(releaseDirectoryInfo(iReleaseDirectoryInfo).folder, releaseName, "test-results.xml");
% Read the test results file
testResults = readstruct(testresultsFilename);
% If no tests failed, errors, or were skipped, then add it to the list
if sum([testResults.testsuite.errorsAttribute]) == 0 ...
&& sum([testResults.testsuite.failuresAttribute]) == 0 ...
&& sum([testResults.testsuite.skippedAttribute]) == 0
if releasesTestedWith ~= ""
% Insert the separator between released after the first one
releasesTestedWith = releasesTestedWith + " | ";
end
releasesTestedWith = releasesTestedWith + releaseName;
else
releasesFailed = releasesFailed + 1;
end
end
if releasesTestedWith ~= ""
switch releasesFailed
case 0
badgecolor = "green";
case 1
badgecolor = "orange";
case 2
badgecolor = "yellow";
otherwise
badgecolor = "red";
end

outputDirectory = fullfile(rootDir, '.github', 'badges', versionNumber);
utility.writeBadgeJSONFile("tested with", releasesTestedWith, badgecolor,...
"OutputFolder", outputDirectory)
end
installMatBox()
projectRootDirectory = ommtools.projectdir();
matbox.tasks.createTestedWithBadgeforToolbox(versionNumber, projectRootDirectory)
end
62 changes: 62 additions & 0 deletions dev/tasks/installMatBox.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
function installMatBox(mode)
% installMatBox - Install MatBox from latest release or latest commit

% Todo:
% - If MatBox release has been updated on remote, should reinstall.

arguments
mode (1,1) string {mustBeMember(mode, ["release", "commit"])} = "release"
end

if mode == "release"
installFromRelease() % local function
elseif mode == "commit"
installFromCommit() % local function
end
end

function installFromRelease()
addonsTable = matlab.addons.installedAddons();
isMatchedAddon = addonsTable.Name == "MatBox";

if ~isempty(isMatchedAddon) && any(isMatchedAddon)
matlab.addons.enableAddon('MatBox')
else
info = webread('https://api.github.com/repos/ehennestad/MatBox/releases/latest');
assetNames = {info.assets.name};
isMltbx = startsWith(assetNames, 'MatBox');

mltbx_URL = info.assets(isMltbx).browser_download_url;

% Download matbox
tempFilePath = websave(tempname, mltbx_URL);
cleanupObj = onCleanup(@(fp) delete(tempFilePath));

% Install toolbox
matlab.addons.install(tempFilePath);
end
end

function installFromCommit()
% Download latest zipped version of repo
url = "https://github.com/ehennestad/MatBox/archive/refs/heads/main.zip";
tempFilePath = websave(tempname, url);
cleanupObj = onCleanup(@(fp) delete(tempFilePath));

% Unzip in temporary location
unzippedFiles = unzip(tempFilePath, tempdir);
unzippedFolder = unzippedFiles{1};
if endsWith(unzippedFolder, filesep)
unzippedFolder = unzippedFolder(1:end-1);
end

% Move to installation location
[~, repoFolderName] = fileparts(unzippedFolder);
targetFolder = fullfile(userpath, "Add-Ons");
targetFolder = fullfile(targetFolder, repoFolderName);
if isfolder(targetFolder); rmdir(targetFolder, "s"); end
movefile(unzippedFolder, targetFolder);

% Add to MATLAB's search path
addpath(genpath(targetFolder))
end
15 changes: 15 additions & 0 deletions dev/tasks/testToolbox.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
function testToolbox(varargin)
% testToolbox - Run tests for openMINDS_MATLAB toolbox

% Prepare
installMatBox("commit")
projectRootDirectory = ommtools.projectdir();
% matbox.installRequirements(projectRootDirectory) % No requirements...

matbox.tasks.testToolbox(...
projectRootDirectory, ...
"CreateBadge", true, ...
"ToolsFolderName", 'dev', ...
varargin{:} ...
)
end
Loading

0 comments on commit 1435d17

Please sign in to comment.