diff --git a/.circleci/test-deploy.yml b/.circleci/test-deploy.yml index c48320e..af26714 100644 --- a/.circleci/test-deploy.yml +++ b/.circleci/test-deploy.yml @@ -20,10 +20,10 @@ integration-tests: &integration-tests executors: linux: &linux-executor machine: - image: ubuntu-2204:edge + image: ubuntu-2204:2022.07.1 macos: macos: - xcode: 13.2.1 + xcode: 13.4.1 windows: win/default @@ -254,6 +254,76 @@ jobs: grep -r "simple_model Coverage Report" --include="*.html" model-coverage/html shell: bash + integration-test-run-build: + parameters: + executor: + type: executor + executor: <> + steps: + # Setup for Integ tests for matlab/run-build + - matlab/install + - run: + command: | + cat \<<'_EOF' >> "buildfile.m" + function plan = buildfile + plan = buildplan(localfunctions); + plan("test").Dependencies = "build"; + plan("deploy").Dependencies = "test"; + + plan.DefaultTasks = "test"; + + function buildTask(~) + f = fopen('buildlog.txt', 'a+'); fprintf(f, 'building\n'); fclose(f); + + function testTask(~) + f = fopen('buildlog.txt', 'a+'); fprintf(f, 'testing\n'); fclose(f); + + function deployTask(~) + f = fopen('buildlog.txt', 'a+'); fprintf(f, 'deploying\n'); fclose(f); + + function checkTask(~) + f = fopen('buildlog.txt', 'a+'); fprintf(f, 'checking\n'); fclose(f); + _EOF + shell: bash + # run build with one specified task + - matlab/run-build: + tasks: deploy + - run: + name: Verify that correct tasks appear in buildlog.txt + command: | + set -e + grep "building" buildlog.txt + grep "testing" buildlog.txt + grep "deploying" buildlog.txt + ! grep "checking" buildlog.txt + rm buildlog.txt + shell: bash + # run build with multiple specified tasks + - matlab/run-build: + tasks: deploy check + - run: + name: Verify that correct tasks appear in buildlog.txt + command: | + set -e + grep "building" buildlog.txt + grep "testing" buildlog.txt + grep "deploying" buildlog.txt + grep "checking" buildlog.txt + rm buildlog.txt + shell: bash + # run build with default tasks + - matlab/run-build + - run: + name: Verify that correct tasks appear in buildlog.txt + command: | + set -e + grep "building" buildlog.txt + grep "testing" buildlog.txt + ! grep "deploying" buildlog.txt + ! grep "checking" buildlog.txt + rm buildlog.txt + shell: bash + workflows: test-deploy: jobs: @@ -261,22 +331,27 @@ workflows: - integration-test-install: matrix: parameters: - executor: [linux, windows] + executor: [linux, windows, macos] - integration-test-install-release: matrix: parameters: - executor: [linux, windows] + executor: [linux, windows, macos] - integration-test-run-command: matrix: parameters: - executor: [linux, windows] + executor: [linux, windows, macos] - integration-test-run-tests: matrix: parameters: - executor: [linux, windows] + executor: [linux, windows, macos] + + - integration-test-run-build: + matrix: + parameters: + executor: [linux, windows, macos] - orb-tools/pack: filters: *filters diff --git a/src/commands/install.yml b/src/commands/install.yml index 06c30b0..4595f87 100644 --- a/src/commands/install.yml +++ b/src/commands/install.yml @@ -15,5 +15,5 @@ steps: name: Install MATLAB environment: PARAM_RELEASE: <> - command: <> + command: <> shell: bash diff --git a/src/commands/run-build.yml b/src/commands/run-build.yml new file mode 100644 index 0000000..c42f055 --- /dev/null +++ b/src/commands/run-build.yml @@ -0,0 +1,28 @@ +description: > + Run builds using the MATLAB build tool. Use this command to run the tasks in the plan returned + by a file named buildfile.m in the root of your repository. To use the run-build command, you + need MATLAB R2022b or a later release. + +parameters: + tasks: + description: > + Space-separated list of tasks to run. If not specified, the command runs the default tasks + in the plan returned by buildfile.m as well as all the tasks on which they depend. + type: string + default: "" + no-output-timeout: + description: > + Elapsed time the command can run without output. The string is a decimal with unit suffix, + such as “20m”, “1.25h”, “5s”. The default is 10 minutes and the maximum is governed by the + maximum time a job is allowed to run. + type: string + default: 10m + +steps: + - run: + name: Run MATLAB build + environment: + PARAM_TASKS: <> + command: <> + shell: bash + no_output_timeout: <> diff --git a/src/commands/run-command.yml b/src/commands/run-command.yml index f9add6a..3bc4dfd 100644 --- a/src/commands/run-command.yml +++ b/src/commands/run-command.yml @@ -25,6 +25,6 @@ steps: name: Run MATLAB command environment: PARAM_COMMAND: <> - command: <> + command: <> shell: bash no_output_timeout: <> diff --git a/src/commands/run-tests.yml b/src/commands/run-tests.yml index 4783bd7..881b437 100644 --- a/src/commands/run-tests.yml +++ b/src/commands/run-tests.yml @@ -89,6 +89,6 @@ steps: PARAM_TEST_RESULTS_SIMULINK_TEST: <> PARAM_TEST_RESULTS_HTML: <> PARAM_TEST_RESULTS_PDF: <> - command: <> + command: <> shell: bash no_output_timeout: <> diff --git a/src/examples/run-build.yml b/src/examples/run-build.yml new file mode 100644 index 0000000..0c3d828 --- /dev/null +++ b/src/examples/run-build.yml @@ -0,0 +1,20 @@ +description: > + Run a MATLAB build for your project. + +usage: + version: 2.1 + orbs: + matlab: mathworks/matlab@0 + jobs: + build: + machine: + image: ubuntu-2204:2022.07.1 + steps: + - checkout + - matlab/install + - matlab/run-build: + tasks: test + workflows: + build: + jobs: + - build diff --git a/src/examples/run-custom-script.yml b/src/examples/run-custom-script.yml index 21dae32..f6975bd 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-2004:202111-02 + image: ubuntu-2204:2022.07.1 steps: - checkout - matlab/install diff --git a/src/examples/run-tests-with-report.yml b/src/examples/run-tests-with-report.yml index 7719eba..14a7ad0 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-2004:202111-02 + image: ubuntu-2204:2022.07.1 steps: - checkout - matlab/install diff --git a/src/scripts/run-build.sh b/src/scripts/run-build.sh new file mode 100644 index 0000000..0693209 --- /dev/null +++ b/src/scripts/run-build.sh @@ -0,0 +1,39 @@ +downloadAndRun() { + url=$1 + shift + if [[ -x $(command -v sudo) ]]; then + curl -sfL $url | sudo -E bash -s -- "$@" + else + curl -sfL $url | bash -s -- "$@" + fi +} + +tmpdir=$(mktemp -d 2>/dev/null || mktemp -d -t 'run-command') + +# install run-matlab-command +downloadAndRun https://ssd.mathworks.com/supportfiles/ci/run-matlab-command/v1/install.sh "${tmpdir}/bin" + +# form OS appropriate paths for MATLAB +os=$(uname) +workdir=$(pwd) +scriptdir=$tmpdir +binext="" +if [[ $os = CYGWIN* || $os = MINGW* || $os = MSYS* ]]; then + workdir=$(cygpath -w "$workdir") + scriptdir=$(cygpath -w "$scriptdir") + binext=".exe" +fi + +# create buildtool command from parameters +buildCommand="buildtool ${PARAM_TASKS}" + +# create script to execute +script=command_${RANDOM} +scriptpath=${tmpdir}/${script}.m +echo "cd('${workdir//\'/\'\'}');" > "$scriptpath" +cat << EOF >> "$scriptpath" +$buildCommand +EOF + +# run MATLAB command +"${tmpdir}/bin/run-matlab-command$binext" "cd('${scriptdir//\'/\'\'}');$script"