name: Test package against Go versions

on: [ push, pull_request ]

jobs:
  test:

    runs-on: ubuntu-latest
    defaults:
      run:
        working-directory: 'go/src/github.com/bugsnag/bugsnag-go' # relative to $GITHUB_WORKSPACE
    strategy:
      fail-fast: false
      matrix:
        go-version: ['1.7', '1.8', '1.9', '1.10', '1.11', '1.12', '1.13', '1.14', '1.15']

    steps:
    - uses: actions/checkout@v2
      with:
        path: 'go/src/github.com/bugsnag/bugsnag-go' # relative to $GITHUB_WORKSPACE
    - name: setup go ${{ matrix.go-version }}
      run: |
        curl --silent --location --output gimme https://github.com/travis-ci/gimme/raw/v1.5.4/gimme
        chmod +x ./gimme
        eval "$(./gimme ${{ matrix.go-version }})"
    - name: set GOPATH
      run: echo "GOPATH=$GITHUB_WORKSPACE/go" >> $GITHUB_ENV
    - name: install dependencies
      run: make alldeps
    - name: run tests (go1.7 - go1.10)
      # gin requires go1.11+
      if: matrix.go-version == '1.7' || matrix.go-version == '1.8' || matrix.go-version == '1.9' || matrix.go-version == '1.10'
      run: go test . ./martini ./negroni ./sessions ./headers ./errors
    - name: run tests
      if: matrix.go-version != '1.7' && matrix.go-version != '1.8' && matrix.go-version != '1.9' && matrix.go-version != '1.10'
      run: go test . ./gin ./martini ./negroni ./sessions ./headers ./errors
    - name: vet package (go1.7 - go1.10)
      if: matrix.go-version == '1.7' || matrix.go-version == '1.8' || matrix.go-version == '1.9' || matrix.go-version == '1.10'
      run: go vet . ./martini ./negroni ./sessions ./headers ./errors
    - name: vet package
      # go1.12 vet shows spurious 'unknown identifier' issues
      if: matrix.go-version != '1.7' && matrix.go-version != '1.8' && matrix.go-version != '1.9' && matrix.go-version != '1.10' && matrix.go-version != '1.12'
      run: go vet . ./gin ./martini ./negroni ./sessions ./headers ./errors

    - name: install integration dependencies
      run: |
        sudo apt-get install docker-compose
        sudo gem install bundler
        bundle install
    - name: maze tests - plain Go apps
      env:
        GO_VERSION: ${{ matrix.go-version }}
      run: bundle exec bugsnag-maze-runner --color --format progress features/plain_features features/net_http_features
    - name: maze tests - Martini apps
      env:
        GO_VERSION: ${{ matrix.go-version }}
      run: bundle exec bugsnag-maze-runner --color --format progress features/martini_features
    - name: maze tests - Gin apps
      # gin requires go1.11+
      if: matrix.go-version != '1.7' && matrix.go-version != '1.8' && matrix.go-version != '1.9' && matrix.go-version != '1.10'
      env:
        GO_VERSION: ${{ matrix.go-version }}
      run: |
        GIN_VERSION=v1.0 bundle exec bugsnag-maze-runner --color --format progress features/gin_features
        GIN_VERSION=v1.3.0 bundle exec bugsnag-maze-runner --color --format progress features/gin_features
    - name: maze tests - Negroni apps
      env:
        GO_VERSION: ${{ matrix.go-version }}
      run: |
        NEGRONI_VERSION=v1.0.0 bundle exec bugsnag-maze-runner --color --format progress features/negroni_features
        NEGRONI_VERSION=v0.3.0 bundle exec bugsnag-maze-runner --color --format progress features/negroni_features
    # Revel flakes out periodically on go1.12-1.15 (PLAT-5295)
    # - name: maze tests - Revel apps
    #   # Revel supports 1.12+
    #   if: matrix.go-version != '1.7' && matrix.go-version != '1.8' && matrix.go-version != '1.9' && matrix.go-version != '1.10' && matrix.go-version != '1.11'
    #   env:
    #     GO_VERSION: ${{ matrix.go-version }}
    #   run: |
    #     REVEL_VERSION=v0.21.0 REVEL_CMD_VERSION=v0.21.1 bundle exec bugsnag-maze-runner --color --format progress features/revel_features
