Skip to content

Commit

Permalink
Workflow command support for MATLAB Build results (#32)
Browse files Browse the repository at this point in the history
* Added workflow command support

* Added test case in bat.yml

* updated test case in bat.yml

* updated test case in bat.yml

* updated test case in bat.yml

* updated test case in bat.yml

* updated test case in bat.yml

* updated test case in bat.yml

* updated test case in bat.yml

* updated test case in bat.yml

* updated test case in bat.yml

* updated test case in bat.yml

* updated test case in bat.yml

* updated test case in bat.yml

* updated test case in bat.yml

* updated test case in bat.yml

* updated test case in bat.yml

* updated test case in bat.yml

* updated test case in bat.yml

* updated test case in bat.yml

* updated test case in bat.yml

* updated test case in bat.yml

* updated test case in bat.yml

* updated test case in bat.yml

* updated as per review coments

* updated as per review coments

* updated as per review coments

* updated as per review coments

* updated as per review coments

* updated as per review coments

* updated as per review coments

* updated as per review coments

* updated as per review coments

* updated as per review coments

* updated as per review coments

* updated as per review coments

* updated as per review coments

* updated as per review coments

* updated exec option

* updated exec option

* updated exec option

* updated exec option

* updated exec option

* updated exec option

* updated exec option

* Added test to parse log

* Added test to parse log

* Testing grep

* Testing grep

* Testing grep

* Testing grep

* Testing grep

* Testing grep

* Testing grep

* Testing grep

* Testing grep

* reverted log changes

* Added tests using log read

* Added tests using log read

* Added tests using log read

* Added tests using log read

* Added tests using log read

* Added tests using log read

* Added tests using log read

* Added tests using log read

* Updated review comments

* changed copy path

* changed copy path

* Reverted copy changes

* Reverted copy changes

* Changed -cp strategy and plugin name

* Updated the test case

* Updated task name in group display

* Changed env variable setting

* Changed env variable setting

* Changed env variable setting

* Changed env variable setting

* Changed env variable setting

* Changed env variable setting

* Refactored test variables
  • Loading branch information
nbhoski authored May 20, 2024
1 parent 56989d3 commit ae4bdd2
Show file tree
Hide file tree
Showing 7 changed files with 73 additions and 13 deletions.
14 changes: 14 additions & 0 deletions .github/workflows/bat.yml
Original file line number Diff line number Diff line change
Expand Up @@ -170,3 +170,17 @@ jobs:
grep "deploying" buildlog.txt
! grep "checking" buildlog.txt
rm buildlog.txt
- name: Run build with startup options
continue-on-error: true
uses: ./
with:
tasks: deploy error
build-options: -continueOnFailure
startup-options: -logfile console.log

- name: Verify workflow command is added
run: |
grep "::group::deploy" console.log
grep "::error::error task failed" console.log
rm console.log
22 changes: 22 additions & 0 deletions plugins/+ciplugins/+github/GitHubLogPlugin.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
classdef GitHubLogPlugin < matlab.buildtool.plugins.BuildRunnerPlugin

% Copyright 2024 The MathWorks, Inc.

methods (Access=protected)

function runTask(plugin, pluginData)
% Add Github workflow command for grouping the tasks
disp("::group::" + pluginData.TaskResults.Name);

runTask@matlab.buildtool.plugins.BuildRunnerPlugin(plugin, pluginData);

% Add Github workflow command ::error:: if the task is failed
if pluginData.TaskResults.Failed
disp("::error::" + pluginData.TaskResults.Name + " task failed");
end

% Complete the group command
disp("::endgroup::");
end
end
end
13 changes: 13 additions & 0 deletions plugins/+ciplugins/+github/getDefaultPlugins.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
function plugins = getDefaultPlugins(pluginProviderData)

% Copyright 2024 The MathWorks, Inc.

arguments
pluginProviderData (1,1) struct = struct();
end

plugins = [ ...
matlab.buildtool.internal.getFactoryDefaultPlugins(pluginProviderData) ...
ciplugins.github.GitHubLogPlugin() ...
];
end
3 changes: 3 additions & 0 deletions scripts/setupdeps.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ SUPPORTED_OS=('win64' 'maci64' 'maca64' 'glnxa64')
DISTDIR="$(pwd)/dist/bin"
mkdir -p $DISTDIR

# Create plugin directory and copy plugin code
cp -R plugins $(pwd)/dist/

# Download and extract in a temporary directory
WORKINGDIR=$(mktemp -d -t rmc_build.XXXXXX)
cd $WORKINGDIR
Expand Down
4 changes: 3 additions & 1 deletion src/buildtool.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
// Copyright 2022-2024 The MathWorks, Inc.
import * as path from "path";

export interface RunBuildOptions {
Tasks?: string;
BuildOptions?: string;
}

export function generateCommand(options: RunBuildOptions): string {
let command: string = "buildtool";
const pluginsPath = path.join(__dirname,"plugins").replace("'","''");
let command: string = "addpath('"+ pluginsPath +"');buildtool"
if (options.Tasks) {
command = command + " " + options.Tasks;
}
Expand Down
10 changes: 6 additions & 4 deletions src/buildtool.unit.test.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
// Copyright 2022-2024 The MathWorks, Inc.

import * as path from "path";
import * as buildtool from "./buildtool";

describe("command generation", () => {
const command = "addpath('"+ path.join(__dirname, "plugins").replace("'","''") +"');buildtool"
it("buildtool invocation with unspecified tasks and build options", () => {
const options: buildtool.RunBuildOptions = {
Tasks: "",
BuildOptions: "",
};

const actual = buildtool.generateCommand(options);
expect(actual).toBe("buildtool")
expect(actual).toBe(command)
});

it("buildtool invocation with tasks specified", () => {
Expand All @@ -19,7 +21,7 @@ describe("command generation", () => {
};

const actual = buildtool.generateCommand(options);
expect(actual).toBe("buildtool compile test")
expect(actual).toBe(command + " compile test")
});

it("buildtool invocation with only build options", () => {
Expand All @@ -29,7 +31,7 @@ describe("command generation", () => {
};

const actual = buildtool.generateCommand(options);
expect(actual).toBe("buildtool -continueOnFailure -skip check")
expect(actual).toBe(command + " -continueOnFailure -skip check")
});

it("buildtool invocation with specified tasks and build options", () => {
Expand All @@ -39,6 +41,6 @@ describe("command generation", () => {
};

const actual = buildtool.generateCommand(options);
expect(actual).toBe("buildtool compile test -continueOnFailure -skip check")
expect(actual).toBe(command + " compile test -continueOnFailure -skip check")
});
});
20 changes: 12 additions & 8 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,19 @@ async function run() {
const command = buildtool.generateCommand(options);
const startupOptions = core.getInput("startup-options").split(" ");

const helperScript = await core.group("Generate script", async () => {
const helperScript = await matlab.generateScript(workspaceDir, command);
core.info("Successfully generated script");
return helperScript;
});
const helperScript = await matlab.generateScript(workspaceDir, command);
const execOptions = { env: {
...process.env,
"MW_MATLAB_BUILDTOOL_DEFAULT_PLUGINS_FCN_OVERRIDE":"ciplugins.github.getDefaultPlugins",
}};

await core.group("Run command", async () => {
await matlab.runCommand(helperScript, platform, architecture, exec.exec, startupOptions);
});
await matlab.runCommand(
helperScript,
platform,
architecture,
(cmd,args)=>exec.exec(cmd,args,execOptions),
startupOptions
);
}

run().catch((e) => {
Expand Down

0 comments on commit ae4bdd2

Please sign in to comment.