diff --git a/.github/workflows/matlab-ci.yml b/.github/workflows/matlab-ci.yml index 1ee7317..fba3f6a 100644 --- a/.github/workflows/matlab-ci.yml +++ b/.github/workflows/matlab-ci.yml @@ -3,76 +3,62 @@ name: MATLAB Build # Controls when the action will run. -on: - push: # Runs on push events - pull_request: # Runs on pull requests - workflow_dispatch: # Allows you to run this workflow manually from the Actions tab +on: + # Triggers the workflow on push or pull request events but only for the main branch + push: + branches: [ main ] + pull_request: + branches: [ main ] + + # Allows you to run this workflow manually from the Actions tab + workflow_dispatch: jobs: # This workflow contains a single job called "build" build: - strategy: - matrix: - platform: [ubuntu-latest, windows-latest, macos-latest] - release: [R2022b, latest] - # The type of runner that the job will run on - runs-on: ${{ matrix.platform }} + runs-on: ubuntu-latest # Steps represent a sequence of tasks that will be executed as part of the job steps: # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - - name: Start display server - if: matrix.platform == 'ubuntu-latest' - run: | - sudo apt-get install xvfb - Xvfb :99 & - echo "DISPLAY=:99" >> $GITHUB_ENV - - # Sets up MATLAB on the GitHub Actions runner - - name: Setup MATLAB - uses: matlab-actions/setup-matlab@v1 + # Sets up MATLAB on a GitHub-hosted runner + - name: Set up MATLAB + uses: matlab-actions/setup-matlab@v2 with: - release: ${{ matrix.release }} + release: R2024a # Runs a set of commands using the runners shell - - name: Run toolbox build - uses: matlab-actions/run-build@v1 - - # Runs a set of commands using the runners shell - - name: Run all tests - uses: matlab-actions/run-tests@v1 - with: - source-folder: . - test-results-pdf: artifacts/report/test-report.pdf - test-results-junit: artifacts/results/test-results.xml - code-coverage-cobertura: artifacts/coverage/coverage.xml + #- name: Run all tests + # uses: matlab-actions/run-tests@v2 + # with: + # source-folder: code - - - name: Upload Test Report - if: ${{ always() }} - uses: actions/upload-artifact@v3 + - name: Cache buildtool artifacts + id: buildtool-cache + uses: actions/cache@v4 with: - # Artifact name - name: Test Report - # A file, directory or wildcard pattern that describes what to upload - path: artifacts/report/test-report.pdf - - - name: Upload Test Results - if: ${{ always() }} - uses: actions/upload-artifact@v3 - with: - # Artifact name - name: Test Report - # A file, directory or wildcard pattern that describes what to upload - path: artifacts/results/test-results.xml - - - name: Upload Test Coverage - uses: actions/upload-artifact@v3 - with: - # Artifact name - name: Test Coverage - # A file, directory or wildcard pattern that describes what to upload - path: artifacts/coverage/coverage.xml + path: | + .buildtool + results + key: ${{ runner.os }}-buildtool-cache-${{ github.ref }} + + # Run MATLAB build + - name: Run the default "test" task in the build file + uses: matlab-actions/run-build@v2 + + #- name: List contents of .buildtool + # run: ls -la .buildtool/**/* + + #- name: Lookup test task trace + # uses: matlab-actions/run-command@v2 + # with: + # command: lookUpTestTaskTrace + + # You can use "run-command" to execute custom MATLAB scripts, functions, or statements + #- name: Run custom testing procedure + # uses: matlab-actions/run-command@v2 + # with: + # command: disp('Running my custom testing procedure!'); addpath('code'); results = runtests('IncludeSubfolders', true); assertSuccess(results); diff --git a/buildfile.m b/buildfile.m index 813068d..443ccd9 100644 --- a/buildfile.m +++ b/buildfile.m @@ -1,167 +1,34 @@ function plan = buildfile +import matlab.buildtool.tasks.* +% import matlabtest.plugins.codecoverage.StandaloneReport +% import matlab.unittest.plugins.codecoverage.CoberturaFormat plan = buildplan(localfunctions); -plan("test").Dependencies = ["mex", "pcode","setup"]; -plan("toolbox").Dependencies = ["lint", "test", "doc"]; +plan("clean") = CleanTask; -plan("doc").Dependencies = "docTest"; -plan("docTest").Dependencies = "setup"; +plan("check") = CodeIssuesTask; -plan("install").Dependencies = "integTest"; -plan("integTest").Dependencies = "toolbox"; +% plan("test") = TestTask(SourceFiles="toolbox").addCodeCoverage([StandaloneReport("mystandalonereport.html") CoberturaFormat("cov.xml")]); +% plan("test") = TestTask(); +plan("test") = TestTask(SourceFiles="toolbox"); -plan("lintAll") = matlab.buildtool.Task("Description","Find code issues in source and tests"); -plan("lintAll").Dependencies = ["lint", "lintTests"]; +plan("test").Dependencies = ["setup" "mex" "pcode"]; -plan.DefaultTasks = "integTest"; -end - -function setupTask(context) -% Setup paths for the build -addpath(fullfile(context.Plan.RootFolder,"toolbox")); -addpath(fullfile(context.Plan.RootFolder,"toolbox","doc")); -end - -function lintTask(~) -% Find static code issues - -issues = codeIssues(["toolbox", "pcode"]); -if ~isempty(issues.Issues) - disp(formattedDisplayText(issues.Issues,"SuppressMarkup",true)); - disp("Detected code issues in source") -end -if ~isempty(issues.SuppressedIssues) - disp(formattedDisplayText(issues.SuppressedIssues,"SuppressMarkup",true)); - disp("Detected suppressed issues in source") -end -end - -function mexTask(~) -% Compile mex files - -mex mex/convec.c -outdir toolbox/; -end - -function docTask(~) -% Generate the doc pages -connector.internal.startConnectionProfile("loopbackHttps"); -com.mathworks.matlabserver.connector.api.Connector.ensureServiceOn(); - -export("toolbox/doc/GettingStarted.mlx","toolbox/doc/GettingStarted.html"); -end - -function docTestTask(~) -% Test the doc and examples - -results = runtests("tests/doc"); -disp(results); -assertSuccess(results); -end - -function testTask(~) -% Run the unit tests - -results = runtests("tests"); -disp(results); -assertSuccess(results); -end - -function lintTestsTask(~) -% Find code issues in test code - -issues = codeIssues("tests"); -if ~isempty(issues.Issues) - disp(formattedDisplayText(issues.Issues,"SuppressMarkup",feature("hotlinks"))); - disp("Detected code issues in tests") -end -if ~isempty(issues.SuppressedIssues) - disp(formattedDisplayText(issues.SuppressedIssues,"SuppressMarkup",feature("hotlinks"))); - disp("Detected suppressed issues in tests") -end -end - -function toolboxTask(~) -% Create an mltbx toolbox package -dir toolbox/*.mex* -matlab.addons.toolbox.packageToolbox("Mass-Spring-Damper.prj","release/Mass-Spring-Damper.mltbx"); -end - -function pcodeTask(context) -% Obfuscate m-files - -% Grab the help text for the pcoded function to generate a help-only m-file -mfile = "pcode/springMassDamperDesign.m"; - -helpText = deblank(string(help(mfile))); -helpText = split(helpText,newline); -helpText = replaceBetween(helpText, 1, 1, "%"); % Add comment symbols - -% Write the file -fid = fopen("toolbox/springMassDamperDesign.m","w"); -closer = onCleanup(@() fclose(fid)); -fprintf(fid, "%s\n", helpText); - -% Now pcode the file -startDir = cd("toolbox/"); -cleaner = onCleanup(@() cd(startDir)); -pcode(fullfile(context.Plan.RootFolder,"pcode/springMassDamperDesign.m")); - -end - -function cleanTask(~) -% Clean all derived artifacts - -derivedFiles = [... - "toolbox/springMassDamperDesign.m" - "toolbox/springMassDamperDesign.p" - "toolbox/convec." + mexext - "toolbox/doc/GettingStarted.html" - "release/Mass-Spring-Damper.mltbx" - ]; +% plan("mex") = MexTask.forEachFile("mex\*.c", "toolbox"); -arrayfun(@deleteFile, derivedFiles); -end - -function integTestTask(~) -% Run integration tests - -import matlab.addons.toolbox.installToolbox; -import matlab.addons.toolbox.uninstallToolbox; - -sourceFile = which("simulateSystem"); - -% Remove source -sourcePaths = cellstr(fullfile(pwd, ["toolbox", "toolbox" + filesep + "doc"])); -origPath = rmpath(sourcePaths{:}); -pathCleaner = onCleanup(@() path(origPath)); - -% Install Toolbox -tbx = installToolbox("release/Mass-Spring-Damper.mltbx"); -tbxCleaner = onCleanup(@() uninstallToolbox(tbx)); +plan("mex") = MexTask("mex/convec.c", "toolbox"); -assert(~strcmp(sourceFile,which("simulateSystem")), ... - "Did not setup integ environment toolbox correctly"); +plan("pcode") = PcodeTask("pcode", "toolbox"); -results = runtests("tests","IncludeSubfolders",true); -disp(results); -assertSuccess(results); +% plan("toolbox") = ToolboxTask.fromToolboxProject("Mass-Spring-Damper.prj"); +% plan("toolbox").Dependencies = ["check" "test"]; -clear pathCleaner tbxCleaner; -assert(strcmp(sourceFile,which("simulateSystem")), ... - "Did not restore integ environment correctly"); - -end - -function installTask(~) -% Install the toolbox locally -matlab.addons.toolbox.installToolbox("release/Mass-Spring-Damper.mltbx"); +% plan.DefaultTasks = "toolbox"; +plan.DefaultTasks = ["check" "test"]; end - -function deleteFile(file) -if exist(file,"file") - delete(file); -end +function setupTask(~) +addpath("toolbox"); +addpath(fullfile("toolbox", "doc")); end - diff --git a/models/myf14.slx b/models/myf14.slx new file mode 100644 index 0000000..646d523 Binary files /dev/null and b/models/myf14.slx differ diff --git a/pcode/springMassDamperDesign.m b/pcode/springMassDamperDesign.m index c684477..0d5dc76 100755 --- a/pcode/springMassDamperDesign.m +++ b/pcode/springMassDamperDesign.m @@ -12,4 +12,4 @@ design.k = 5e6; % Spring Constant design.c = 5e5; -%design.c = 2*m*sqrt(design.k/m); % Damping Coefficient to be critically damped +% design.c = 2*m*sqrt(design.k/m); % Damping Coefficient to be critically damped diff --git a/toolbox/simulateSystem.m b/toolbox/simulateSystem.m index 3ec7574..86d0705 100755 --- a/toolbox/simulateSystem.m +++ b/toolbox/simulateSystem.m @@ -11,7 +11,8 @@ % Constant variables z0 = [-0.1; 0]; % Initial Position and Velocity -m = 1500; % Mass +% m = 1500; % Mass +m = 2500; % Mass odefun = @(t,z) [0 1; -k/m -c/m]*z; [t, z] = ode45(odefun, [0, 1], z0);