-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added tested badge for github release
- Loading branch information
Showing
5 changed files
with
206 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
name: Module Test | ||
|
||
# Controls when the action will run. | ||
on: | ||
push: | ||
branches: [ release ] | ||
pull_request: | ||
branches: [ release ] | ||
|
||
jobs: | ||
RunTests: | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
MATLABVersion: [R2024a] | ||
runs-on: ubuntu-latest | ||
steps: | ||
# Checks-out your repository | ||
- uses: actions/checkout@v3 | ||
|
||
# Sets up MATLAB | ||
- name: Setup MATLAB | ||
uses: matlab-actions/setup-matlab@v1 | ||
with: | ||
release: ${{ matrix.MATLABVersion }} | ||
|
||
# Run all the tests | ||
- name: Run SmokeTests | ||
uses: matlab-actions/run-command@v1 | ||
with: | ||
command: openProject(pwd); RunAllTests; | ||
|
||
# Upload the test results as artifact | ||
- name: Upload TestResults | ||
if: always() | ||
uses: actions/[email protected] | ||
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/[email protected] | ||
with: | ||
name: TestResults | ||
path: ./SoftwareTests/ | ||
|
||
# Create the test results badge | ||
- name: Run CreateBadge | ||
uses: matlab-actions/run-command@v1 | ||
with: | ||
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"schemaVersion":1,"label":"Tested with","color":"success","message":"R2024a"} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
% 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")); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
function RunAllTest(EnableReport,ReportFolder) | ||
arguments | ||
EnableReport (1,1) logical = false; | ||
ReportFolder (1,1) string = "public"; | ||
end | ||
|
||
import matlab.unittest.plugins.TestReportPlugin; | ||
|
||
% Create a runner | ||
Runner = matlab.unittest.TestRunner.withTextOutput; | ||
if EnableReport | ||
Folder = fullfile(currentProject().RootFolder,ReportFolder); | ||
if ~isfolder(Folder) | ||
mkdir(Folder) | ||
else | ||
rmdir(Folder,'s') | ||
mkdir(Folder) | ||
end | ||
Plugin = TestReportPlugin.producingHTML(Folder,... | ||
"IncludingPassingDiagnostics",true,... | ||
"IncludingCommandWindowText",true,... | ||
"LoggingLevel",matlab.automation.Verbosity(1)); | ||
Runner.addPlugin(Plugin); | ||
end | ||
|
||
% Create the test suite with SmokeTest and Function test if they exist | ||
Suite = testsuite("SmokeTests"); | ||
Suite = [Suite testsuite("FunctionTests")]; | ||
|
||
% Run the test suite | ||
Results = Runner.run(Suite); | ||
|
||
if EnableReport | ||
web(fullfile(Folder,"index.html")) | ||
else | ||
T = table(Results); | ||
disp(newline + "Test summary:") | ||
disp(T) | ||
end | ||
|
||
% Format the results in a table and save them | ||
ResultsTable = table(Results') | ||
writetable(ResultsTable,fullfile("SoftwareTests","TestResults_"+release_version+".txt")); | ||
|
||
% Assert success of test | ||
assertSuccess(Results); | ||
|
||
end |