Skip to content

Commit cbee4de

Browse files
committed
Update CI
1 parent 0093cf7 commit cbee4de

File tree

6 files changed

+210
-13
lines changed

6 files changed

+210
-13
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,7 @@ jobs:
3838
uses: matlab-actions/setup-matlab@v2
3939
with:
4040
release: ${{ matrix.MATLABVersion }}
41-
products: # Simulink Statistics_and_Machine_Learning_Toolbox
42-
# List required products above in the format shown (and uncomment them)
43-
# List of product strings:
44-
# Simulink
45-
# Statistics_and_Machine_Learning_Toolbox
46-
# Simulink_Coder
47-
# Econometrics_Toolbox
48-
# Deep_Learning_Toolbox
49-
41+
products: Statistics_and_Machine_Learning_Toolbox Image_Processing_Toolbox Curve_Fitting_Toolbox
5042

5143
# Run all the tests
5244
- name: Run SmokeTests

MainMenu.mlx

-89 Bytes
Binary file not shown.

README.md

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ The instructions inside the live scripts will guide you through the exercises an
2424

2525
## Contact Us
2626

27-
Solutions are available upon instructor request. Contact the [MathWorks teaching resources team](mailto:onlineteaching@mathworks.com) if you would like to request solutions, provide feedback, or if you have a question.
27+
Contact the [MathWorks teaching resources team](mailto:onlineteaching@mathworks.com) if you would like to provide feedback, or if you have a question.
2828

2929

3030
## Prerequisites
@@ -51,9 +51,6 @@ Ensure you have all the required products (listed below) installed. If you need
5151
MATLAB® is used throughout. Tools from Image Processing Toolbox™, Statistics and Machine Learning Toolbox™, and Curve Fitting Toolbox™ are used as well.
5252

5353
# Scripts
54-
55-
*If you are viewing this in a version of MATLAB prior to R2023b, you can view the learning outcomes for each script* [*here*](https://www.mathworks.com/matlabcentral/fileexchange/110125-climate-data-visualization-and-analysis)
56-
5754
## [**GlobalTemperature.mlx**](https://matlab.mathworks.com/open/github/v1?repo=MathWorks-Teaching-Resources/Climate-Data-Visualization-and-Analysis&project=ClimateVis.prj&file=Scripts/GlobalTemperature.mlx)
5855
| | |
5956
| :-- | :-- |

README.mlx

-142 Bytes
Binary file not shown.

SoftwareTests/PostSmokeTest.m

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
function PostSmokeTest(ShowReport)
2+
arguments
3+
ShowReport (1,1) logical = false;
4+
end
5+
6+
import matlab.unittest.plugins.TestRunnerPlugin;
7+
8+
% Create the runner:
9+
Runner = matlab.unittest.TestRunner.withTextOutput;
10+
11+
% Create report folder:
12+
Folder = fullfile(currentProject().RootFolder,"public");
13+
if ~isfolder(Folder)
14+
mkdir(Folder)
15+
end
16+
17+
% Add HTML plugin:
18+
Plugin = matlab.unittest.plugins.TestReportPlugin.producingHTML(Folder,...
19+
"IncludingPassingDiagnostics",true,...
20+
"IncludingCommandWindowText",false,...
21+
"LoggingLevel",matlab.automation.Verbosity(1));
22+
Runner.addPlugin(Plugin);
23+
24+
25+
% Create Test Suite
26+
Suite = testsuite("CheckTestResults");
27+
28+
% Run the test suite
29+
Results = Runner.run(Suite);
30+
31+
32+
% Format the results in a table and save them
33+
Results = table(Results');
34+
Results = Results(Results.Passed,:);
35+
Version = extractBetween(string(Results.Name),"Version=",")");
36+
37+
% Add link to other report
38+
File = fileread(fullfile("public","index.html"));
39+
for iVer = 1:length(Version)
40+
File = replace(File,"Version="+Version(iVer),...
41+
sprintf('<a href="%s/index.html">%s</a>',Version(iVer),"Version="+Version(iVer)));
42+
end
43+
writelines(File,fullfile("public","index.html"),"WriteMode","overwrite");
44+
45+
% Format the JSON file
46+
Badge = struct;
47+
Badge.schemaVersion = 1;
48+
Badge.label = "Tested with";
49+
if size(Results,1) >= 1
50+
Badge.color = "success"
51+
Badge.message = join("R"+Version," | ");
52+
else
53+
Badge.color = "failure";
54+
Badge.message = "Pipeline fails";
55+
end
56+
Badge = jsonencode(Badge);
57+
writelines(Badge,fullfile("Images","TestedWith.json"));
58+
59+
if ShowReport
60+
web(fullfile(Folder,"index.html"))
61+
end
62+
63+
end

SoftwareTests/SolnSmokeTests.m

Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
classdef SolnSmokeTests < matlab.unittest.TestCase
2+
3+
properties
4+
RootFolder
5+
isSolnOnPath
6+
end
7+
8+
properties (ClassSetupParameter)
9+
Project = {currentProject()};
10+
end
11+
12+
properties (TestParameter)
13+
File;
14+
end
15+
16+
methods (TestParameterDefinition,Static)
17+
18+
function File = GetScriptName(Project)
19+
% Retrieve student template files:
20+
RootFolder = Project.RootFolder;
21+
File = dir(fullfile(RootFolder,"Scripts","*.mlx"));
22+
File = {File.name};
23+
end
24+
25+
end
26+
27+
methods (TestClassSetup)
28+
29+
function SetUpPath(testCase,Project)
30+
% Navigate to project root folder:
31+
testCase.RootFolder = Project.RootFolder;
32+
cd(testCase.RootFolder)
33+
34+
% Check that solutions are on path:
35+
testCase.isSolnOnPath = isfolder("Solutions");
36+
if testCase.isSolnOnPath == 0
37+
addpath(fullfile(testCase.RootFolder,"InstructorResources","Solutions"))
38+
end
39+
40+
% Close the StartUp app if still open:
41+
delete(findall(groot,'Name','StartUp App'))
42+
43+
% Log MATLAB version:
44+
testCase.log("Running in " + version)
45+
46+
end % function setUpPath
47+
48+
end % methods (TestClassSetup)
49+
50+
methods(Test)
51+
52+
% Check that solutions files exist for each of the student
53+
% templates
54+
function ExistSolns(testCase,File)
55+
SolutionName = replace(string(File),".mlx","Soln.mlx");
56+
assert(exist(SolutionName,"file"),"Missing solutions for "+File);
57+
end
58+
59+
60+
function SmokeRun(testCase,File)
61+
62+
% Navigate to project root folder:
63+
cd(testCase.RootFolder)
64+
FileToRun = replace(string(File),".mlx","Soln.mlx");
65+
66+
% Pre-test:
67+
PreFiles = CheckPreFile(testCase,FileToRun);
68+
run(PreFiles);
69+
70+
% Run SmokeTest
71+
disp(">> Running " + FileToRun);
72+
try
73+
run(fullfile("InstructorResources","Solutions",FileToRun));
74+
catch ME
75+
76+
end
77+
78+
% Post-test:
79+
PostFiles = CheckPostFile(testCase,FileToRun);
80+
run(PostFiles)
81+
82+
% Log every figure created during run:
83+
Figures = findall(groot,'Type','figure');
84+
Figures = flipud(Figures);
85+
if ~isempty(Figures)
86+
for f = 1:size(Figures,1)
87+
if ~isempty(Figures(f).Number)
88+
FigDiag = matlab.unittest.diagnostics.FigureDiagnostic(Figures(f),'Formats','png');
89+
log(testCase,1,FigDiag);
90+
end
91+
end
92+
end
93+
94+
% Close all figures and Simulink models
95+
close all force
96+
if any(matlab.addons.installedAddons().Name == "Simulink")
97+
bdclose all
98+
end
99+
100+
% Rethrow error if any
101+
if exist("ME","var")
102+
if ~any(strcmp(ME.identifier,KnownIssuesID))
103+
rethrow(ME)
104+
end
105+
end
106+
107+
end
108+
109+
end
110+
111+
methods (Access = private)
112+
113+
function Path = CheckPreFile(testCase,Filename)
114+
PreFile = "Pre"+replace(Filename,".mlx",".m");
115+
PreFilePath = fullfile(testCase.RootFolder,"SoftwareTests","PreFiles",PreFile);
116+
if ~isfolder(fullfile(testCase.RootFolder,"SoftwareTests/PreFiles"))
117+
mkdir(fullfile(testCase.RootFolder,"SoftwareTests/PreFiles"))
118+
end
119+
if ~isfile(PreFilePath)
120+
writelines("% Pre-run script for "+Filename,PreFilePath)
121+
writelines("% ---- Known Issues -----",PreFilePath,'WriteMode','append');
122+
writelines("KnownIssuesID = "+char(34)+char(34)+";",PreFilePath,'WriteMode','append');
123+
writelines("% ---- Pre-run commands -----",PreFilePath,'WriteMode','append');
124+
writelines(" ",PreFilePath,'WriteMode','append');
125+
end
126+
Path = PreFilePath;
127+
end
128+
129+
function Path = CheckPostFile(testCase,Filename)
130+
PostFile = "Post"+replace(Filename,".mlx",".m");
131+
PostFilePath = fullfile(testCase.RootFolder,"SoftwareTests","PostFiles",PostFile);
132+
if ~isfolder(fullfile(testCase.RootFolder,"SoftwareTests/PostFiles"))
133+
mkdir(fullfile(testCase.RootFolder,"SoftwareTests/PostFiles"))
134+
end
135+
if ~isfile(PostFilePath)
136+
writelines("% Post-run script for "+Filename,PostFilePath)
137+
writelines("% ---- Post-run commands -----",PostFilePath,'WriteMode','append');
138+
writelines(" ",PostFilePath,'WriteMode','append');
139+
end
140+
Path = PostFilePath;
141+
end
142+
143+
end
144+
145+
end

0 commit comments

Comments
 (0)