Testing is a crucial part of software development, and there are several kinds of testing performed by software development teams. Configuration testing is one type of testing that verifies the performance of a system under different configurations. This blog explains how to use GitHub Actions Matrices to build the code with different configurations.
GitHub actions matrices allow to use of variables in a single job definition to create multiple jobs with different configurations.
Let's get started.
We can define the variable as job.<jobid>.strategy.matrix. Following sample has two variables for OS values and version values. During the GitHub Actions pipeline run time, there will be multiple jobs with a combination of all the variables defined.
jobs:
build:
strategy:
matrix:
os: [ubuntu-22.04, ubuntu-20.04, windows-latest]
version: [3.1.424, 5.0.100, 6.0.402]
Following is a sample pipeline that builds .NET application with combination of OS and .NET versions. You can enhance the pipeline by adding a test step to test the code with different .NET versions and OS versions.
name: .NET on: push: branches: [ "main" ] pull_request: branches: [ "main" ] jobs: build: strategy: matrix: os: [ubuntu-22.04, ubuntu-20.04, windows-latest] version: [3.1.424, 5.0.100, 6.0.402] runs-on: ${{ matrix.os }} steps: - uses: actions/checkout@v3 - name: Setup .NET uses: actions/setup-dotnet@v3 with: dotnet-version: ${{ matrix.version }} - name: Restore dependencies run: dotnet restore "./actionsdemoapp/actionsdemoapp/actionsdemoapp.csproj" - name: Build run: dotnet build "./actionsdemoapp/actionsdemoapp/actionsdemoapp.csproj" --configuration Release --no-restore
Once you run the pipeline, you would be able to see multiple jobs with different configuration.
Find sample pipeline code in GitHub
No comments:
Post a Comment