Skip to content

Commit 4fdda8f

Browse files
authored
Refactor code and add support for test results summary and logs grouping via common-utils (#70)
* Add test results data viz * update imports * print total tests count * update yml * check workspace * fix join * update pluginPath * move resources * add copy dir command * remove test file * rename resource * update namespace * update counts to stats * fix error * move failed tests section above all tests * introduce test failure * update failed tests view * add title and preserve MATLAB formatting * add more tests and update view * try nested table * unify sections * format diagnostics * format table * format function calls * update testcase * more formattinhg * update join separator * update all join separators * add sub-heading * introduce test failure * remove diagnostics formatting * add formatting for double \n * add whitespace * debug * debug * debug * debug * double \n formatting * debug * debug * debug * debug * debug * debug * debug * debug * debug * update diagnostics condition * update file path * update display path * add action name * update workspace * refactor * verify multiple test runs in same action * add grouping * add test class grouping * update test class grouping * update test class grouping * remove test case grouping * remove old grouping * add tests * add multi-platform testting * debug * update test setup * remove extra files and add more MATLAB tests * update os check * add continue-on-error * update assumption failure * format code and add more tests * update os info * update package * move fatalAssertion failure to a new file so it runs at the end * fix codescan issue and add help icon * fix test * fix typo * remove fatal assertion as it cause other test scripts to not run * update genscript url temporarily for dev * move test summary and log grouping to common-utils * check if node_modules is present * reorder steps in npm ci command * update common-utils repo * update bat.yml * use matlab module from common-utils * update view generation preferences * update bat.yml * add tests log grouping * commit untracked plugin files * update as per common-utils update * revert plugins path logic * update plugins path and add execOptions * fix test failure * use common-utils v1.0.0 * fix package-lock.json
1 parent c7667c9 commit 4fdda8f

File tree

10 files changed

+1085
-533
lines changed

10 files changed

+1085
-533
lines changed

.github/workflows/bat.yml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,12 @@ jobs:
3636
uses: matlab-actions/setup-matlab@v2
3737
with:
3838
products: |
39+
MATLAB_Test
3940
Simulink
4041
Simulink_Test
4142
Simulink_Coverage
4243
- name: Run MATLAB Tests
44+
continue-on-error: true
4345
uses: ./
4446
with:
4547
source-folder: sample
@@ -58,6 +60,7 @@ jobs:
5860
- name: Set up diary for logging
5961
run: echo 'diary console.log' >> startup.m
6062
- name: Run run-test command
63+
continue-on-error: true
6164
uses: ./
6265
with:
6366
test-results-simulink-test: test-results/simulinktest.mldatx
@@ -90,4 +93,8 @@ jobs:
9093
grep -q "runInParallel" console.log
9194
grep -q "'OutputDetail', 3" console.log
9295
grep -q "'LoggingLevel', 3" console.log
93-
shell: bash
96+
shell: bash
97+
- name: Verify workflow command is added
98+
run: |
99+
grep "::group::TheTruth" output.log
100+
shell: bash

.npmrc

Lines changed: 0 additions & 1 deletion
This file was deleted.

package-lock.json

Lines changed: 1015 additions & 494 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,22 +13,24 @@
1313
"package": "ncc build --minify",
1414
"test": "jest",
1515
"all": "npm test && npm run build && npm run package",
16-
"ci": "npm run clean && npm run deps && npm ci && npm run all"
16+
"ci": "npm run clean && npm ci && npm run deps && npm run all"
1717
},
1818
"files": [
1919
"lib/"
2020
],
2121
"dependencies": {
2222
"@actions/core": "^1.11.1",
2323
"@actions/exec": "^1.1.1",
24-
"run-matlab-command-action": "github:matlab-actions/run-command#v2.3.0"
24+
"common-utils": "github:matlab-actions/common-utils#v1.0.0"
2525
},
2626
"devDependencies": {
2727
"@types/jest": "^30.0.0",
28+
"@types/jsdom": "^21.1.7",
2829
"@types/node": "^24.3.0",
2930
"@vercel/ncc": "^0.38.3",
3031
"jest": "^30.0.5",
3132
"jest-circus": "^30.0.5",
33+
"jsdom": "^26.1.0",
3234
"prettier": "3.6.2",
3335
"ts-jest": "^29.4.1",
3436
"typescript": "^5.9.2"
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
classdef GitHubLogTestPluginService < matlab.buildtool.internal.services.ciplugins.CITestRunnerPluginService
2+
% Copyright 2025 The MathWorks, Inc.
3+
4+
methods
5+
function plugins = providePlugins(~, ~)
6+
plugins = testframework.GitHubLogTestPlugin();
7+
end
8+
end
9+
end
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
classdef GitHubLogTestPlugin < matlab.unittest.plugins.TestRunnerPlugin
2+
% Copyright 2025 The MathWorks, Inc.
3+
4+
methods (Access=protected)
5+
function runTestClass(plugin, pluginData)
6+
% Add GitHub workflow command for starting a test class output group
7+
disp("::group::" + pluginData.Name);
8+
9+
% Invoke the superclass method
10+
runTestClass@matlab.unittest.plugins.TestRunnerPlugin(plugin, pluginData);
11+
12+
% End the test class output group
13+
disp("::endgroup::");
14+
end
15+
end
16+
end

sample/tAssumptionFailure.m

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
classdef tAssumptionFailure < matlab.unittest.TestCase
2+
methods (Test)
3+
function testAssumptionFailure(testCase)
4+
testCase.assumeEqual(1+1, 11);
5+
end
6+
end
7+
end

scripts/setupdeps.sh

Lines changed: 2 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,8 @@
11
#!/bin/bash
22

3-
SCRIPTGEN_URL='https://ssd.mathworks.com/supportfiles/ci/matlab-script-generator/v0/matlab-script-generator.zip'
4-
RMC_BASE_URL='https://ssd.mathworks.com/supportfiles/ci/run-matlab-command/v2'
5-
SUPPORTED_OS=('win64' 'maci64' 'maca64' 'glnxa64')
6-
7-
# Create dist directory if it doesn't already exist
8-
DISTDIR="$(pwd)/dist"
9-
mkdir -p $DISTDIR/bin
10-
11-
# Download and extract in a temporary directory
12-
WORKINGDIR=$(mktemp -d -t rmc_build.XXXXXX)
13-
cd $WORKINGDIR
3+
source ./node_modules/common-utils/scripts/setupdeps.sh
144

15-
wget -O "$WORKINGDIR/license.txt" "$RMC_BASE_URL/license.txt"
16-
wget -O "$WORKINGDIR/thirdpartylicenses.txt" "$RMC_BASE_URL/thirdpartylicenses.txt"
17-
18-
for os in ${SUPPORTED_OS[@]}
19-
do
20-
if [[ $os == 'win64' ]] ; then
21-
bin_ext='.exe'
22-
else
23-
bin_ext=''
24-
fi
25-
mkdir -p "$WORKINGDIR/$os"
26-
wget -O "$WORKINGDIR/$os/run-matlab-command$bin_ext" "$RMC_BASE_URL/$os/run-matlab-command$bin_ext"
27-
done
5+
SCRIPTGEN_URL='https://ssd.mathworks.com/supportfiles/ci/matlab-script-generator/v0/matlab-script-generator.zip'
286

297
wget -O scriptgen.zip $SCRIPTGEN_URL
308
unzip -qod scriptgen scriptgen.zip
@@ -33,4 +11,3 @@ rm scriptgen.zip
3311

3412
mv -f ./* "$DISTDIR/bin"
3513
rm -rf $WORKINGDIR
36-

src/index.ts

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
// Copyright 2020-2023 The MathWorks, Inc.
1+
// Copyright 2020-2025 The MathWorks, Inc.
22

33
import * as core from "@actions/core";
44
import * as exec from "@actions/exec";
5-
import { matlab } from "run-matlab-command-action";
65
import * as scriptgen from "./scriptgen";
6+
import { matlab, testResultsSummary } from "common-utils";
77

88
/**
99
* Gather action inputs and then run action
@@ -34,14 +34,28 @@ async function run() {
3434
const command = scriptgen.generateCommand(options);
3535
const startupOptions = core.getInput("startup-options").split(" ");
3636

37-
const helperScript = await core.group("Generate script", async () => {
38-
const helperScript = await matlab.generateScript(workspaceDir, command);
39-
core.info("Successfully generated script");
40-
return helperScript;
41-
});
37+
const helperScript = await matlab.generateScript(workspaceDir, command);
38+
const execOptions = {
39+
env: {
40+
...process.env,
41+
MW_BATCH_LICENSING_ONLINE:'true', // Remove when online batch licensing is the default
42+
}
43+
};
44+
core.info("Successfully generated test script!");
45+
46+
await matlab.runCommand(
47+
helperScript,
48+
platform,
49+
architecture,
50+
(cmd, args) => exec.exec(cmd, args, execOptions),
51+
startupOptions
52+
).finally(() => {
53+
const runnerTemp = process.env.RUNNER_TEMP || '';
54+
const runId = process.env.GITHUB_RUN_ID || '';
55+
const actionName = process.env.GITHUB_ACTION || '';
4256

43-
await core.group("Run command", async () => {
44-
await matlab.runCommand(helperScript, platform, architecture, exec.exec, startupOptions);
57+
testResultsSummary.processAndAddTestSummary(runnerTemp, runId, actionName, workspaceDir);
58+
core.summary.write();
4559
});
4660
}
4761

tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"compilerOptions": {
3-
"target": "ES6",
3+
"target": "ES2022",
44
"module": "CommonJS",
55
"declaration": true,
66
"sourceMap": true,

0 commit comments

Comments
 (0)