Skip to content

Commit 59fe8ed

Browse files
authored
Refactor code and add support for test, build results summary and logs grouping via common-utils (#81)
* update to use common-utils * add test results summary generation step * add sample MATLAB test * use new test summary api * update bat.yml * update bat.yml * update bat.yml * add write function call * update summary APIs and add workflow verification * update verification * update verification * update as per common-utils change * revert plugins path logic * update plugins path * use common-utils v1.0.0
1 parent b4cb80d commit 59fe8ed

File tree

11 files changed

+622
-4053
lines changed

11 files changed

+622
-4053
lines changed

.github/workflows/bat.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ jobs:
3333
name: built-action
3434
- name: Perform 'setup-matlab'
3535
uses: matlab-actions/setup-matlab@v2
36+
with:
37+
products: MATLAB_Test
3638
- name: Greet the world in style
3739
uses: ./
3840
with:
@@ -92,6 +94,23 @@ jobs:
9294
[~, f] = fileparts(pwd);
9395
assert(strcmp(f, 'subdir'));
9496
startup-options: -sd subdir
97+
- name: Create buildfile.m in project root for build and test summary
98+
shell: bash
99+
run: |
100+
cat <<'_EOF' >> "buildfile.m"
101+
function plan = buildfile
102+
import matlab.buildtool.tasks.TestTask
103+
104+
plan = buildplan(localfunctions);
105+
plan("preMadeTest") = TestTask;
106+
107+
plan.DefaultTasks = "preMadeTest";
108+
end
109+
_EOF
110+
- name: Run command with buildtool pre-made test task
111+
uses: ./
112+
with:
113+
command: buildtool preMadeTest
95114
- name: Verify environment variables make it to MATLAB
96115
uses: ./
97116
with:

package-lock.json

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

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,17 @@
1111
"build": "tsc",
1212
"deps": "bash ./scripts/setupdeps.sh",
1313
"package": "ncc build --minify",
14-
"test": "jest",
14+
"test": "jest --passWithNoTests",
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-
"uuid": "^11.1.0"
24+
"common-utils": "github:matlab-actions/common-utils#v1.0.0"
2525
},
2626
"devDependencies": {
2727
"@types/jest": "^30.0.0",

sample/TheTruth.m

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

scripts/setupdeps.sh

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

3-
RMC_BASE_URL='https://ssd.mathworks.com/supportfiles/ci/run-matlab-command/v2'
4-
SUPPORTED_OS=('win64' 'maci64' 'maca64' 'glnxa64')
3+
source ./node_modules/common-utils/scripts/setupdeps.sh
54

6-
# Create dist directory if it doesn't already exist
7-
DISTDIR="$(pwd)/dist/bin"
8-
mkdir -p $DISTDIR
9-
10-
# Download and extract in a temporary directory
11-
WORKINGDIR=$(mktemp -d -t rmc_build.XXXXXX)
12-
cd $WORKINGDIR
13-
14-
wget -O "$WORKINGDIR/license.txt" "$RMC_BASE_URL/license.txt"
15-
wget -O "$WORKINGDIR/thirdpartylicenses.txt" "$RMC_BASE_URL/thirdpartylicenses.txt"
16-
17-
for os in ${SUPPORTED_OS[@]}
18-
do
19-
if [[ $os == 'win64' ]] ; then
20-
bin_ext='.exe'
21-
else
22-
bin_ext=''
23-
fi
24-
mkdir -p "$WORKINGDIR/$os"
25-
wget -O "$WORKINGDIR/$os/run-matlab-command$bin_ext" "$RMC_BASE_URL/$os/run-matlab-command$bin_ext"
26-
done
27-
28-
mv -f ./* "$DISTDIR/"
5+
mv -f ./* "$DISTDIR/bin"
296
rm -rf $WORKINGDIR

src/index.ts

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
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 * as matlab from "./matlab";
6-
7-
export { matlab };
5+
import { matlab, testResultsSummary, buildSummary } from "common-utils";
86

97
/**
108
* Gather action inputs and then run action.
@@ -13,14 +11,27 @@ async function run() {
1311
const platform = process.platform;
1412
const architecture = process.arch;
1513
const workspaceDir = process.cwd();
14+
1615
const command = core.getInput("command");
1716
const startupOpts = core.getInput("startup-options").split(" ");
1817

1918
const helperScript = await matlab.generateScript(workspaceDir, command);
2019
const execOpts = {
21-
env: {...process.env, MW_BATCH_LICENSING_ONLINE:'true'} // Remove when online batch licensing is the default
20+
env: {
21+
...process.env,
22+
MW_BATCH_LICENSING_ONLINE:'true', // Remove when online batch licensing is the default
23+
"MW_MATLAB_BUILDTOOL_DEFAULT_PLUGINS_FCN_OVERRIDE": "buildframework.getDefaultPlugins",
24+
}
2225
};
23-
await matlab.runCommand(helperScript, platform, architecture, (cmd,args)=>exec.exec(cmd,args,execOpts), startupOpts);
26+
await matlab.runCommand(helperScript, platform, architecture, (cmd,args)=>exec.exec(cmd,args,execOpts), startupOpts).finally(() => {
27+
const runnerTemp = process.env.RUNNER_TEMP || '';
28+
const runId = process.env.GITHUB_RUN_ID || '';
29+
const actionName = process.env.GITHUB_ACTION || '';
30+
31+
buildSummary.processAndAddBuildSummary(runnerTemp, runId, actionName);
32+
testResultsSummary.processAndAddTestSummary(runnerTemp, runId, actionName, workspaceDir);
33+
core.summary.write();
34+
});
2435
}
2536

2637
// Only run this action if it is invoked directly. Do not run if this node

src/matlab.ts

Lines changed: 0 additions & 109 deletions
This file was deleted.

0 commit comments

Comments
 (0)