Skip to content

Commit 61e74ea

Browse files
committed
Added FEX badge, removed old startup files.
1 parent 92699fb commit 61e74ea

64 files changed

Lines changed: 292 additions & 198 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/ci.yml

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,61 @@
1-
name: MATLAB Build
1+
name: Module Test
22

33
# Controls when the action will run.
44
on:
55
push:
66
branches: [ release ]
77
pull_request:
88
branches: [ release ]
9-
workflow_dispatch:
109

1110
jobs:
12-
test:
11+
RunTests:
1312
strategy:
1413
fail-fast: false
1514
matrix:
16-
MATLABVersion: [R2023a,R2023b]
15+
MATLABVersion: [R2022a,R2022b,R2023a,R2023b,R2024a]
1716
runs-on: ubuntu-latest
1817
steps:
19-
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
18+
# Checks-out your repository
2019
- uses: actions/checkout@v3
2120

22-
# Sets up MATLAB on the GitHub Actions runner
21+
# Sets up MATLAB
2322
- name: Setup MATLAB
2423
uses: matlab-actions/setup-matlab@v1
2524
with:
2625
release: ${{ matrix.MATLABVersion }}
2726

28-
# Run SmokeTests
27+
# Run all the tests
2928
- name: Run SmokeTests
3029
uses: matlab-actions/run-command@v1
3130
with:
32-
command: openProject(pwd); results = runtests(fullfile("SoftwareTests","SmokeTests.m")); assertSuccess(results);
33-
34-
# Run FunctionTests
35-
- name: Run FunctionTests
36-
uses: matlab-actions/run-command@v1
37-
with:
38-
command: openProject(pwd); results = runtests(fullfile("SoftwareTests","FunctionTests.m")); assertSuccess(results);
31+
command: openProject(pwd); RunAllTests;
3932

4033
# Upload the test results as artifact
4134
- name: Upload TestResults
35+
if: always()
4236
uses: actions/upload-artifact@v3.1.3
4337
with:
4438
name: TestResults
4539
path: ./SoftwareTests/TestResults_${{ matrix.MATLABVersion }}.txt
4640

41+
42+
CreateBadge:
43+
if: ${{ always() }}
44+
needs: [RunTests]
45+
strategy:
46+
fail-fast: false
47+
runs-on: ubuntu-latest
48+
steps:
49+
50+
# Checks-out your repository
51+
- uses: actions/checkout@v3
52+
53+
# Sets up R2023b
54+
- name: Setup MATLAB
55+
uses: matlab-actions/setup-matlab@v1
56+
with:
57+
release: R2023b
58+
4759
# Download the test results from artifact
4860
- name: Download TestResults
4961
uses: actions/download-artifact@v2.1.1
@@ -55,14 +67,16 @@ jobs:
5567
- name: Run CreateBadge
5668
uses: matlab-actions/run-command@v1
5769
with:
58-
command: openProject(pwd); results = runtests(fullfile("SoftwareTests","CreateBadge.m"));
70+
command: openProject(pwd); CreateBadge;
5971

6072
# Commit the JSON for the MATLAB releases badge
6173
- name: Commit changed files
6274
continue-on-error: true
6375
run: |
6476
git config user.name "${{ github.workflow }} by ${{ github.actor }}"
6577
git config user.email "<>"
78+
git pull
79+
git add Images/TestedWith.json
6680
git commit Images/TestedWith.json -m "Update CI badges ${{ github.ref_name }}"
6781
git fetch
6882
git push

.gitlab-ci.yml

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

Images/TestedWith.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"schemaVersion":1,"label":"tested with","message":"R2023b","color":"success"}
1+
{"schemaVersion":1,"label":"Tested with","color":"success","message":"R2022a | R2022b | R2023a | R2023b | R2024a"}

SoftwareTests/CheckTestResults.m

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
classdef CheckTestResults < matlab.unittest.TestCase
2+
3+
properties (SetAccess = protected)
4+
end
5+
6+
properties (ClassSetupParameter)
7+
Project = {''};
8+
end
9+
10+
properties (TestParameter)
11+
Version
12+
end
13+
14+
15+
methods (TestParameterDefinition,Static)
16+
17+
function Version = GetResults(Project)
18+
RootFolder = currentProject().RootFolder;
19+
Version = dir(fullfile(RootFolder,"SoftwareTests","TestResults*.txt"));
20+
Version = extractBetween([Version.name],"TestResults_",".txt");
21+
end
22+
23+
end
24+
25+
methods (TestClassSetup)
26+
27+
function SetUpSmokeTest(testCase,Project)
28+
try
29+
currentProject;
30+
catch
31+
error("Project is not loaded.")
32+
end
33+
end
34+
35+
end
36+
37+
methods(Test)
38+
39+
function CheckResults(testCase,Version)
40+
File = fullfile("SoftwareTests","TestResults_"+Version+".txt");
41+
Results = readtable(File,TextType="string");
42+
testCase.verifyTrue(all(Results.Passed));
43+
end
44+
45+
end
46+
47+
end

SoftwareTests/CreateBadge.m

Lines changed: 28 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -1,82 +1,28 @@
1-
% Run these tests with runMyTests
2-
% All tests so far are on code expected to run without errors
3-
% If/when we end up with a version that _should_ error,
4-
% please add it to this set of examples
5-
classdef CreateBadge < matlab.unittest.TestCase
6-
7-
properties
8-
rootProject
9-
results
10-
end
11-
12-
13-
methods (TestClassSetup)
14-
15-
function setUpPath(testCase)
16-
17-
try
18-
project = currentProject;
19-
testCase.rootProject = project.RootFolder;
20-
cd(testCase.rootProject)
21-
catch
22-
error("Load project prior to run tests")
23-
end
24-
25-
testCase.log("Running in " + version)
26-
27-
end % function setUpPath
28-
29-
function readResults(testCase)
30-
Release = string([]);
31-
Passed = [];
32-
testCase.results = table(Release,Passed);
33-
34-
ResultFiles = dir("SoftwareTests"+filesep+"TestResults_*");
35-
for kFiles = 1:size(ResultFiles)
36-
Results = readtable(fullfile(ResultFiles(kFiles).folder,ResultFiles(kFiles).name),...
37-
Delimiter=",",TextType="string");
38-
Release = Results.Version(1);
39-
Passed = all(Results.Status == "passed");
40-
testCase.results(end+1,:) = table(Release,Passed);
41-
end
42-
end
43-
44-
end % methods (TestClassSetup)
45-
46-
methods(Test)
47-
48-
function writeBadge(testCase)
49-
50-
% Create JSON
51-
badgeInfo = struct;
52-
badgeInfo.schemaVersion = 1;
53-
badgeInfo.label = "tested with";
54-
badgeInfo.message = "";
55-
56-
% Check that results exist:
57-
if size(testCase.results,1) == 0
58-
badgeInfo.message = "None";
59-
badgeInfo.color = "failed";
60-
else
61-
for i = 1:size(testCase.results,1)
62-
if testCase.results.Passed(i)
63-
if badgeInfo.message ~= ""
64-
badgeInfo.message = badgeInfo.message + " | ";
65-
end
66-
badgeInfo.message = badgeInfo.message + string(testCase.results.Release(i));
67-
end
68-
end
69-
badgeInfo.color = "success";
70-
end
71-
72-
% Write JSON file out
73-
badgeJSON = jsonencode(badgeInfo);
74-
fid = fopen(fullfile("Images","TestedWith.json"),"w");
75-
fwrite(fid,badgeJSON);
76-
fclose(fid);
77-
78-
end
79-
80-
end
81-
82-
end
1+
% Create the test suite with SmokeTest and Function test if they exist
2+
Suite = testsuite("CheckTestResults");
3+
4+
% Create a runner with no plugins
5+
Runner = matlab.unittest.TestRunner.withNoPlugins;
6+
7+
% Run the test suite
8+
Results = Runner.run(Suite);
9+
10+
% Format the results in a table and save them
11+
Results = table(Results');
12+
Results = Results(Results.Passed,:);
13+
Version = extractBetween(string(Results.Name),"Version=",")");
14+
15+
16+
% Format the JSON file
17+
Badge = struct;
18+
Badge.schemaVersion = 1;
19+
Badge.label = "Tested with";
20+
if size(Results,1) >= 1
21+
Badge.color = "success"
22+
Badge.message = join(Version," | ");
23+
else
24+
Badge.color = "failure";
25+
Badge.message = "Pipeline fails";
26+
end
27+
Badge = jsonencode(Badge);
28+
writelines(Badge,fullfile("Images","TestedWith.json"));

SoftwareTests/RunAllTests.m

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
function RunAllTest(EnableReport,ReportFolder)
2+
arguments
3+
EnableReport (1,1) logical = false;
4+
ReportFolder (1,1) string = "public";
5+
end
6+
7+
import matlab.unittest.plugins.TestReportPlugin;
8+
9+
% Create a runner
10+
Runner = matlab.unittest.TestRunner.withTextOutput;
11+
if EnableReport
12+
Folder = fullfile(currentProject().RootFolder,ReportFolder);
13+
if ~isfolder(Folder)
14+
mkdir(Folder)
15+
else
16+
rmdir(Folder,'s')
17+
mkdir(Folder)
18+
end
19+
Plugin = TestReportPlugin.producingHTML(Folder,...
20+
"IncludingPassingDiagnostics",true,...
21+
"IncludingCommandWindowText",true,...
22+
"LoggingLevel",matlab.automation.Verbosity(1));
23+
Runner.addPlugin(Plugin);
24+
end
25+
26+
% Create the test suite with SmokeTest and Function test if they exist
27+
Suite = testsuite("SmokeTests");
28+
Suite = [Suite testsuite("FunctionTests")];
29+
30+
% Run the test suite
31+
Results = Runner.run(Suite);
32+
33+
if EnableReport
34+
web(fullfile(Folder,"index.html"))
35+
else
36+
T = table(Results);
37+
disp(newline + "Test summary:")
38+
disp(T)
39+
end
40+
41+
% Format the results in a table and save them
42+
ResultsTable = table(Results')
43+
writetable(ResultsTable,fullfile("SoftwareTests","TestResults_"+release_version+".txt"));
44+
45+
% Assert success of test
46+
assertSuccess(Results);
47+
48+
end

0 commit comments

Comments
 (0)