name: Test

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

jobs:

  test:
    runs-on: ubuntu-latest
    strategy:
      fail-fast: false
      matrix:
        go-version: [1.16.x, 1.17.x, 1.18.0-beta1]
        race: ["-race", ""]

    steps:

    - name: Set up Go
      uses: actions/setup-go@v2
      with:
        stable: '!contains(${{ matrix.go-version }}, "beta") && !contains(${{ matrix.go-version }}, "rc")'
        go-version: ${{ matrix.go-version }}

    - name: Checkout
      uses: actions/checkout@v2

    - name: Install dbus
      run: sudo apt-get install dbus dbus-x11

    - name: Build
      run: go build ${{ matrix.race }} -v ./...

    - name: Test
      run: go test ${{ matrix.race }} -v ./...

  codespell:
    runs-on: ubuntu-20.04
    steps:
    - uses: actions/checkout@v2
    - name: install deps
      # Version of codespell bundled with Ubuntu is way old, so use pip.
      run: pip install codespell
    - name: run codespell
      run: codespell
