GitHub Actions

How to use CAT in GitHub Actions

Prerequisites

  • GitHub public or private repository set up
  • CAT project along with test definitions created and pushed to the repository
  • A basic understanding of CAT

Secrets

First of all, let’s set up environment secrets and then pass them as variables. Navigate to this page in your repo:

1

Click on Settings, then Environments, and New environment. Name it and click Configure environment. After this, navigate to this environment and create a secret:

2

The secret contains the connection string of our database. The syntax for passing it to the pipeline via Powershell is shown below.

Pipeline Code

Once variables are set up, navigate to the pane on the top left and click on Actions and then New workflow:

3

This will lead you to the page shown below where you can either choose from a template or create a workflow yourself:

4

After clicking on set up a workflow yourself, you can start working and commit your code to repo.

Below is an example code we used to run CAT; commit the code and this will automatically start the Github workflow.

name: testing_pipeline
on: push
permissions:
  checks: write
  pull-requests: write
jobs:
  deployment:
    runs-on: windows-latest
    environment: dev
    steps:
      - name: checkout
        uses: actions/checkout@v3
      - name: run cat
        shell: pwsh
        env:
          AERO_STRING_PROD: ${{ secrets.AERO_STRING_PROD }}
        run: |

          Install-Module CAT -Force -AcceptLicense

          Import-Module CAT

          Invoke-CatProject

      - name: Publish Test Results
        uses: EnricoMi/publish-unit-test-result-action/composite@v2
        if: always()
        with:
          files: |
            **\*.trx

This script installs CAT, invokes it, runs the tests and then publishes the results of the tests to the pipeline using Github action provided by the community. The environment variable passed secretly is used to connect to the database on which the tests are run.

Results

Navigate to the pipeline you want the results for via actions and click on the latest run. The result will look like this:

5

The user can see the list of the tests conducted and failed tests, along with their output as well.