Skip to content

Commit efab0bb

Browse files
committed
Added badge to repo. Removed old startup files from project.
1 parent c4b42f6 commit efab0bb

16 files changed

+162
-198
lines changed

.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/[email protected]
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/[email protected]
@@ -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":"","color":"success"}
1+
{"schemaVersion":1,"label":"Tested with","color":"success","message":"R2022a | R2022b | R2023a | R2023b | R2024a"}

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55

66
[![View on File Exchange](https://www.mathworks.com/matlabcentral/images/matlab-file-exchange.svg)](https://www.mathworks.com/matlabcentral/fileexchange/113670-beam-bending-and-deflection) or [![Open in MATLAB Online](https://www.mathworks.com/images/responsive/global/open-in-matlab-online.svg)](https://matlab.mathworks.com/open/github/v1?repo=MathWorks-Teaching-Resources/Beam-Bending-and-Deflection&project=MechanicsOfMaterials.prj)
77

8+
![MATLAB Versions Tested](https://img.shields.io/endpoint?url=https%3A%2F%2Fraw.githubusercontent.com%2FMathWorks-Teaching-Resources%2FBeam-Bending-and-Deflection%2Frelease%2FImages%2FTestedWith.json)
9+
810
**Curriculum Module**
911

1012
_Created with R2022a. Compatible with R2022a and later releases._

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"));

0 commit comments

Comments
 (0)