# OCPP tests in GitHub Actions and GitLab CI

Source: https://timetick.io/docs/developers/ci

Run OCPP tests in GitHub Actions, GitLab CI or any pipeline. A charger simulator connects to your CSMS and the job fails when a test fails.

On every pull request, TimeTick runs your test on a simulator connected to your CSMS on staging. If the test fails, so does the job.

## Before you start

1. [Create a simulator](https://timetick.io/docs/simulators/create) for your staging CSMS and run a test on it in the portal until it passes.
2. Save an [API key](https://timetick.io/docs/developers/api-keys) as the secret `TIMETICK_API_TOKEN`.
3. Note three numbers from the address bar in the portal:

| Id | Address |
| --- | --- |
| Project | `app.timetick.io/projects/<project id>` |
| Test | `.../tests/<test id>` |
| Simulator | `.../simulators/<simulator id>` |

## GitHub Actions

Save this as `.github/workflows/timetick.yml` and put in your ids:

```yaml
name: TimeTick OCPP tests

on:
  pull_request:
  workflow_dispatch:

concurrency:
  group: timetick

jobs:
  ocpp-tests:
    runs-on: ubuntu-latest
    steps:
      - name: Run the TimeTick test
        uses: TimeTickIO/timetick-ci@v1
        with:
          api-key: ${{ secrets.TIMETICK_API_TOKEN }}
          project-id: "123"
          test-id: "456"
          simulators: "789"
```

To test a branch, deploy it to staging before this step. The job page shows a table with the results.

## GitLab CI

Save the key as a masked variable named `TIMETICK_API_TOKEN`, then add:

```yaml
stages:
  - test

include:
  - component: gitlab.com/TimeTickIO/timetick-ci/run-test@1.0.0
    inputs:
      version: "1.0.0"
      project-id: "123"
      test-id: "456"
      simulators: "789"
```

Results appear in the **Tests** tab of the merge request.

## Other CI

You need Node.js 20:

```bash
wget -qO timetick.js https://gitlab.com/TimeTickIO/timetick-ci/-/raw/1.0.0/dist/index.js

INPUT_PROJECT_ID=123 INPUT_TEST_ID=456 INPUT_SIMULATORS=789 node timetick.js
```

It exits with `0` when the test passes.

A simulator runs one test at a time, so give each pipeline its own. All options are in the [timetick-ci repository](https://github.com/TimeTickIO/timetick-ci).
