Automation for software development
Continuous Integration (CI) refers to the build and unit testing stages of the software release process. Every committed revision can trigger an automated build and test. With Continuous Delivery (CD), code changes are automatically built, tested, and prepared for a release to production.
GitHub Actions
GitHub Actions is a Continuous Integration and Continuous Delivery (CI/CD) platform that automates building, testing, and deploying code. You can set up workflows that build and test every pull request in your repository, and optionally deploy changes after those pull requests are merged, triggered automatically based on your chosen rules.
Automating testing
A common usecase of automation is to trigger automatic testing when pushing changes and creating pull requests.
The example below is taken from the CodeRefinery lesson on Continuous Integration.
MATLAB has multiple pre-defined GitHub Actions available to use in your workflows.
This workflow uses Codecov to analyse the coverage report (free service for public repositories).
⮕ Learn more about Codecov
Automating documentation generation
GitHub Pages is a static site hosting service that takes HTML, CSS, and JavaScript files straight from a repository on GitHub, optionally runs the files through a build process, and publishes a website.
In order to deploy the documentation generated by the workflow below, you need to navigate to Settings -> Pages in your repository and set:
- Source: “Deploy from a branch”
- Branch:
gh-pages
fromroot
It is a best practice to only deploy new documentation to the gh-pages
branch upon a Pull Request to the main
branch. This avoids mismatches between the available source code and the documentation.
Workflows for building Python packages
You can automate publishing a new version of your Python package with a GitHub Action. Notice that in the workflow below, the trigger is the creation of a new release on GitHub.
This action should only run after all other workflows (such as testing and building) have passed.
Additional concepts
Variables and secrets
Secrets are variables that you create in an organization, repository, or repository environment. The secrets that you create are available to use in GitHub Actions workflows. GitHub Actions can only read a secret if you explicitly include the secret in a workflow.
⮕ More information on using secrets in GitHub Actions.
Matrix strategy
A matrix strategy lets you use variables in a single job definition to automatically create multiple job runs that are based on the combinations of the variables. For example, you can use a matrix strategy to test your code in multiple versions of a language or on multiple operating systems.
A job will run for each possible combination of the variables. In the example below, the workflow will run 12 jobs, one for each combination of the os
and python-version
variables.
jobs:
example_matrix:
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
python-version: ['3.10', '3.11', '3.12', '3.13']
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
⮕ More information on using a matrix for your jobs.
Artifacts
Artifacts are files or sets of files that are produced during the execution of a workflow and need to be stored or shared between jobs in a workflow.
To upload an artifact, you typically add a step in your workflow:
steps:
- name: Upload build output
uses: actions/upload-artifact@v4
with:
name: build-output
path: <path/to/build/output>
Artifacts can be downloaded in subsequent jobs of the same workflow run using the actions/download-artifact
action. This is done with a step like:
steps:
- name: Download build output
uses: actions/download-artifact@v4
with:
name: build-output
path: <path/to/download>
By default, artifacts are retained for 90 days, but this can be configured per workflow or at the repository/organization level.
GitLab pipelines
As previously mentioned in the Project management section, TU Delft has its own GitLab instance. However, it does not (yet) have preconfigured servers available to run GitLab pipelines, the equivalent of GitHub Actions.
In order to set up a pipeline, you will need to request a TU Delft Virtual Private Server and configure a GitLab runner there. The DCC has developed a step-by-step guide (see below), along with guidance on setting up a CI pipeline for a MATLAB environment.
Continuous Integration with GitLab
Set up CI/CD for your project in TU Delft GitLab.
Setting up a GitLab runner for MATLAB
Create a CI pipeline for a MATLAB environment in TU Delft GitLab.
Sonar
To automate checking your code quality, you can also make use of a third-party service. SonarQube Cloud (previously known as SonarCloud) is a cloud-based code analysis service designed to detect coding issues in many different programming languages. The free plan allows you to analyze an unlimited number of public repositories. Private projects will not be importable on this plan.
- Make your repository public.
- Link your GitHub repository via their login page.
- Follow the instructions to set up the code analysis.
You can also integrate SonarQube Cloud code analysis in GitHub Actions. Typically, you would create a new workflow file, for example .github/workflows/sonar.yml
, and configure triggers to your needs. You will need to set up a token in GitHub Secrets and configure what needs to be analyzed in sonar-project.properties
.
The basic usage step-by-step is described in their GitHub repository.