RASA - Continuous integration using GitHub Actions
Tags: rasa, chatbot, nlp, ai
Published: 2021-05-13 17:39:54

To be sure, that the new code that we write does not break the behaviour of our assistant, we have written a few tests for [happy](https://dev.to/petr7555/rasa-rules-and-testing-forms-4ffa#testing) and [unhappy](https://dev.to/petr7555/rasa-testing-unhappy-paths-3gh1) paths. But we still have to run those tests manually every time we make any changes. 
To automate this process, we will create a GitHub Action, that will train our assistant and run the tests every time we push any changes to GitHub.

Create a new file in folder `.github/workflows/` named `continuous-integration.yml`.

```yml
# .github/workflows/continuous-integration.yml
name: Train and test Rasa

on:
  push:
    branches: [ master ]
  pull_request:
    branches: [ master ]

jobs:
  training-testing:
    name: Training and Testing
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - name: Rasa Train and Test GitHub Action
        uses: RasaHQ/rasa-train-test-gha@main
        with:
          data_validate: true # Validates domain and data files to check for possible mistakes
          rasa_train: true # Run rasa train
          rasa_test: true # Run rasa test
          test_args: --fail-on-prediction-errors # Fail pipeline when test fails
          test_type: all # Run both 'core' and 'nlu' tests
      - name: Upload model
        if: github.ref == 'refs/heads/master'
        uses: actions/upload-artifact@master
        with:
          name: model
          path: models
      - name: Store test results
        uses: actions/upload-artifact@v2
        with:
          name: test-results
          path: |
            results
            reports

```

The file reads as follows:
- This action is run when anyone pushes to `master` of creates a pull request to `master` branch.
- It contains one job, named **Training and Testing** that is made of several steps.
- First, the repository is checked-out.
- Second, a premade **Rasa Train and Test GitHub Action** is run with a configuration. The configuration options are described in the comments. You can learn about more configuration options in their [README](https://github.com/RasaHQ/rasa-train-test-gha). 
- During this step:
  - domain and data files are validated to check for possible mistakes. You can learn more about data validation in the [documentation](https://rasa.com/docs/rasa/testing-your-assistant/#validating-data-and-stories).
  - a model is trained
  - a model is tested
- At the end we store the trained model as an artifact.
- We also store test results and reports. The reports contain various metrics of our model, both in `.json` and `.csv` format.

I have also simplified `requirements.txt` to install only `rasa` package. Its dependencies are resolved automatically.
Contents of `requirements.txt`:
```
rasa==2.3.1
```

You can learn more about GitHub Actions [here](https://github.com/features/actions).

You can learn more about continuous integration for Rasa in the [documentation](https://rasa.com/docs/rasa/testing-your-assistant/).

In the next chapter, we will look at checkpoints.

Repository for this tutorial:
{% github petr7555/rasa-dev-tutorial no-readme %}

You can checkout the state of the repository at the end of this tutorial by running:
```bash
git clone --branch 12-continuous-integration git@github.com:petr7555/rasa-dev-tutorial.git
```