Skip to content

Commit 90da0ef

Browse files
Buildtool integration (#42)
* add run-build command
1 parent 8dadb4c commit 90da0ef

File tree

9 files changed

+173
-11
lines changed

9 files changed

+173
-11
lines changed

.circleci/test-deploy.yml

Lines changed: 81 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ integration-tests: &integration-tests
2020
executors:
2121
linux: &linux-executor
2222
machine:
23-
image: ubuntu-2204:edge
23+
image: ubuntu-2204:2022.07.1
2424
macos:
2525
macos:
26-
xcode: 13.2.1
26+
xcode: 13.4.1
2727
windows:
2828
win/default
2929

@@ -254,29 +254,104 @@ jobs:
254254
grep -r "simple_model Coverage Report" --include="*.html" model-coverage/html
255255
shell: bash
256256

257+
integration-test-run-build:
258+
parameters:
259+
executor:
260+
type: executor
261+
executor: <<parameters.executor>>
262+
steps:
263+
# Setup for Integ tests for matlab/run-build
264+
- matlab/install
265+
- run:
266+
command: |
267+
cat \<<'_EOF' >> "buildfile.m"
268+
function plan = buildfile
269+
plan = buildplan(localfunctions);
270+
plan("test").Dependencies = "build";
271+
plan("deploy").Dependencies = "test";
272+
273+
plan.DefaultTasks = "test";
274+
275+
function buildTask(~)
276+
f = fopen('buildlog.txt', 'a+'); fprintf(f, 'building\n'); fclose(f);
277+
278+
function testTask(~)
279+
f = fopen('buildlog.txt', 'a+'); fprintf(f, 'testing\n'); fclose(f);
280+
281+
function deployTask(~)
282+
f = fopen('buildlog.txt', 'a+'); fprintf(f, 'deploying\n'); fclose(f);
283+
284+
function checkTask(~)
285+
f = fopen('buildlog.txt', 'a+'); fprintf(f, 'checking\n'); fclose(f);
286+
_EOF
287+
shell: bash
288+
# run build with one specified task
289+
- matlab/run-build:
290+
tasks: deploy
291+
- run:
292+
name: Verify that correct tasks appear in buildlog.txt
293+
command: |
294+
set -e
295+
grep "building" buildlog.txt
296+
grep "testing" buildlog.txt
297+
grep "deploying" buildlog.txt
298+
! grep "checking" buildlog.txt
299+
rm buildlog.txt
300+
shell: bash
301+
# run build with multiple specified tasks
302+
- matlab/run-build:
303+
tasks: deploy check
304+
- run:
305+
name: Verify that correct tasks appear in buildlog.txt
306+
command: |
307+
set -e
308+
grep "building" buildlog.txt
309+
grep "testing" buildlog.txt
310+
grep "deploying" buildlog.txt
311+
grep "checking" buildlog.txt
312+
rm buildlog.txt
313+
shell: bash
314+
# run build with default tasks
315+
- matlab/run-build
316+
- run:
317+
name: Verify that correct tasks appear in buildlog.txt
318+
command: |
319+
set -e
320+
grep "building" buildlog.txt
321+
grep "testing" buildlog.txt
322+
! grep "deploying" buildlog.txt
323+
! grep "checking" buildlog.txt
324+
rm buildlog.txt
325+
shell: bash
326+
257327
workflows:
258328
test-deploy:
259329
jobs:
260330
# Make sure to include "filters: *filters" in every test job you want to run as part of your deployment.
261331
- integration-test-install:
262332
matrix:
263333
parameters:
264-
executor: [linux, windows]
334+
executor: [linux, windows, macos]
265335

266336
- integration-test-install-release:
267337
matrix:
268338
parameters:
269-
executor: [linux, windows]
339+
executor: [linux, windows, macos]
270340

271341
- integration-test-run-command:
272342
matrix:
273343
parameters:
274-
executor: [linux, windows]
344+
executor: [linux, windows, macos]
275345

276346
- integration-test-run-tests:
277347
matrix:
278348
parameters:
279-
executor: [linux, windows]
349+
executor: [linux, windows, macos]
350+
351+
- integration-test-run-build:
352+
matrix:
353+
parameters:
354+
executor: [linux, windows, macos]
280355

281356
- orb-tools/pack:
282357
filters: *filters

src/commands/install.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,5 @@ steps:
1515
name: Install MATLAB
1616
environment:
1717
PARAM_RELEASE: <<parameters.release>>
18-
command: <<include(scripts/install.sh)>>
18+
command: <<include(scripts/install.sh)>>
1919
shell: bash

src/commands/run-build.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
description: >
2+
Run builds using the MATLAB build tool. Use this command to run the tasks in the plan returned
3+
by a file named buildfile.m in the root of your repository. To use the run-build command, you
4+
need MATLAB R2022b or a later release.
5+
6+
parameters:
7+
tasks:
8+
description: >
9+
Space-separated list of tasks to run. If not specified, the command runs the default tasks
10+
in the plan returned by buildfile.m as well as all the tasks on which they depend.
11+
type: string
12+
default: ""
13+
no-output-timeout:
14+
description: >
15+
Elapsed time the command can run without output. The string is a decimal with unit suffix,
16+
such as “20m”, “1.25h”, “5s”. The default is 10 minutes and the maximum is governed by the
17+
maximum time a job is allowed to run.
18+
type: string
19+
default: 10m
20+
21+
steps:
22+
- run:
23+
name: Run MATLAB build
24+
environment:
25+
PARAM_TASKS: <<parameters.tasks>>
26+
command: <<include(scripts/run-build.sh)>>
27+
shell: bash
28+
no_output_timeout: <<parameters.no-output-timeout>>

src/commands/run-command.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,6 @@ steps:
2525
name: Run MATLAB command
2626
environment:
2727
PARAM_COMMAND: <<parameters.command>>
28-
command: <<include(scripts/run-command.sh)>>
28+
command: <<include(scripts/run-command.sh)>>
2929
shell: bash
3030
no_output_timeout: <<parameters.no-output-timeout>>

src/commands/run-tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,6 @@ steps:
8989
PARAM_TEST_RESULTS_SIMULINK_TEST: <<parameters.test-results-simulink-test>>
9090
PARAM_TEST_RESULTS_HTML: <<parameters.test-results-html>>
9191
PARAM_TEST_RESULTS_PDF: <<parameters.test-results-pdf>>
92-
command: <<include(scripts/run-tests.sh)>>
92+
command: <<include(scripts/run-tests.sh)>>
9393
shell: bash
9494
no_output_timeout: <<parameters.no-output-timeout>>

src/examples/run-build.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
description: >
2+
Run a MATLAB build for your project.
3+
4+
usage:
5+
version: 2.1
6+
orbs:
7+
matlab: mathworks/matlab@0
8+
jobs:
9+
build:
10+
machine:
11+
image: ubuntu-2204:2022.07.1
12+
steps:
13+
- checkout
14+
- matlab/install
15+
- matlab/run-build:
16+
tasks: test
17+
workflows:
18+
build:
19+
jobs:
20+
- build

src/examples/run-custom-script.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ usage:
88
jobs:
99
build:
1010
machine:
11-
image: ubuntu-2004:202111-02
11+
image: ubuntu-2204:2022.07.1
1212
steps:
1313
- checkout
1414
- matlab/install

src/examples/run-tests-with-report.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ usage:
88
jobs:
99
build:
1010
machine:
11-
image: ubuntu-2004:202111-02
11+
image: ubuntu-2204:2022.07.1
1212
steps:
1313
- checkout
1414
- matlab/install

src/scripts/run-build.sh

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
downloadAndRun() {
2+
url=$1
3+
shift
4+
if [[ -x $(command -v sudo) ]]; then
5+
curl -sfL $url | sudo -E bash -s -- "$@"
6+
else
7+
curl -sfL $url | bash -s -- "$@"
8+
fi
9+
}
10+
11+
tmpdir=$(mktemp -d 2>/dev/null || mktemp -d -t 'run-command')
12+
13+
# install run-matlab-command
14+
downloadAndRun https://ssd.mathworks.com/supportfiles/ci/run-matlab-command/v1/install.sh "${tmpdir}/bin"
15+
16+
# form OS appropriate paths for MATLAB
17+
os=$(uname)
18+
workdir=$(pwd)
19+
scriptdir=$tmpdir
20+
binext=""
21+
if [[ $os = CYGWIN* || $os = MINGW* || $os = MSYS* ]]; then
22+
workdir=$(cygpath -w "$workdir")
23+
scriptdir=$(cygpath -w "$scriptdir")
24+
binext=".exe"
25+
fi
26+
27+
# create buildtool command from parameters
28+
buildCommand="buildtool ${PARAM_TASKS}"
29+
30+
# create script to execute
31+
script=command_${RANDOM}
32+
scriptpath=${tmpdir}/${script}.m
33+
echo "cd('${workdir//\'/\'\'}');" > "$scriptpath"
34+
cat << EOF >> "$scriptpath"
35+
$buildCommand
36+
EOF
37+
38+
# run MATLAB command
39+
"${tmpdir}/bin/run-matlab-command$binext" "cd('${scriptdir//\'/\'\'}');$script"

0 commit comments

Comments
 (0)