diff --git a/.github/workflows/bat.yml b/.github/workflows/bat.yml index 1a94da6..8518446 100644 --- a/.github/workflows/bat.yml +++ b/.github/workflows/bat.yml @@ -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 \ No newline at end of file diff --git a/plugins/+ciplugins/+github/GitHubLogPlugin.m b/plugins/+ciplugins/+github/GitHubLogPlugin.m new file mode 100644 index 0000000..c547a5e --- /dev/null +++ b/plugins/+ciplugins/+github/GitHubLogPlugin.m @@ -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 \ No newline at end of file diff --git a/plugins/+ciplugins/+github/getDefaultPlugins.m b/plugins/+ciplugins/+github/getDefaultPlugins.m new file mode 100644 index 0000000..cf16bd5 --- /dev/null +++ b/plugins/+ciplugins/+github/getDefaultPlugins.m @@ -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 \ No newline at end of file diff --git a/scripts/setupdeps.sh b/scripts/setupdeps.sh index e324d94..af8590b 100755 --- a/scripts/setupdeps.sh +++ b/scripts/setupdeps.sh @@ -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 diff --git a/src/buildtool.ts b/src/buildtool.ts index 8bf2d07..29890f7 100644 --- a/src/buildtool.ts +++ b/src/buildtool.ts @@ -1,4 +1,5 @@ // Copyright 2022-2024 The MathWorks, Inc. +import * as path from "path"; export interface RunBuildOptions { Tasks?: string; @@ -6,7 +7,8 @@ export interface RunBuildOptions { } 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; } diff --git a/src/buildtool.unit.test.ts b/src/buildtool.unit.test.ts index 12e3b3d..f8432e7 100644 --- a/src/buildtool.unit.test.ts +++ b/src/buildtool.unit.test.ts @@ -1,8 +1,10 @@ // 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: "", @@ -10,7 +12,7 @@ describe("command generation", () => { }; const actual = buildtool.generateCommand(options); - expect(actual).toBe("buildtool") + expect(actual).toBe(command) }); it("buildtool invocation with tasks specified", () => { @@ -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", () => { @@ -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", () => { @@ -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") }); }); diff --git a/src/index.ts b/src/index.ts index 6c24f07..af78399 100644 --- a/src/index.ts +++ b/src/index.ts @@ -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) => {