Optisway home
Documentation menu

REST API reference: CI integration

Run an Optisway test as a step of your pipeline and fail the build when the test fails. The example below is a GitHub Actions job; the same steps work in any CI system that has curl and jq.

Before the job

Create a key with run access, scoped to the project of the test, from an account that will stay in the organisation. Store it as the repository secret OPTISWAY_API_KEY and put the tst_… id of the test in TEST_ID.

What the job does

The job starts a run with POST /tests/{id}/runs and reads its id from the response. It then reads GET /runs/{id} every 10 seconds until status is passed, failed or error.

The step ends with 0 when the run passed and with 1 when it failed or ended in error, which fails the job. timeout-minutes: 30 stops a job that waits too long, because the API never holds a request open while a run works.

Where to look when it fails

If the job fails before the run starts, the curl line in the log shows the HTTP status, for example 409. The Errors page explains every status: 409 means another run of the same test is still going, and 429 usually means the organisation has used its 30 runs of the past hour.

If the run itself failed, open it in the app from the history of the test, or read GET /runs/{id}: summary and findings say what went wrong. The evidence ZIP and report.pdf come from GET /runs/{id}/artifacts and GET /runs/{id}/files?path=report.pdf.

GitHub Actions workflow

GitHub Actions workflowYAML
name: Optisway check
on:
  push:
    branches: [main]
  workflow_dispatch:
jobs:
  optisway:
    runs-on: ubuntu-latest
    timeout-minutes: 30
    steps:
      - name: Run the Optisway test
        env:
          OPTISWAY_API_KEY: ${{ secrets.OPTISWAY_API_KEY }}
          TEST_ID: tst_7k2m9q4xh3vd
        run: |
          api=https://optisway.com/api/v1
          auth="Authorization: Bearer $OPTISWAY_API_KEY"
          # A 4xx/5xx fails the step and prints the error envelope in the log.
          request() {
            if ! body=$(curl --fail-with-body -sS -H "$auth" "$@"); then
              echo "$body" >&2
              exit 1
            fi
          }
          request -X POST "$api/tests/$TEST_ID/runs"
          run_id=$(echo "$body" | jq -r .id)
          echo "Started run $run_id"
          while true; do
            request "$api/runs/$run_id"
            status=$(echo "$body" | jq -r .status)
            case "$status" in
              passed) echo "Run $run_id passed"; exit 0 ;;
              failed|error) echo "Run $run_id ended: $status"; exit 1 ;;
            esac
            sleep 10
          done

The API never waits for a run to finish, so poll GET /runs/{id} until status is passed, failed or error.