Skip to content

Commit

Permalink
Added badge to repo. Removed old startup files from project.
Browse files Browse the repository at this point in the history
  • Loading branch information
callieEDU committed Apr 16, 2024
1 parent c4b42f6 commit efab0bb
Show file tree
Hide file tree
Showing 16 changed files with 162 additions and 198 deletions.
44 changes: 29 additions & 15 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,49 +1,61 @@
name: MATLAB Build
name: Module Test

# Controls when the action will run.
on:
push:
branches: [ release ]
pull_request:
branches: [ release ]
workflow_dispatch:

jobs:
test:
RunTests:
strategy:
fail-fast: false
matrix:
MATLABVersion: [R2023a,R2023b]
MATLABVersion: [R2022a,R2022b,R2023a,R2023b,R2024a]
runs-on: ubuntu-latest
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
# Checks-out your repository
- uses: actions/checkout@v3

# Sets up MATLAB on the GitHub Actions runner
# Sets up MATLAB
- name: Setup MATLAB
uses: matlab-actions/setup-matlab@v1
with:
release: ${{ matrix.MATLABVersion }}

# Run SmokeTests
# Run all the tests
- name: Run SmokeTests
uses: matlab-actions/run-command@v1
with:
command: openProject(pwd); results = runtests(fullfile("SoftwareTests","SmokeTests.m")); assertSuccess(results);

# Run FunctionTests
- name: Run FunctionTests
uses: matlab-actions/run-command@v1
with:
command: openProject(pwd); results = runtests(fullfile("SoftwareTests","FunctionTests.m")); assertSuccess(results);
command: openProject(pwd); RunAllTests;

# Upload the test results as artifact
- name: Upload TestResults
if: always()
uses: actions/upload-artifact@v3.1.3
with:
name: TestResults
path: ./SoftwareTests/TestResults_${{ matrix.MATLABVersion }}.txt


CreateBadge:
if: ${{ always() }}
needs: [RunTests]
strategy:
fail-fast: false
runs-on: ubuntu-latest
steps:

# Checks-out your repository
- uses: actions/checkout@v3

# Sets up R2023b
- name: Setup MATLAB
uses: matlab-actions/setup-matlab@v1
with:
release: R2023b

# Download the test results from artifact
- name: Download TestResults
uses: actions/download-artifact@v2.1.1
Expand All @@ -55,14 +67,16 @@ jobs:
- name: Run CreateBadge
uses: matlab-actions/run-command@v1
with:
command: openProject(pwd); results = runtests(fullfile("SoftwareTests","CreateBadge.m"));
command: openProject(pwd); CreateBadge;

# Commit the JSON for the MATLAB releases badge
- name: Commit changed files
continue-on-error: true
run: |
git config user.name "${{ github.workflow }} by ${{ github.actor }}"
git config user.email "<>"
git pull
git add Images/TestedWith.json
git commit Images/TestedWith.json -m "Update CI badges ${{ github.ref_name }}"
git fetch
git push
85 changes: 0 additions & 85 deletions .gitlab-ci.yml

This file was deleted.

2 changes: 1 addition & 1 deletion Images/TestedWith.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"schemaVersion":1,"label":"tested with","message":"","color":"success"}
{"schemaVersion":1,"label":"Tested with","color":"success","message":"R2022a | R2022b | R2023a | R2023b | R2024a"}
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

[![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)

![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)

**Curriculum Module**

_Created with R2022a. Compatible with R2022a and later releases._
Expand Down
47 changes: 47 additions & 0 deletions SoftwareTests/CheckTestResults.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
classdef CheckTestResults < matlab.unittest.TestCase

properties (SetAccess = protected)
end

properties (ClassSetupParameter)
Project = {''};
end

properties (TestParameter)
Version
end


methods (TestParameterDefinition,Static)

function Version = GetResults(Project)
RootFolder = currentProject().RootFolder;
Version = dir(fullfile(RootFolder,"SoftwareTests","TestResults*.txt"));
Version = extractBetween([Version.name],"TestResults_",".txt");
end

end

methods (TestClassSetup)

function SetUpSmokeTest(testCase,Project)
try
currentProject;
catch
error("Project is not loaded.")
end
end

end

methods(Test)

function CheckResults(testCase,Version)
File = fullfile("SoftwareTests","TestResults_"+Version+".txt");
Results = readtable(File,TextType="string");
testCase.verifyTrue(all(Results.Passed));
end

end

end
110 changes: 28 additions & 82 deletions SoftwareTests/CreateBadge.m
Original file line number Diff line number Diff line change
@@ -1,82 +1,28 @@
% Run these tests with runMyTests
% All tests so far are on code expected to run without errors
% If/when we end up with a version that _should_ error,
% please add it to this set of examples
classdef CreateBadge < matlab.unittest.TestCase

properties
rootProject
results
end


methods (TestClassSetup)

function setUpPath(testCase)

try
project = currentProject;
testCase.rootProject = project.RootFolder;
cd(testCase.rootProject)
catch
error("Load project prior to run tests")
end

testCase.log("Running in " + version)

end % function setUpPath

function readResults(testCase)
Release = string([]);
Passed = [];
testCase.results = table(Release,Passed);

ResultFiles = dir("SoftwareTests"+filesep+"TestResults_*");
for kFiles = 1:size(ResultFiles)
Results = readtable(fullfile(ResultFiles(kFiles).folder,ResultFiles(kFiles).name),...
Delimiter=",",TextType="string");
Release = Results.Version(1);
Passed = all(Results.Status == "passed");
testCase.results(end+1,:) = table(Release,Passed);
end
end

end % methods (TestClassSetup)

methods(Test)

function writeBadge(testCase)

% Create JSON
badgeInfo = struct;
badgeInfo.schemaVersion = 1;
badgeInfo.label = "tested with";
badgeInfo.message = "";

% Check that results exist:
if size(testCase.results,1) == 0
badgeInfo.message = "None";
badgeInfo.color = "failed";
else
for i = 1:size(testCase.results,1)
if testCase.results.Passed(i)
if badgeInfo.message ~= ""
badgeInfo.message = badgeInfo.message + " | ";
end
badgeInfo.message = badgeInfo.message + string(testCase.results.Release(i));
end
end
badgeInfo.color = "success";
end

% Write JSON file out
badgeJSON = jsonencode(badgeInfo);
fid = fopen(fullfile("Images","TestedWith.json"),"w");
fwrite(fid,badgeJSON);
fclose(fid);

end

end

end
% Create the test suite with SmokeTest and Function test if they exist
Suite = testsuite("CheckTestResults");

% Create a runner with no plugins
Runner = matlab.unittest.TestRunner.withNoPlugins;

% Run the test suite
Results = Runner.run(Suite);

% Format the results in a table and save them
Results = table(Results');
Results = Results(Results.Passed,:);
Version = extractBetween(string(Results.Name),"Version=",")");


% Format the JSON file
Badge = struct;
Badge.schemaVersion = 1;
Badge.label = "Tested with";
if size(Results,1) >= 1
Badge.color = "success"
Badge.message = join(Version," | ");
else
Badge.color = "failure";
Badge.message = "Pipeline fails";
end
Badge = jsonencode(Badge);
writelines(Badge,fullfile("Images","TestedWith.json"));

0 comments on commit efab0bb

Please sign in to comment.