diff --git a/.circleci/config.yml b/.circleci/config.yml index d61d935..ebbb768 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -1,315 +1,36 @@ version: 2.1 - +setup: true orbs: - matlab: mathworks/matlab@<> - orb-tools: circleci/orb-tools@9.1 - win: circleci/windows@2.2.0 - -# Pipeline parameters -parameters: - # These pipeline parameters are required by the "trigger-integration-tests-workflow" - # job, by default. - run-integration-tests: - type: boolean - default: false - dev-orb-version: - type: string - default: "dev:alpha" - -integration-tests: &integration-tests - [ - integration-test-install, - integration-test-install-release, - integration-test-run-command, - integration-test-run-tests - ] - -executors: - linux: &linux-executor - machine: - image: ubuntu-2004:202111-02 - macos: - macos: - xcode: 13.2.1 - windows: - win/default - -jobs: - integration-test-install: - parameters: - executor: - type: executor - executor: <> - steps: - - matlab/install - - run: - name: Verify the matlab and mex scripts are available - command: | - set -e - matlab -batch version - os=$(uname) - if [[ $os = CYGWIN* || $os = MINGW* || $os = MSYS* ]]; then - mex.bat -h - else - mex -h - fi - shell: bash - - integration-test-install-release: - parameters: - executor: - type: executor - executor: <> - steps: - - matlab/install: - release: R2021a - - run: - name: Verify the matlab and mex scripts are available - command: | - set -e - matlab -batch "assert(strcmp(version('-release'),'2021a'))" - shell: bash + orb-tools: circleci/orb-tools@11.1 + shellcheck: circleci/shellcheck@3.1 - integration-test-run-command: - parameters: - executor: - type: executor - executor: <> - steps: - - matlab/install - - matlab/run-command: - command: f = fopen('myscript.m', 'w'); fwrite(f, 'assert(true)'); fclose(f); - - matlab/run-command: - command: myscript - - matlab/run-command: - command: "eval(\"a = 1+2\"); assert(a == 3); eval('b = 3+4'); assert(b == 7);" - - matlab/run-command: - command: 'eval("a = 1+2"); assert(a == 3); eval(''b = 3+4''); assert(b == 7);' - - matlab/run-command: - command: a = """hello world"""; b = '"hello world"'; assert(strcmp(a,b), a+b); - - matlab/run-command: - command: | - a = " !""#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~"; b = char([32:126]); assert(strcmp(a, b), a+b); - - run: - command: | - dir=$CIRCLE_WORKING_DIRECTORY - os=$(uname) - if [[ $os = CYGWIN* || $os = MINGW* || $os = MSYS* ]]; then - dir=$(cygpath -w "${dir/#\~/$HOME}") - fi - echo 'export WORK_DIR="'$dir'"' >> $BASH_ENV - shell: bash - - matlab/run-command: - command: | - [~, exp] = system("echo " + getenv('WORK_DIR')); exp = strtrim(exp); act = pwd; assert(strcmp(act, exp), strjoin({act exp}, '\n')); - - run: - command: echo 'myvar = 123' > startup.m - shell: bash - - matlab/run-command: - command: assert(myvar==123, 'myvar was not set as expected by startup.m') - - integration-test-run-tests: - parameters: - executor: - type: executor - executor: <> - steps: - # Setup for Integ tests for matlab/run-tests - - matlab/install - - run: - command: | - echo 'myvar = 123' > startup.m - mkdir src - echo 'function c=add(a,b);c=a+b;' > src/add.m - mkdir tests - echo "%% StartupTest" > tests/mytest.m - echo "evalin('base','assert(myvar==123)')" >> tests/mytest.m - echo "%% FirstTest" >> tests/mytest.m - echo "assert(add(1,2)==3)" >> tests/mytest.m - mkdir tests/filteredTest - echo "%% simpleTest" >> tests/filteredTest/filtertest.m - echo "assert(2==2)" >> tests/filteredTest/filtertest.m - printf "%% FilterByTag\n" >> tests/filteredTest/TaggedTest.m - printf "classdef (TestTags = {'FILTERED'}) TaggedTest < matlab.unittest.TestCase\n" >> tests/filteredTest/TaggedTest.m - printf "methods (Test)\n function testTag (testCase)\n assert(2==2);\n end\n end\n end" >> tests/filteredTest/TaggedTest.m - shell: bash - - # Integ tests for matlab/run-tests - - matlab/run-tests: - source-folder: src - - matlab/run-tests: - test-results-junit: test-results/matlab/results.xml - code-coverage-cobertura: code-coverage/coverage.xml - source-folder: src - - matlab/run-tests: - test-results-junit: test-results/matlab/filterdtestresult.xml - select-by-folder: tests/filteredTest - - matlab/run-tests: - test-results-junit: test-results/matlab/filterdtagresult.xml - select-by-tag: FILTERED - - - run: - name: Verify test results file was created - command: | - set -e - grep -q FirstTest test-results/matlab/results.xml - shell: bash - - run: - name: Verify code coverage file was created - command: | - set -e - grep -q add code-coverage/coverage.xml - shell: bash - - run: - name: Verify filtered test results file was created - command: | - set -e - grep -q simpleTest test-results/matlab/filterdtestresult.xml - grep -v FirstTest test-results/matlab/filterdtestresult.xml - shell: bash - - run: - name: Verify filter by tag test results file was created - command: | - set -e - grep -q TaggedTest test-results/matlab/filterdtagresult.xml - grep -v FirstTest test-results/matlab/filterdtagresult.xml - grep -v simpleTest test-results/matlab/filterdtagresult.xml - shell: bash - - # Set up for model coverage artifact tests - - when: - condition: - equal: [*linux-executor, <>] - steps: - - run: - command: | - mkdir simtests - cat \<<'_EOF' >> "simtests/createModelAndTest.m" - model = 'simple_model'; - evalin('base','bdclose all'); - if exist('simple_model.slx', 'file') == 0 - new_system(model); - load_system(model); - add_block('built-in/Constant', [model, '/Constant']); - save_system(model); - close_system(model); - sltest.testmanager.clear; - sltest.testmanager.clearResults; - tf = sltest.testmanager.TestFile('test.mldatx'); - cs = tf.getCoverageSettings; - cs.RecordCoverage = true; - cs.MdlRefCoverage = true; - cs.MetricSettings = 'd'; - ts = tf.getTestSuites; - tc = ts.getTestCases; - tc.setProperty('model', model); - tf.saveToFile; - tf.close; - sltest.testmanager.close; - end - disp('Created Model and Simulink Test file to simulate the model.'); - _EOF - shell: bash - - matlab/run-command: - command: cd simtests;createModelAndTest; - - matlab/run-tests: - select-by-folder: simtests - model-coverage-cobertura: model-coverage/coverage.xml - test-results-pdf: test-results/matlab/pdfresults.pdf - test-results-simulink-test: test-results/matlab/simulinkTest.mldatx - - run: - name: Verify pdf test report file generation - command: | - set -e - test -f test-results/matlab/pdfresults.pdf - shell: bash - - run: - name: Verify Simulink Test result file generation - command: | - set -e - test -f test-results/matlab/simulinkTest.mldatx - shell: bash - - run: - name: Verify model coverage file was created - command: | - set -e - grep -q simple_model model-coverage/coverage.xml - shell: bash +filters: &filters + tags: + only: /.*/ workflows: - # This `lint-pack_validate_publish-dev` workflow will run on any commit. - lint_pack-validate_publish-dev: - unless: << pipeline.parameters.run-integration-tests >> + lint-pack: jobs: - # Lint your YAML - - orb-tools/lint - - # pack your orb YAML files to a single orb.yml - # validate the orb.yml file to ensure it is well-formed - - orb-tools/pack - - # release dev version of orb, for testing & possible publishing. - # orb will be published as dev:alpha and dev:${CIRCLE_SHA1:0:7}. - # requires a CircleCI API token to be stored as CIRCLE_TOKEN (default) - # https://circleci.com/docs/2.0/managing-api-tokens - # store CIRCLE_TOKEN as a project env var or Contexts resource - # if using Contexts, add your context below - - orb-tools/publish-dev: + # Lint, pack, and review your orb + - orb-tools/lint: + filters: *filters + - orb-tools/pack: + filters: *filters + - orb-tools/review: + exclude: RC005 + filters: *filters + - shellcheck/check: + exclude: SC2148,SC2038,SC2086,SC2002,SC2016 + filters: *filters + - orb-tools/publish: orb-name: mathworks/matlab + vcs-type: << pipeline.project.type >> requires: - - orb-tools/lint - - orb-tools/pack - - # trigger an integration workflow to test the - # dev:${CIRCLE_SHA1:0:7} version of your orb - - orb-tools/trigger-integration-tests-workflow: - name: trigger-integration-dev - requires: - - orb-tools/publish-dev - - # This `integration-tests_prod-release` workflow will only run - # when the run-integration-tests pipeline parameter is set to true. - # It is meant to be triggered by the "trigger-integration-tests-workflow" - # job, and run tests on @dev:${CIRCLE_SHA1:0:7}. - integration-tests_prod-release: - when: << pipeline.parameters.run-integration-tests >> - jobs: - # your integration test jobs go here: essentially, run all your orb's - # jobs and commands to ensure they behave as expected. or, run other - # integration tests of your choosing - - integration-test-install: - matrix: - parameters: - executor: [linux, windows] - - - integration-test-install-release: - matrix: - parameters: - executor: [linux, windows] - - - integration-test-run-command: - matrix: - parameters: - executor: [linux, windows] - - - integration-test-run-tests: - matrix: - parameters: - executor: [linux, windows] - - # publish a semver version of the orb. relies on - # the commit subject containing the text "[semver:patch|minor|major|skip]" - # as that will determine whether a patch, minor or major - # version will be published or if publishing should - # be skipped. - # e.g. [semver:patch] will cause a patch version to be published. - - orb-tools/dev-promote-prod-from-commit-subject: - orb-name: mathworks/matlab - add-pr-comment: false - fail-if-semver-not-indicated: true - publish-version-tag: true - ssh-fingerprints: e0:48:de:54:c4:e8:fb:15:1c:1c:a5:89:95:e5:23:69 - requires: *integration-tests - filters: - branches: - only: master + [orb-tools/lint, orb-tools/review, orb-tools/pack, shellcheck/check] + filters: *filters + # Triggers the next workflow in the Orb Development Kit. + - orb-tools/continue: + pipeline-number: << pipeline.number >> + vcs-type: << pipeline.project.type >> + requires: [orb-tools/publish] + filters: *filters \ No newline at end of file diff --git a/.circleci/test-deploy.yml b/.circleci/test-deploy.yml new file mode 100644 index 0000000..d98d455 --- /dev/null +++ b/.circleci/test-deploy.yml @@ -0,0 +1,286 @@ +version: 2.1 +orbs: + matlab: mathworks/matlab@dev:<> + orb-tools: circleci/orb-tools@11.1 + win: circleci/windows@2.2.0 + +filters: &filters + tags: + only: /.*/ + +integration-tests: &integration-tests + [ + orb-tools/pack, + integration-test-install, + integration-test-install-release, + integration-test-run-command, + integration-test-run-tests + ] + +executors: + linux: &linux-executor + machine: + image: ubuntu-2204:edge + macos: + macos: + xcode: 13.2.1 + windows: + win/default + +jobs: + integration-test-install: + parameters: + executor: + type: executor + executor: <> + steps: + - checkout + - matlab/install + - run: + name: Verify the matlab and mex scripts are available + command: | + set -e + matlab -batch version + os=$(uname) + if [[ $os = CYGWIN* || $os = MINGW* || $os = MSYS* ]]; then + mex.bat -h + else + mex -h + fi + shell: bash + + integration-test-install-release: + parameters: + executor: + type: executor + executor: <> + steps: + - checkout + - matlab/install: + release: R2021a + - run: + name: Verify the matlab and mex scripts are available + command: | + set -e + matlab -batch "assert(strcmp(version('-release'),'2021a'))" + shell: bash + + integration-test-run-command: + parameters: + executor: + type: executor + executor: <> + steps: + - matlab/install + - matlab/run-command: + command: f = fopen('myscript.m', 'w'); fwrite(f, 'assert(true)'); fclose(f); + - matlab/run-command: + command: myscript + - matlab/run-command: + command: "eval(\"a = 1+2\"); assert(a == 3); eval('b = 3+4'); assert(b == 7);" + - matlab/run-command: + command: 'eval("a = 1+2"); assert(a == 3); eval(''b = 3+4''); assert(b == 7);' + - matlab/run-command: + command: a = """hello world"""; b = '"hello world"'; assert(strcmp(a,b), a+b); + - matlab/run-command: + command: | + a = " !""#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~"; b = char([32:126]); assert(strcmp(a, b), a+b); + - run: + command: | + dir=$CIRCLE_WORKING_DIRECTORY + os=$(uname) + if [[ $os = CYGWIN* || $os = MINGW* || $os = MSYS* ]]; then + dir=$(cygpath -w "${dir/#\~/$HOME}") + fi + echo 'export WORK_DIR="'$dir'"' >> $BASH_ENV + shell: bash + - matlab/run-command: + command: | + [~, exp] = system("echo " + getenv('WORK_DIR')); exp = strtrim(exp); act = pwd; assert(strcmp(act, exp), strjoin({act exp}, '\n')); + - run: + command: echo 'myvar = 123' > startup.m + shell: bash + - matlab/run-command: + command: assert(myvar==123, 'myvar was not set as expected by startup.m') + + integration-test-run-tests: + parameters: + executor: + type: executor + executor: <> + steps: + # Setup for Integ tests for matlab/run-tests + - matlab/install + - run: + command: | + echo 'myvar = 123' > startup.m + mkdir src + echo 'function c=add(a,b);c=a+b;' > src/add.m + mkdir tests + echo "%% StartupTest" > tests/mytest.m + echo "evalin('base','assert(myvar==123)')" >> tests/mytest.m + echo "%% FirstTest" >> tests/mytest.m + echo "assert(add(1,2)==3)" >> tests/mytest.m + mkdir tests/filteredTest + echo "%% simpleTest" >> tests/filteredTest/filtertest.m + echo "assert(2==2)" >> tests/filteredTest/filtertest.m + printf "%% FilterByTag\n" >> tests/filteredTest/TaggedTest.m + printf "classdef (TestTags = {'FILTERED'}) TaggedTest < matlab.unittest.TestCase\n" >> tests/filteredTest/TaggedTest.m + printf "methods (Test)\n function testTag (testCase)\n assert(2==2);\n end\n end\n end" >> tests/filteredTest/TaggedTest.m + shell: bash + + # Integ tests for matlab/run-tests + - matlab/run-tests: + source-folder: src + - matlab/run-tests: + test-results-junit: test-results/matlab/results.xml + code-coverage-cobertura: code-coverage/coverage.xml + source-folder: src + - matlab/run-tests: + test-results-html: test-results/matlab/html + code-coverage-html: code-coverage/html + source-folder: src + - matlab/run-tests: + test-results-junit: test-results/matlab/filterdtestresult.xml + select-by-folder: tests/filteredTest + - matlab/run-tests: + test-results-junit: test-results/matlab/filterdtagresult.xml + select-by-tag: FILTERED + + - run: + name: Verify test results file was created + command: | + set -e + grep -q FirstTest test-results/matlab/results.xml + shell: bash + - run: + name: Verify HTML test results report was created + command: | + set -e + grep -q FirstTest test-results/matlab/html/index.html + shell: bash + - run: + name: Verify code coverage file was created + command: | + set -e + grep -q add code-coverage/coverage.xml + shell: bash + - run: + name: Verify HTML code coverage report was created + command: | + set -e + grep -q CoverageSummary code-coverage/html/index.html + shell: bash + - run: + name: Verify filtered test results file was created + command: | + set -e + grep -q simpleTest test-results/matlab/filterdtestresult.xml + grep -v FirstTest test-results/matlab/filterdtestresult.xml + shell: bash + - run: + name: Verify filter by tag test results file was created + command: | + set -e + grep -q TaggedTest test-results/matlab/filterdtagresult.xml + grep -v FirstTest test-results/matlab/filterdtagresult.xml + grep -v simpleTest test-results/matlab/filterdtagresult.xml + shell: bash + + # Set up for model coverage artifact tests + - when: + condition: + equal: [*linux-executor, <>] + steps: + - run: + command: | + mkdir simtests + cat \<<'_EOF' >> "simtests/createModelAndTest.m" + model = 'simple_model'; + evalin('base','bdclose all'); + if exist('simple_model.slx', 'file') == 0 + new_system(model); + load_system(model); + add_block('built-in/Constant', [model, '/Constant']); + save_system(model); + close_system(model); + sltest.testmanager.clear; + sltest.testmanager.clearResults; + tf = sltest.testmanager.TestFile('test.mldatx'); + cs = tf.getCoverageSettings; + cs.RecordCoverage = true; + cs.MdlRefCoverage = true; + cs.MetricSettings = 'd'; + ts = tf.getTestSuites; + tc = ts.getTestCases; + tc.setProperty('model', model); + tf.saveToFile; + tf.close; + sltest.testmanager.close; + end + disp('Created Model and Simulink Test file to simulate the model.'); + _EOF + shell: bash + - matlab/run-command: + command: cd simtests;createModelAndTest; + - matlab/run-tests: + select-by-folder: simtests + model-coverage-cobertura: model-coverage/coverage.xml + test-results-pdf: test-results/matlab/pdfresults.pdf + test-results-simulink-test: test-results/matlab/simulinkTest.mldatx + - run: + name: Verify pdf test report file generation + command: | + set -e + test -f test-results/matlab/pdfresults.pdf + shell: bash + - run: + name: Verify Simulink Test result file generation + command: | + set -e + test -f test-results/matlab/simulinkTest.mldatx + shell: bash + - run: + name: Verify model coverage file was created + command: | + set -e + grep -q simple_model model-coverage/coverage.xml + shell: bash + +workflows: + test-deploy: + jobs: + # Make sure to include "filters: *filters" in every test job you want to run as part of your deployment. + - integration-test-install: + matrix: + parameters: + executor: [linux, windows] + + - integration-test-install-release: + matrix: + parameters: + executor: [linux, windows] + + - integration-test-run-command: + matrix: + parameters: + executor: [linux, windows] + + - integration-test-run-tests: + matrix: + parameters: + executor: [linux, windows] + + - orb-tools/pack: + filters: *filters + + - orb-tools/publish: + orb-name: mathworks/matlab + vcs-type: << pipeline.project.type >> + pub-type: production + requires: *integration-tests + filters: + branches: + only: master + tags: + only: /^v[0-9]+\.[0-9]+\.[0-9]+$/ diff --git a/src/commands/install.yml b/src/commands/install.yml index 9c0869d..06c30b0 100644 --- a/src/commands/install.yml +++ b/src/commands/install.yml @@ -13,38 +13,7 @@ parameters: steps: - run: name: Install MATLAB - command: | - downloadAndRun() { - url=$1 - shift - if [[ -x $(command -v sudo) ]]; then - curl -sfL $url | sudo -E bash -s -- "$@" - else - curl -sfL $url | bash -s -- "$@" - fi - } - - os=$(uname) - - # installer does not support the Docker executor type on Linux - if [[ $os = Linux ]] && awk -F/ '$2 == "docker"' /proc/self/cgroup | read; then - echo 'The Docker executor type is not supported.' - exit 1 - fi - - # install core system dependencies - if [[ $os = Linux ]]; then - downloadAndRun https://ssd.mathworks.com/supportfiles/ci/matlab-deps/v0/install.sh <> - fi - - # install ephemeral version of MATLAB - downloadAndRun https://ssd.mathworks.com/supportfiles/ci/ephemeral-matlab/v0/ci-install.sh --release <> - - # add MATLAB to path - tmpdir=$(dirname $(mktemp -u)) - rootdir=$(cat "$tmpdir/ephemeral_matlab_root") - if [[ $os = CYGWIN* || $os = MINGW* || $os = MSYS* ]]; then - rootdir=$(cygpath "$rootdir") - fi - echo 'export PATH="'$rootdir'/bin:$PATH"' >> $BASH_ENV + environment: + PARAM_RELEASE: <> + command: <> shell: bash diff --git a/src/commands/run-command.yml b/src/commands/run-command.yml index 8363f63..aaa851a 100644 --- a/src/commands/run-command.yml +++ b/src/commands/run-command.yml @@ -16,30 +16,7 @@ parameters: steps: - run: name: Run MATLAB command - command: | - tmpdir=$(mktemp -d 2>/dev/null || mktemp -d -t 'run-command') - - # download run command shell scripts - curl -sfLo "${tmpdir}/run-matlab-command.zip" https://ssd.mathworks.com/supportfiles/ci/run-matlab-command/v0/run-matlab-command.zip - unzip -qod "${tmpdir}/bin" "${tmpdir}/run-matlab-command.zip" - - # form OS appropriate paths for MATLAB - os=$(uname) - workdir=$(pwd) - scriptdir=$tmpdir - if [[ $os = CYGWIN* || $os = MINGW* || $os = MSYS* ]]; then - workdir=$(cygpath -w "$workdir") - scriptdir=$(cygpath -w "$scriptdir") - fi - - # create script to execute - script=command_${RANDOM} - scriptpath=${tmpdir}/${script}.m - echo "cd('${workdir//\'/\'\'}');" > "$scriptpath" - cat \<<'_EOF' >> "$scriptpath" - <> - _EOF - - # run MATLAB command - "${tmpdir}/bin/run_matlab_command.sh" "cd('${scriptdir//\'/\'\'}'); $script" + environment: + PARAM_COMMAND: <> + command: <> shell: bash diff --git a/src/commands/run-tests.yml b/src/commands/run-tests.yml index 88c5c53..f3f3a68 100644 --- a/src/commands/run-tests.yml +++ b/src/commands/run-tests.yml @@ -14,6 +14,11 @@ parameters: Path to write code coverage report in Cobertura XML format. type: string default: '' + code-coverage-html: + description: > + Path to write code coverage report in HTML format. + type: string + default: '' source-folder: description: > Location of the folder containing source code, relative to the project root folder. The @@ -46,6 +51,11 @@ parameters: Path to export Simulink Test Manager results in MLDATX format. type: string default: '' + test-results-html: + description: > + Path to write test results report in HTML format. + type: string + default: '' test-results-pdf: description: > Path to write test results report in PDF format. @@ -55,38 +65,16 @@ parameters: steps: - run: name: Run MATLAB tests - command: | - tmpdir=$(mktemp -d 2>/dev/null || mktemp -d -t 'run-tests') - - # download run command shell scripts - curl -sfLo "${tmpdir}/bin.zip" https://ssd.mathworks.com/supportfiles/ci/run-matlab-command/v0/run-matlab-command.zip - unzip -qod "${tmpdir}/bin" "${tmpdir}/bin.zip" - - # download script generator - curl -sfLo "${tmpdir}/scriptgen.zip" https://ssd.mathworks.com/supportfiles/ci/matlab-script-generator/v0/matlab-script-generator.zip - unzip -qod "${tmpdir}/scriptgen" "${tmpdir}/scriptgen.zip" - - # form OS appropriate paths for MATLAB - os=$(uname) - gendir=$tmpdir - if [[ $os = CYGWIN* || $os = MINGW* || $os = MSYS* ]]; then - gendir=$(cygpath -w "$gendir") - fi - - # generate and run MATLAB test script - "${tmpdir}/bin/run_matlab_command.sh" "\ - addpath('${gendir}/scriptgen');\ - testScript = genscript('Test',\ - 'JUnitTestResults','<>',\ - 'CoberturaCodeCoverage','<>',\ - 'SourceFolder','<>',\ - 'SelectByFolder','<>',\ - 'SelectByTag','<>',\ - 'CoberturaModelCoverage','<>',\ - 'SimulinkTestResults','<>',\ - 'PDFTestReport','<>');\ - disp('Running MATLAB script with contents:');\ - disp(testScript.Contents);\ - fprintf('__________\n\n');\ - run(testScript);" + environment: + PARAM_TEST_RESULTS_JUNIT: <> + PARAM_CODE_COVERAGE_COBERTURA: <> + PARAM_CODE_COVERAGE_HTML: <> + PARAM_SOURCE_FOLDER: <> + PARAM_SELECT_BY_FOLDER: <> + PARAM_SELECT_BY_TAG: <> + PARAM_MODEL_COVERAGE_COBERTURA: <> + PARAM_TEST_RESULTS_SIMULINK_TEST: <> + PARAM_TEST_RESULTS_HTML: <> + PARAM_TEST_RESULTS_PDF: <> + command: <> shell: bash diff --git a/src/examples/run-custom-script.yml b/src/examples/run-custom-script.yml index 2119357..ce5b7da 100644 --- a/src/examples/run-custom-script.yml +++ b/src/examples/run-custom-script.yml @@ -8,7 +8,7 @@ usage: jobs: build: machine: - image: ubuntu-1604:201903-01 + image: ubuntu-2004:202111-02 steps: - checkout - matlab/install diff --git a/src/examples/run-tests-with-report.yml b/src/examples/run-tests-with-report.yml index 2af92e8..84003c7 100644 --- a/src/examples/run-tests-with-report.yml +++ b/src/examples/run-tests-with-report.yml @@ -8,7 +8,7 @@ usage: jobs: build: machine: - image: ubuntu-1604:201903-01 + image: ubuntu-2004:202111-02 steps: - checkout - matlab/install diff --git a/src/scripts/install.sh b/src/scripts/install.sh new file mode 100644 index 0000000..fdff161 --- /dev/null +++ b/src/scripts/install.sh @@ -0,0 +1,33 @@ +downloadAndRun() { + url=$1 + shift + if [[ -x $(command -v sudo) ]]; then + curl -sfL $url | sudo -E bash -s -- "$@" + else + curl -sfL $url | bash -s -- "$@" + fi +} + +os=$(uname) + +# installer does not support the Docker executor type on Linux +if [[ $os = Linux ]] && awk -F/ '$2 == "docker"' /proc/self/cgroup | read -r; then + echo 'The Docker executor type is not supported.' + exit 1 +fi + +# install core system dependencies +if [[ $os = Linux ]]; then + downloadAndRun https://ssd.mathworks.com/supportfiles/ci/matlab-deps/v0/install.sh ${PARAM_RELEASE} +fi + +# install ephemeral version of MATLAB +downloadAndRun https://ssd.mathworks.com/supportfiles/ci/ephemeral-matlab/v0/ci-install.sh --release ${PARAM_RELEASE} + +# add MATLAB to path +tmpdir=$(dirname "$(mktemp -u)") +rootdir=$(cat "$tmpdir/ephemeral_matlab_root") +if [[ $os = CYGWIN* || $os = MINGW* || $os = MSYS* ]]; then + rootdir=$(cygpath "$rootdir") +fi +echo 'export PATH="'$rootdir'/bin:$PATH"' >> $BASH_ENV diff --git a/src/scripts/run-command.sh b/src/scripts/run-command.sh new file mode 100644 index 0000000..ca66f26 --- /dev/null +++ b/src/scripts/run-command.sh @@ -0,0 +1,25 @@ +tmpdir=$(mktemp -d 2>/dev/null || mktemp -d -t 'run-command') + +# download run command shell scripts +curl -sfLo "${tmpdir}/run-matlab-command.zip" https://ssd.mathworks.com/supportfiles/ci/run-matlab-command/v0/run-matlab-command.zip +unzip -qod "${tmpdir}/bin" "${tmpdir}/run-matlab-command.zip" + +# form OS appropriate paths for MATLAB +os=$(uname) +workdir=$(pwd) +scriptdir=$tmpdir +if [[ $os = CYGWIN* || $os = MINGW* || $os = MSYS* ]]; then + workdir=$(cygpath -w "$workdir") + scriptdir=$(cygpath -w "$scriptdir") +fi + +# create script to execute +script=command_${RANDOM} +scriptpath=${tmpdir}/${script}.m +echo "cd('${workdir//\'/\'\'}');" > "$scriptpath" +cat << EOF >> "$scriptpath" +${PARAM_COMMAND} +EOF + +# run MATLAB command +"${tmpdir}/bin/run_matlab_command.sh" "cd('${scriptdir//\'/\'\'}'); $script" diff --git a/src/scripts/run-tests.sh b/src/scripts/run-tests.sh new file mode 100644 index 0000000..41a60b2 --- /dev/null +++ b/src/scripts/run-tests.sh @@ -0,0 +1,35 @@ +tmpdir=$(mktemp -d 2>/dev/null || mktemp -d -t 'run-tests') + +# download run command shell scripts +curl -sfLo "${tmpdir}/bin.zip" https://ssd.mathworks.com/supportfiles/ci/run-matlab-command/v0/run-matlab-command.zip +unzip -qod "${tmpdir}/bin" "${tmpdir}/bin.zip" + +# download script generator +curl -sfLo "${tmpdir}/scriptgen.zip" https://ssd.mathworks.com/supportfiles/ci/matlab-script-generator/v0/matlab-script-generator.zip +unzip -qod "${tmpdir}/scriptgen" "${tmpdir}/scriptgen.zip" + +# form OS appropriate paths for MATLAB +os=$(uname) +gendir=$tmpdir +if [[ $os = CYGWIN* || $os = MINGW* || $os = MSYS* ]]; then + gendir=$(cygpath -w "$gendir") +fi + +# generate and run MATLAB test script +"${tmpdir}/bin/run_matlab_command.sh" "\ + addpath('${gendir}/scriptgen');\ + testScript = genscript('Test',\ + 'JUnitTestResults','${PARAM_TEST_RESULTS_JUNIT}',\ + 'CoberturaCodeCoverage','${PARAM_CODE_COVERAGE_COBERTURA}',\ + 'HTMLCodeCoverage','${PARAM_CODE_COVERAGE_HTML}',\ + 'SourceFolder','${PARAM_SOURCE_FOLDER}',\ + 'SelectByFolder','${PARAM_SELECT_BY_FOLDER}',\ + 'SelectByTag','$PARAM_SELECT_BY_TAG',\ + 'CoberturaModelCoverage','${PARAM_MODEL_COVERAGE_COBERTURA}',\ + 'SimulinkTestResults','${PARAM_TEST_RESULTS_SIMULINK_TEST}',\ + 'HTMLTestReport','${PARAM_TEST_RESULTS_HTML}',\ + 'PDFTestReport','${PARAM_TEST_RESULTS_PDF}');\ + disp('Running MATLAB script with contents:');\ + disp(testScript.Contents);\ + fprintf('__________\n\n');\ + run(testScript);"