From 8e8b4d972a1bfc9c41ed648a3d451d82d411092e Mon Sep 17 00:00:00 2001 From: David Buzinski Date: Tue, 30 Aug 2022 09:40:47 -0400 Subject: [PATCH 01/10] add run-build command --- .circleci/test-deploy.yml | 77 +++++++++++++++++++++++++- src/commands/run-build.yml | 28 ++++++++++ src/examples/run-build.yml | 20 +++++++ src/examples/run-custom-script.yml | 2 +- src/examples/run-tests-with-report.yml | 2 +- src/scripts/run-build.sh | 39 +++++++++++++ 6 files changed, 165 insertions(+), 3 deletions(-) create mode 100644 src/commands/run-build.yml create mode 100644 src/examples/run-build.yml create mode 100644 src/scripts/run-build.sh diff --git a/.circleci/test-deploy.yml b/.circleci/test-deploy.yml index c48320e..cc73569 100644 --- a/.circleci/test-deploy.yml +++ b/.circleci/test-deploy.yml @@ -20,7 +20,7 @@ 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 @@ -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', 'w'); fwrite(f, 'building'); fclose(f); + + function testTask(~) + f = fopen('buildlog.txt', 'w'); fwrite(f, 'testing'); fclose(f); + + function deployTask(~) + f = fopen('buildlog.txt', 'w'); fwrite(f, 'deploying'); fclose(f); + + function checkTask(~) + f = fopen('buildlog.txt', 'w'); fwrite(f, 'checking'); fclose(f); + _EOF + shell: bash + # run build with one specified task + - matlab/run-build: + tasks: deploy + - run: + name: Verify 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 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 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: @@ -278,6 +348,11 @@ workflows: parameters: executor: [linux, windows] + - integration-test-run-build: + matrix: + parameters: + executor: [linux, windows] + - orb-tools/pack: filters: *filters diff --git a/src/commands/run-build.yml b/src/commands/run-build.yml new file mode 100644 index 0000000..04c869b --- /dev/null +++ b/src/commands/run-build.yml @@ -0,0 +1,28 @@ +description: > + Execute the MATLAB Build Tool to execute a build. MATLAB exits with exit code 0 if all specified + tasks execute successfully without error. Otherwise, MATLAB terminates with a nonzero exit code, + which causes the build to fail. + +parameters: + tasks: + description: > + A space separated list of one or more tasks to execute from buildfile.m. If no tasks are + specified, buildtool with run a build with the default tasks. + 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 command + environment: + PARAM_TASKS: <> + 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..99d0a35 --- /dev/null +++ b/src/examples/run-build.yml @@ -0,0 +1,20 @@ +description: > + Run a custom MATLAB script in 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..f6d6492 --- /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" From 1a49b2b993a8214e4614a1a854f79f9a1373ec62 Mon Sep 17 00:00:00 2001 From: David Buzinski Date: Tue, 30 Aug 2022 09:47:10 -0400 Subject: [PATCH 02/10] fixing yaml lint --- src/commands/run-build.yml | 6 +++--- src/commands/run-command.yml | 2 +- src/commands/run-tests.yml | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/commands/run-build.yml b/src/commands/run-build.yml index 04c869b..06cf8c6 100644 --- a/src/commands/run-build.yml +++ b/src/commands/run-build.yml @@ -1,12 +1,12 @@ description: > Execute the MATLAB Build Tool to execute a build. MATLAB exits with exit code 0 if all specified - tasks execute successfully without error. Otherwise, MATLAB terminates with a nonzero exit code, + tasks execute successfully without error. Otherwise, MATLAB terminates with a nonzero exit code, which causes the build to fail. parameters: tasks: description: > - A space separated list of one or more tasks to execute from buildfile.m. If no tasks are + A space separated list of one or more tasks to execute from buildfile.m. If no tasks are specified, buildtool with run a build with the default tasks. type: string default: "" @@ -23,6 +23,6 @@ steps: name: Run MATLAB command environment: PARAM_TASKS: <> - command: <> + 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: <> From d745a0f0d12e2c9105fc5f314c8267be121344da Mon Sep 17 00:00:00 2001 From: David Buzinski Date: Tue, 30 Aug 2022 09:47:57 -0400 Subject: [PATCH 03/10] fixing shellcheck findings --- src/scripts/run-build.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/scripts/run-build.sh b/src/scripts/run-build.sh index f6d6492..0693209 100644 --- a/src/scripts/run-build.sh +++ b/src/scripts/run-build.sh @@ -25,7 +25,7 @@ if [[ $os = CYGWIN* || $os = MINGW* || $os = MSYS* ]]; then fi # create buildtool command from parameters -buildCommand = "buildtool ${PARAM_TASKS}" +buildCommand="buildtool ${PARAM_TASKS}" # create script to execute script=command_${RANDOM} From 31de377dd64b36e9baa4cb567f6ac5fd4398a0c7 Mon Sep 17 00:00:00 2001 From: David Buzinski Date: Tue, 30 Aug 2022 09:52:09 -0400 Subject: [PATCH 04/10] fixing typo in circleci config --- .circleci/test-deploy.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.circleci/test-deploy.yml b/.circleci/test-deploy.yml index cc73569..10cba8c 100644 --- a/.circleci/test-deploy.yml +++ b/.circleci/test-deploy.yml @@ -312,7 +312,7 @@ jobs: rm buildlog.txt shell: bash # run build with default tasks - - matlab/run-build: + - matlab/run-build - run: name: Verify correct tasks appear in buildlog.txt command: | From 6dead9907d4a4bebb32138c93476d25344d6f118 Mon Sep 17 00:00:00 2001 From: David Buzinski Date: Tue, 30 Aug 2022 09:55:55 -0400 Subject: [PATCH 05/10] changing name in run-build.yml --- src/commands/run-build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/commands/run-build.yml b/src/commands/run-build.yml index 06cf8c6..fe7863c 100644 --- a/src/commands/run-build.yml +++ b/src/commands/run-build.yml @@ -20,7 +20,7 @@ parameters: steps: - run: - name: Run MATLAB command + name: Run MATLAB build environment: PARAM_TASKS: <> command: <> From d4a836eea4145b383a4976da37c051ff0af9ee6a Mon Sep 17 00:00:00 2001 From: David Buzinski Date: Mon, 26 Sep 2022 08:28:42 -0400 Subject: [PATCH 06/10] fixing typo in buildfile --- .circleci/test-deploy.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.circleci/test-deploy.yml b/.circleci/test-deploy.yml index 10cba8c..8a348d6 100644 --- a/.circleci/test-deploy.yml +++ b/.circleci/test-deploy.yml @@ -273,16 +273,16 @@ jobs: plan.DefaultTasks = "test"; function buildTask(~) - f = fopen('buildlog.txt', 'w'); fwrite(f, 'building'); fclose(f); + f = fopen('buildlog.txt', 'a+'); fprintf(f, 'building\n'); fclose(f); function testTask(~) - f = fopen('buildlog.txt', 'w'); fwrite(f, 'testing'); fclose(f); + f = fopen('buildlog.txt', 'a+'); fprintf(f, 'testing\n'); fclose(f); function deployTask(~) - f = fopen('buildlog.txt', 'w'); fwrite(f, 'deploying'); fclose(f); + f = fopen('buildlog.txt', 'a+'); fprintf(f, 'deploying\n'); fclose(f); function checkTask(~) - f = fopen('buildlog.txt', 'w'); fwrite(f, 'checking'); fclose(f); + f = fopen('buildlog.txt', 'a+'); fprintf(f, 'checking\n'); fclose(f); _EOF shell: bash # run build with one specified task From ba69e2013e6fce214065edc39e03bf27e334343f Mon Sep 17 00:00:00 2001 From: David Buzinski Date: Mon, 26 Sep 2022 08:51:12 -0400 Subject: [PATCH 07/10] updating yml to match other doc --- src/commands/run-build.yml | 4 ++-- src/examples/run-build.yml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/commands/run-build.yml b/src/commands/run-build.yml index fe7863c..b5fa547 100644 --- a/src/commands/run-build.yml +++ b/src/commands/run-build.yml @@ -6,8 +6,8 @@ description: > parameters: tasks: description: > - A space separated list of one or more tasks to execute from buildfile.m. If no tasks are - specified, buildtool with run a build with the default tasks. + Space-separated list of tasks to run. If not specified, the action 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: diff --git a/src/examples/run-build.yml b/src/examples/run-build.yml index 99d0a35..0c3d828 100644 --- a/src/examples/run-build.yml +++ b/src/examples/run-build.yml @@ -1,5 +1,5 @@ description: > - Run a custom MATLAB script in your project. + Run a MATLAB build for your project. usage: version: 2.1 From 1503c8384f0580d180d39e08b80813b44a6e8e66 Mon Sep 17 00:00:00 2001 From: David Buzinski Date: Mon, 26 Sep 2022 08:53:00 -0400 Subject: [PATCH 08/10] fixing orb linting finds --- src/commands/install.yml | 2 +- src/commands/run-build.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) 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 index b5fa547..23e57a1 100644 --- a/src/commands/run-build.yml +++ b/src/commands/run-build.yml @@ -6,7 +6,7 @@ description: > parameters: tasks: description: > - Space-separated list of tasks to run. If not specified, the action runs the default tasks + Space-separated list of tasks to run. If not specified, the action runs the default tasks in the plan returned by buildfile.m as well as all the tasks on which they depend. type: string default: "" From 68bd7b795fad14cda60aa005bf51d603dc39f681 Mon Sep 17 00:00:00 2001 From: David Buzinski Date: Mon, 26 Sep 2022 09:04:13 -0400 Subject: [PATCH 09/10] fixing description draft --- src/commands/run-build.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/commands/run-build.yml b/src/commands/run-build.yml index 23e57a1..ca99e73 100644 --- a/src/commands/run-build.yml +++ b/src/commands/run-build.yml @@ -1,7 +1,7 @@ description: > - Execute the MATLAB Build Tool to execute a build. MATLAB exits with exit code 0 if all specified - tasks execute successfully without error. Otherwise, MATLAB terminates with a nonzero exit code, - which causes the build to fail. + 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: From d96bda161874c740c01227681394a0bd8d36354b Mon Sep 17 00:00:00 2001 From: David Buzinski Date: Mon, 26 Sep 2022 09:34:45 -0400 Subject: [PATCH 10/10] incorporating feedback --- .circleci/test-deploy.yml | 18 +++++++++--------- src/commands/run-build.yml | 2 +- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/.circleci/test-deploy.yml b/.circleci/test-deploy.yml index 8a348d6..af26714 100644 --- a/.circleci/test-deploy.yml +++ b/.circleci/test-deploy.yml @@ -23,7 +23,7 @@ executors: image: ubuntu-2204:2022.07.1 macos: macos: - xcode: 13.2.1 + xcode: 13.4.1 windows: win/default @@ -289,7 +289,7 @@ jobs: - matlab/run-build: tasks: deploy - run: - name: Verify correct tasks appear in buildlog.txt + name: Verify that correct tasks appear in buildlog.txt command: | set -e grep "building" buildlog.txt @@ -302,7 +302,7 @@ jobs: - matlab/run-build: tasks: deploy check - run: - name: Verify correct tasks appear in buildlog.txt + name: Verify that correct tasks appear in buildlog.txt command: | set -e grep "building" buildlog.txt @@ -314,7 +314,7 @@ jobs: # run build with default tasks - matlab/run-build - run: - name: Verify correct tasks appear in buildlog.txt + name: Verify that correct tasks appear in buildlog.txt command: | set -e grep "building" buildlog.txt @@ -331,27 +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] + executor: [linux, windows, macos] - orb-tools/pack: filters: *filters diff --git a/src/commands/run-build.yml b/src/commands/run-build.yml index ca99e73..c42f055 100644 --- a/src/commands/run-build.yml +++ b/src/commands/run-build.yml @@ -6,7 +6,7 @@ description: > parameters: tasks: description: > - Space-separated list of tasks to run. If not specified, the action runs the default tasks + 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: ""