diff --git a/.github/actions/check-code/action.yml b/.github/actions/check-code/action.yml index 77e9921..998b263 100644 --- a/.github/actions/check-code/action.yml +++ b/.github/actions/check-code/action.yml @@ -16,9 +16,25 @@ inputs: runs: using: "composite" steps: + - name: Check if buildfile exists + id: check-buildfile + shell: bash + run: | + if [ -f "buildfile.m" ]; then + echo "exists=true" >> $GITHUB_OUTPUT + else + echo "exists=false" >> $GITHUB_OUTPUT + fi + + - name: Check for MATLAB code issues (buildtool) + if: steps.check-buildfile.outputs.exists == 'true' + uses: matlab-actions/run-build@v2 + with: + tasks: check + - name: Check for MATLAB code issues + if: steps.check-buildfile.outputs.exists != 'true' uses: matlab-actions/run-command@v2 - if: always() with: command: | addpath(genpath("${{ inputs.tools_directory }}")); diff --git a/.github/actions/test-code/action.yml b/.github/actions/test-code/action.yml index 0b784c5..78d419f 100644 --- a/.github/actions/test-code/action.yml +++ b/.github/actions/test-code/action.yml @@ -14,9 +14,25 @@ inputs: runs: using: "composite" steps: + - name: Check if buildfile exists + id: check-buildfile + shell: bash + run: | + if [ -f "buildfile.m" ]; then + echo "exists=true" >> $GITHUB_OUTPUT + else + echo "exists=false" >> $GITHUB_OUTPUT + fi + + - name: Run tests (buildtool) + if: steps.check-buildfile.outputs.exists == 'true' + uses: matlab-actions/run-build@v2 + with: + tasks: test + - name: Run MATLAB test suites + if: steps.check-buildfile.outputs.exists != 'true' uses: matlab-actions/run-command@v2 - if: always() with: command: | addpath(genpath("${{ inputs.tools_directory }}")); diff --git a/buildfile.m b/buildfile.m new file mode 100644 index 0000000..d002877 --- /dev/null +++ b/buildfile.m @@ -0,0 +1,37 @@ +function plan = buildfile +%buildfile - Build configuration for MatBox CI tasks +% +% Defines tasks for continuous integration using MATLAB's buildtool. +% Available tasks: +% buildtool setup - Install MatBox and set up paths +% buildtool check - Identify code issues +% buildtool test - Run tests with code coverage +% +% Requires MATLAB R2023b or later. + + import matlab.buildtool.tasks.CodeIssuesTask + import matlab.buildtool.tasks.TestTask + + plan = buildplan(localfunctions); + + plan("setup").Description = "Install MatBox and set up paths"; + + plan("check") = CodeIssuesTask("code"); + plan("check").Description = ... + "Identify code issues using MATLAB code analyzer"; + plan("check").Dependencies = "setup"; + + plan("test") = TestTask( ... + Tests="tools/tests", ... + SourceFiles="code"); + plan("test").Description = "Run tests with code coverage"; + plan("test").Dependencies = "setup"; + + plan.DefaultTasks = ["check", "test"]; +end + +function setupTask(~) +%setupTask - Install MatBox and add tools to MATLAB path + addpath(genpath("tools")); + installMatBox(); +end diff --git a/code/templates/buildfile.m b/code/templates/buildfile.m new file mode 100644 index 0000000..fb34beb --- /dev/null +++ b/code/templates/buildfile.m @@ -0,0 +1,42 @@ +function plan = buildfile +%buildfile - Build configuration for toolbox CI tasks +% +% Defines tasks for continuous integration using MATLAB's buildtool. +% Available tasks: +% buildtool setup - Set up paths and install dependencies +% buildtool check - Identify code issues +% buildtool test - Run tests with code coverage +% +% Requires MATLAB R2023b or later. +% +% Note: Adapt the source and test folder paths to match your project +% structure. + + import matlab.buildtool.tasks.CodeIssuesTask + import matlab.buildtool.tasks.TestTask + + plan = buildplan(localfunctions); + + plan("setup").Description = "Set up paths and install dependencies"; + + plan("check") = CodeIssuesTask("code"); + plan("check").Description = ... + "Identify code issues using MATLAB code analyzer"; + plan("check").Dependencies = "setup"; + + plan("test") = TestTask( ... + Tests="tools/tests", ... + SourceFiles="code"); + plan("test").Description = "Run tests with code coverage"; + plan("test").Dependencies = "setup"; + + plan.DefaultTasks = ["check", "test"]; +end + +function setupTask(~) +%setupTask - Set up MATLAB path and install dependencies + addpath(genpath("tools")); + if exist("installMatBox", "file") + installMatBox(); + end +end