|
| 1 | +| **GitHub<sup>®</sup> Actions** | |
| 2 | +|:---------------------------------------:| |
| 3 | +| [](https://github.com/mathworks/ci-configuration-examples/actions/workflows/ci.yml) <br><br> | |
| 4 | + |
| 5 | + |
| 6 | +# Continuous Integration (CI) configuration examples for MATLAB<sup>®</sup> |
| 7 | + |
| 8 | +Are you interested in automating your testing with CI? |
| 9 | + |
| 10 | +Not sure how to connect MATLAB with CI systems? |
| 11 | + |
| 12 | +We've got you covered! |
| 13 | + |
| 14 | +This repository makes it easy to run your MATLAB tests on some of the most common CI platforms. The configuration files take care of setting up MATLAB to work with the CI system and automatically executing your MATLAB tests. |
| 15 | + |
| 16 | +<br> |
| 17 | + |
| 18 | + |
| 19 | +## Getting started |
| 20 | +### <u>Quick start guide</u> |
| 21 | +Here's how to quickly get this repository running on a CI system: |
| 22 | +1. Fork the repository to your own GitHub account |
| 23 | +2. Go to one of the supported CI platforms and install the available MATLAB CI plugin ***Note:*** GitHub Actions does not require this step |
| 24 | +3. Create a new CI job using your forked repository |
| 25 | +4. Enjoy using CI with MATLAB! |
| 26 | + |
| 27 | +That's really it! |
| 28 | + |
| 29 | +To use your MATLAB code or Simulink<sup>®</sup> models with this repository, simply replace the existing code and tests in "source" and "tests" with your own code and tests. There's no need to modify any of the CI configuration files because they are all completely agnostic of the MATLAB code being used. |
| 30 | + |
| 31 | +***Notes:*** |
| 32 | +* In most cases, the configuration files will automatically get picked up by the CI platform during step 3, but some platforms may require you to specify which file to use |
| 33 | +* The default branch for this repository is "main" |
| 34 | + |
| 35 | +<br> |
| 36 | + |
| 37 | + |
| 38 | +### <u>Step-by-step getting started guide for GitHub Actions</u> |
| 39 | +Our Continuous Integration with MATLAB and GitHub Actions Workshop provides a step-by-step guide for getting started with GitHub Actions. |
| 40 | +* https://github.com/mathworks/ci-with-matlab-and-github-actions-workshop |
| 41 | + |
| 42 | + |
| 43 | +<br> |
| 44 | + |
| 45 | + |
| 46 | +## Badges |
| 47 | + |
| 48 | +Badges look really great, but they're not always easy to set up. Take a look at the badges, badge code, and reference links below to get started with badges for your repository. |
| 49 | + |
| 50 | +<br> |
| 51 | + |
| 52 | +| **GitHub Actions** | | |
| 53 | +|:-----------------------------|:-| |
| 54 | +| Badge | [](https://github.com/mathworks/ci-configuration-examples/actions/workflows/ci.yml) | |
| 55 | +| Badge Code | \[\!\[MATLAB](https[]()://github.com/***GITHUB_USERNAME***/***GITHUB_REPO_NAME***/actions/workflows/ci.yml/badge.svg)](https[]()://github.com/***GITHUB_USERNAME***/***GITHUB_REPO_NAME***/actions/workflows/ci.yml) | |
| 56 | +| Badge Help | [GitHub Actions documentation for setting up badges](https://docs.github.com/en/actions/managing-workflow-runs/adding-a-workflow-status-badge) | |
| 57 | + |
| 58 | +<br> |
| 59 | + |
| 60 | +**How to use the Badge Code:** |
| 61 | +1. Copy-paste the badge code into your README.md file |
| 62 | + * The badge code you copy should start with "`[!`" and not "`\[\!`" |
| 63 | +2. Replace all ***BOLD+ITALIC*** names with your specific credentials/names |
| 64 | + * Replace ***GITHUB_ORG*** with your GitHub organization name (usually your GitHub username) |
| 65 | + * Replace ***GITHUB_REPO_NAME*** with the name of your GitHub repository |
| 66 | + * Replace ***SOURCE_CONTROL_SYSTEM*** with the name of the source control system you are pointing to (gh = GitHub, bb = BitBucket) |
| 67 | + * Replace ***DEFAULT_BRANCH_NAME*** with the repository branch name you want to get the pipeline status from |
| 68 | + |
| 69 | +<br> |
| 70 | + |
| 71 | +## About the code |
| 72 | +The primary goal of this repository is to provide a set of configuration files as templates that illustrate how to run MATLAB on various CI platforms (e.g., Azure DevOps, CircleCI, GitHub Actions, Jenkins). |
| 73 | + |
| 74 | +Each of these pipeline definitions does four things: |
| 75 | + |
| 76 | +1. Install the latest MATLAB release on a Linux<sup>®</sup>-based build agent |
| 77 | +2. Run all MATLAB tests in the root of your repository, including its subfolders |
| 78 | +3. Produce a test results report (if necessary) |
| 79 | +4. Produce a code coverage report in Cobertura XML format for the source folder |
| 80 | + * To see an example of using [Codecov](https://about.codecov.io/) to show coverage results, please refer to [https://github.com/mathworks/matlab-codecov-example](https://github.com/mathworks/matlab-codecov-example) |
| 81 | + |
| 82 | +The example MATLAB code example `dayofyear.m` is a simple function takes a date string `"mm/dd/yyyy"` and returns the day-of-year number. |
| 83 | + |
| 84 | +Notes: |
| 85 | +* MATLAB already includes a day-of-year calculation using `day(d,"dayofyear")`, where `d` is a datetime object. This code is only used as an example since it is a concept that is familiar to most people. |
| 86 | +* The code coverage is intentionally set below 100% to show how missing coverage looks with badges. Uncomment the last test in `TestExamples.m` to increase the coverage to 100%. |
| 87 | + |
| 88 | +There are 2 test classes provided: |
| 89 | +1. TestExamples.m - A simple set of equality and negative tests |
| 90 | +2. ParameterizedTestExamples.m - A set of 12 equality tests set up using the parameterized test format |
| 91 | + |
| 92 | +The repository includes these files: |
| 93 | + |
| 94 | +| **File Path** | **Description** | |
| 95 | +|:---------------------------|:----------------| |
| 96 | +| [`source/dayofyear.m`](source/dayofyear.m) | The [`dayofyear`](source/dayofyear.m) function returns the day-of-year number for a given date string "mm/dd/yyyy" | |
| 97 | +| [`tests/TestExamples.m`](tests/TestExamples.m) | The [`TestExamples`](tests/TestExamples.m) class provides a few equality and negative tests for the [`dayofyear`](source/dayofyear.m) function | |
| 98 | +| [`tests/ParameterizedTestExample.m`](tests/ParameterizedTestExample.m) | The [`ParameterizedTestExample`](tests/ParameterizedTestExample.m) class provides 12 tests for the [`dayofyear`](source/dayofyear.m) function using the parameterized test format | |
| 99 | +| [`.github/workflows/ci.yml`](###GitHub-Actions) | The [`ci.yml`](.github/workflows/ci.yml) file defines the pipeline that runs on [GitHub Actions](https://github.com/matlab-actions/overview) | |
| 100 | + |
| 101 | +<br> |
| 102 | + |
| 103 | +## Caveats |
| 104 | +* On cloud-hosted agents provided by Azure DevOps, CircleCI, and GitHub Actions, you need a [MATLAB batch licensing token](https://github.com/mathworks-ref-arch/matlab-dockerfile/blob/main/alternates/non-interactive/MATLAB-BATCH.md#matlab-batch-licensing-token) if your project is private or if your pipeline includes transformation products, such as MATLAB Coder™ and MATLAB Compiler™. You can request a token by contacting MathWorks® at [batch-tokens@mathworks.com](mailto:batch-tokens@mathworks.com). |
| 105 | + |
| 106 | +<br> |
| 107 | + |
| 108 | + |
| 109 | +## Links |
| 110 | +- [Continuous Integration with MATLAB and Simulink](https://www.mathworks.com/solutions/continuous-integration.html) |
| 111 | + |
| 112 | +<br> |
| 113 | + |
| 114 | + |
| 115 | +## Contact Us |
| 116 | +If you have any questions or suggestions, please contact MathWorks at [continuous-integration@mathworks.com](mailto:continuous-integration@mathworks.com). |
0 commit comments