language: go

sudo: required

os:
- linux

go:
- "1.11.x"
- "1.12.x"
- stable

services:
  - docker

addons:
  apt:
    packages:
    - openjdk-9-jre-headless

install:
- go get -u github.com/mgechev/revive
- sudo curl -o /usr/local/lib/antlr-4.7.2-complete.jar https://www.antlr.org/download/antlr-4.7.2-complete.jar
- export CLASSPATH=".:/usr/local/lib/antlr-4.7.2-complete.jar:$CLASSPATH"
- mkdir $HOME/travis-bin
- echo -e '#!/bin/bash\njava -jar /usr/local/lib/antlr-4.7.2-complete.jar "$@"' > $HOME/travis-bin/antlr
- echo -e '#!/bin/bash\njava org.antlr.v4.gui.TestRig "$@"' > $HOME/travis-bin/grun
- chmod +x $HOME/travis-bin/*
- export PATH=$PATH:$HOME/travis-bin
- export GO111MODULE=on
- git reset --hard

stages:
- lint
- compile
- test
- e2e
- bench

jobs:
  include:
  - stage: lint
    go: stable
    script:
    - make vet
    - make lint
    - make fmt
    - git diff
    - if [[ $(git diff) != '' ]]; then echo 'Invalid formatting!' >&2; exit 1; fi
  - stage: compile
    go: stable
    script:
    - make generate
    - make compile
  - stage: test
    script:
    - make cover
  - stage: e2e
    go: stable
    before_script:
    - docker pull microbox/chromium-headless:77.0.3844.0
    - docker run -d -p 9222:9222 microbox/chromium-headless:77.0.3844.0
    - docker ps
    script:
    - make e2e
    after_script:
    - docker stop $(docker ps -q)
  - stage: bench
    go: stable
    script:
    - make bench
