debian-mirror-gitlab/lib/gitlab/ci/templates/MATLAB.gitlab-ci.yml

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

113 lines
5.9 KiB
YAML
Raw Normal View History

2022-06-21 17:19:12 +05:30
# To contribute improvements to CI/CD templates, please follow the Development guide at:
# https://docs.gitlab.com/ee/development/cicd/templates.html
# This specific template is located at:
# https://gitlab.com/gitlab-org/gitlab/-/blob/master/lib/gitlab/ci/templates/MATLAB.gitlab-ci.yml
2022-08-27 11:52:29 +05:30
# Use this template to run MATLAB and Simulink as part of your CI/CD pipeline. The template includes three jobs:
2022-06-21 17:19:12 +05:30
# - `command`: Run MATLAB scripts, functions, and statements.
# - `test`: Run tests authored using the MATLAB unit testing framework or Simulink Test.
2022-07-16 23:28:13 +05:30
# - `test_artifacts`: Run MATLAB and Simulink tests, and generate test and coverage artifacts.
2022-06-21 17:19:12 +05:30
#
2022-08-27 11:52:29 +05:30
# The jobs in the template use the `matlab -batch` syntax to start MATLAB. The `-batch` option is supported
# in MATLAB R2019a and later.
#
2022-06-21 17:19:12 +05:30
# You can copy and paste one or more jobs in this template into your `.gitlab-ci.yml` file.
# You should not add this template to an existing `.gitlab-ci.yml` file by using the `include:` keyword.
#
2022-08-27 11:52:29 +05:30
# Your runner must use the Docker executor to run MATLAB within a container. The [MATLAB Container on Docker Hub][1]
# lets you run your build using MATLAB R2020b or a later release. If your build requires additional toolboxes, use a
# custom MATLAB container instead. For more information on how to create and use a custom MATLAB container,
# see [Create a Custom MATLAB Container][2].
#
# [1] https://www.mathworks.com/help/cloudcenter/ug/matlab-container-on-docker-hub.html
# [2] https://www.mathworks.com/help/cloudcenter/ug/create-a-custom-matlab-container.html
# The jobs in this template incorporate the contents of a hidden `.matlab_defaults` job. You need to
# configure this job before running the `command`, `test`, and `test_artifacts` jobs. To configure the job:
# - Specify the name of the MATLAB container image you want to use.
# - Set the `MLM_LICENSE_FILE` environment variable using the port number and DNS address for your network license manager.
#
.matlab_defaults:
image:
name: mathworks/matlab:latest # Replace the value with the name of the MATLAB container image you want to use
entrypoint: [""]
variables:
MLM_LICENSE_FILE: 27000@MyLicenseServer # Replace the value with the port number and DNS address for your network license manager
2022-06-21 17:19:12 +05:30
2022-07-16 23:28:13 +05:30
# The `command` job runs MATLAB scripts, functions, and statements. To use the job in your pipeline,
# substitute `mycommand` with the code you want to run.
2022-06-21 17:19:12 +05:30
#
command:
2022-08-27 11:52:29 +05:30
extends: .matlab_defaults
2022-07-16 23:28:13 +05:30
script: matlab -batch mycommand
2022-06-21 17:19:12 +05:30
# If you specify more than one script, function, or statement, use a comma or semicolon to separate them.
# For example, to run `myscript.m` in a folder named `myfolder` located in the root of the repository,
2022-07-16 23:28:13 +05:30
# you can specify `mycommand` like this:
2022-06-21 17:19:12 +05:30
#
# "addpath('myfolder'), myscript"
#
# MATLAB exits with exit code 0 if the specified script, function, or statement executes successfully without
# error. Otherwise, MATLAB terminates with a nonzero exit code, which causes the job to fail. To have the
2022-08-27 11:52:29 +05:30
# job fail in certain conditions, use the [`assert`][3] or [`error`][4] functions.
2022-06-21 17:19:12 +05:30
#
2022-08-27 11:52:29 +05:30
# [3] https://www.mathworks.com/help/matlab/ref/assert.html
# [4] https://www.mathworks.com/help/matlab/ref/error.html
2022-06-21 17:19:12 +05:30
2022-08-27 11:52:29 +05:30
# The `test` job runs the MATLAB and Simulink tests in your project. It calls the [`runtests`][5] function
# to run the tests and then the [`assertSuccess`][6] method to fail the job if any of the tests fail.
2022-06-21 17:19:12 +05:30
#
test:
2022-08-27 11:52:29 +05:30
extends: .matlab_defaults
2022-06-21 17:19:12 +05:30
script: matlab -batch "results = runtests('IncludeSubfolders',true), assertSuccess(results);"
2022-08-27 11:52:29 +05:30
# By default, the job includes any files in your [MATLAB Project][7] that have a `Test` label. If your repository
2022-06-21 17:19:12 +05:30
# does not have a MATLAB project, then the job includes all tests in the root of your repository or in any of
# its subfolders.
#
2022-08-27 11:52:29 +05:30
# [5] https://www.mathworks.com/help/matlab/ref/runtests.html
# [6] https://www.mathworks.com/help/matlab/ref/matlab.unittest.testresult.assertsuccess.html
# [7] https://www.mathworks.com/help/matlab/projects.html
2022-06-21 17:19:12 +05:30
2022-07-16 23:28:13 +05:30
# The `test_artifacts` job runs your tests and additionally generates test and coverage artifacts.
2022-08-27 11:52:29 +05:30
# It uses the plugin classes in the [`matlab.unittest.plugins`][8] package to generate a JUnit test results
2022-07-16 23:28:13 +05:30
# report and a Cobertura code coverage report. Like the `test` job, this job runs all the tests in your
2022-06-21 17:19:12 +05:30
# project and fails the build if any of the tests fail.
#
2022-07-16 23:28:13 +05:30
test_artifacts:
2022-08-27 11:52:29 +05:30
extends: .matlab_defaults
2022-06-21 17:19:12 +05:30
script: |
2022-08-27 11:52:29 +05:30
cat <<- 'BLOCK' > runAllTests.m
import matlab.unittest.TestRunner
import matlab.unittest.Verbosity
import matlab.unittest.plugins.CodeCoveragePlugin
import matlab.unittest.plugins.XMLPlugin
import matlab.unittest.plugins.codecoverage.CoberturaFormat
suite = testsuite(pwd,'IncludeSubfolders',true);
[~,~] = mkdir('artifacts')
runner = TestRunner.withTextOutput('OutputDetail',Verbosity.Detailed);
runner.addPlugin(XMLPlugin.producingJUnitFormat('artifacts/results.xml'))
% Replace `pwd` with the location of the folder containing source code
runner.addPlugin(CodeCoveragePlugin.forFolder(pwd,'IncludingSubfolders',true, ...
'Producing',CoberturaFormat('artifacts/cobertura.xml')))
results = runner.run(suite)
assertSuccess(results);
BLOCK
matlab -batch runAllTests
2022-06-21 17:19:12 +05:30
artifacts:
reports:
junit: "./artifacts/results.xml"
2022-07-16 23:28:13 +05:30
coverage_report:
coverage_format: cobertura
path: "./artifacts/cobertura.xml"
2022-06-21 17:19:12 +05:30
paths:
- "./artifacts"
2022-07-16 23:28:13 +05:30
# You can modify the contents of the `test_artifacts` job depending on your goals. For more
2022-06-21 17:19:12 +05:30
# information on how to customize the test runner and generate various test and coverage artifacts,
2022-08-27 11:52:29 +05:30
# see [Generate Artifacts Using MATLAB Unit Test Plugins][9].
2022-06-21 17:19:12 +05:30
#
2022-08-27 11:52:29 +05:30
# [8] https://www.mathworks.com/help/matlab/ref/matlab.unittest.plugins-package.html
# [9] https://www.mathworks.com/help/matlab/matlab_prog/generate-artifacts-using-matlab-unit-test-plugins.html